Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ci:
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -35,21 +35,21 @@ repos:

# Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.7.0
rev: 25.1.0
hooks:
- id: black
exclude: ^(docs)

# Check linting and style issues
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.287"
rev: "v0.11.13"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

# Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
rev: v1.5.5
hooks:
- id: remove-tabs
exclude: ^(docs)
Expand Down
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
}
],
"version": 4
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
"valarray": "cpp",
"variant": "cpp"
}
}
}
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ find_package(pybind11 CONFIG REQUIRED)
# Include the include/barry library
include_directories(include/barry)

python_add_library(_core MODULE src/main.cpp src/terms.cpp src/model.cpp WITH_SOABI)
python_add_library(_core MODULE src/main.cpp src/terms.cpp src/model.cpp
WITH_SOABI)
target_link_libraries(_core PRIVATE pybind11::headers)
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
pip3 install .
pip3 install .

update:
rsync -avz ../barry/include/barry include/
rsync -avz ../barry/include/barry include/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ m.term_formula(obj, "{y0}")
m.term_formula(obj, "{y1}")
m.term_formula(obj, "{0y0, y1}")
obj.init()
obj.print()
obj.print()
```

Num. of Arrays : 6
Expand Down
8 changes: 4 additions & 4 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ERGMs. More information in [this preprint](https://arxiv.org/abs/2211.00627).
- `pip install ./pydefm`


# Examples
# Examples

## Base setup

Expand All @@ -64,7 +64,7 @@ x = np.array([1, 2.0, 3.4, 3, 1, 2])
id = np.array([1, 1, 1, 2, 2, 2])
```

Once we have the needed data -- the binary array `y`, the covariates `x` and the ids `id` -- we can create a `defm` object.
Once we have the needed data -- the binary array `y`, the covariates `x` and the ids `id` -- we can create a `defm` object.

```{python}
# Creating the object
Expand All @@ -83,7 +83,7 @@ m.term_formula(obj, "{y0}")
m.term_formula(obj, "{y1}")
m.term_formula(obj, "{0y0, y1}")
obj.init()
obj.print()
obj.print()
```

```{python}
Expand Down Expand Up @@ -122,4 +122,4 @@ m.simulate(obj, par)

# Acknowledgements

This port work was supported by the Office of the Assistant Secretary of Defense for Health Affairs through the Epilepsy Research Program under Award No. HT94252310221. Opinions, interpretations, conclusions, and recommendations are those of the author and are not necessarily endorsed by the Department of Defense.
This port work was supported by the Office of the Assistant Secretary of Defense for Health Affairs through the Epilepsy Research Program under Award No. HT94252310221. Opinions, interpretations, conclusions, and recommendations are those of the author and are not necessarily endorsed by the Department of Defense.
70 changes: 35 additions & 35 deletions include/barry/barray-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// #include "cell-bones.hpp"
// #include "barraycell-bones.hpp"

#ifndef BARRAY_BONES_HPP
#ifndef BARRAY_BONES_HPP
#define BARRAY_BONES_HPP 1

template<typename Cell_Type, typename Data_Type>
Expand All @@ -15,7 +15,7 @@ class BArrayCell_const;

/**
* @brief Baseline class for binary arrays.
*
*
* `BArray` class objects are arbitrary arrays
* in which non-empty cells hold data of type `Cell_Type`. The non-empty cells
* are stored by row and indexed using `unordered_map`s, i.e.
Expand Down Expand Up @@ -43,34 +43,34 @@ class BArray {
static const bool dense = false;

public:
/**

/**
* This is as a reference, if we need to iterate through the cells and we need
* to keep track which were visited, we use this as a reference. So that if
* cell.visited = true and visited = true, it means that we haven't been here
* yet. Ideally, any routine using this->visited should switch it at the
* beginning of the routine.
*/
bool visited = false;


/**
* @name Constructors
*
*
* @param N_ Number of rows
* @param M_ Number of columns
* @param source An unsigned vector ranging from 0 to N_
* @param target An size_t vector ranging from 0 to M_
* @param target When `true` tries to add repeated observations.
*/
///@{

/** @brief Zero-size array */
BArray() : N(0u), M(0u), NCells(0u), el_ij(0u), el_ji(0u) {};

/** @brief Empty array */
BArray (size_t N_, size_t M_) : N(N_), M(M_), NCells(0u), el_ij(N_), el_ji(M_) {};

/** @brief Edgelist with data */
BArray (
size_t N_, size_t M_,
Expand All @@ -79,18 +79,18 @@ class BArray {
const std::vector< Cell_Type > & value,
bool add = true
);

/** @brief Edgelist with no data (simpler) */
BArray (
size_t N_, size_t M_,
const std::vector< size_t > & source,
const std::vector< size_t > & target,
bool add = true
);

/** @brief Copy constructor */
BArray(const BArray<Cell_Type,Data_Type> & Array_, bool copy_data = false);

/** @brief Assignment constructor */
BArray<Cell_Type,Data_Type> & operator=(const BArray<Cell_Type,Data_Type> & Array_);

Expand All @@ -100,20 +100,20 @@ class BArray {
/** @brief Move assignment */
BArray<Cell_Type,Data_Type> & operator=(BArray<Cell_Type,Data_Type> && x) noexcept;
///@}

bool operator==(const BArray<Cell_Type,Data_Type> & Array_);

~BArray();

// In principle, copy can be faster by using openmp on the rows
// since those are independent.
// BArray(BArray & A);

/**
* @brief Set the data object
*
* @param data_
* @param delete_data_
*
* @param data_
* @param delete_data_
*/
///@{
void set_data(Data_Type * data_, bool delete_data_ = false);
Expand All @@ -123,11 +123,11 @@ class BArray {
const Data_Type & D() const;
void flush_data();
///@}

// Function to access the elements
// bool check_cell
void out_of_range(size_t i, size_t j) const;
Cell_Type get_cell(size_t i, size_t j, bool check_bounds = true) const;
Cell_Type get_cell(size_t i, size_t j, bool check_bounds = true) const;
std::vector< Cell_Type > get_col_vec(size_t i, bool check_bounds = true) const;
std::vector< Cell_Type > get_row_vec(size_t i, bool check_bounds = true) const;
void get_col_vec(std::vector< Cell_Type > * x, size_t i, bool check_bounds = true) const;
Expand All @@ -137,12 +137,12 @@ class BArray {

/**
* @brief Get the edgelist
*
*
* `Entries` is a class with three objects: Two `std::vector` with the row and
* column coordinates respectively, and one `std::vector` with the corresponding
* value of the cell.
*
* @return Entries<Cell_Type>
*
* @return Entries<Cell_Type>
*/
Entries<Cell_Type> get_entries() const;

Expand Down Expand Up @@ -170,64 +170,64 @@ class BArray {
* delete/add), or, in the case of `swap_cells`, check if either of both
* cells exists/don't exist.
*/
///@{
///@{
BArray<Cell_Type,Data_Type> & operator+=(const std::pair<size_t, size_t> & coords);
BArray<Cell_Type,Data_Type> & operator-=(const std::pair<size_t, size_t> & coords);
BArrayCell<Cell_Type,Data_Type> operator()(size_t i, size_t j, bool check_bounds = true);
const Cell_Type operator()(size_t i, size_t j, bool check_bounds = true) const;

void rm_cell(size_t i, size_t j, bool check_bounds = true, bool check_exists = true);

void insert_cell(size_t i, size_t j, const Cell< Cell_Type > & v, bool check_bounds, bool check_exists);
void insert_cell(size_t i, size_t j, Cell< Cell_Type > && v, bool check_bounds, bool check_exists);
void insert_cell(size_t i, size_t j, Cell_Type v, bool check_bounds, bool check_exists);

void swap_cells(
size_t i0, size_t j0, size_t i1, size_t j1, bool check_bounds = true,
int check_exists = CHECK::BOTH,
int * report = nullptr
);

void toggle_cell(size_t i, size_t j, bool check_bounds = true, int check_exists = EXISTS::UKNOWN);
void toggle_lock(size_t i, size_t j, bool check_bounds = true);
///@}

/**@name Column/row wise interchange*/
///@{
void swap_rows(size_t i0, size_t i1, bool check_bounds = true);
void swap_cols(size_t j0, size_t j1, bool check_bounds = true);

void zero_row(size_t i, bool check_bounds = true);
void zero_col(size_t j, bool check_bounds = true);
///@}

void transpose();
void clear(bool hard = true);
void resize(size_t N_, size_t M_);
void reserve();

// Advances operators
// void toggle_iterator

// Misc
void print(const char * fmt = nullptr, ...) const;
void print_n(size_t nrow, size_t ncol, const char * fmt = nullptr, ...) const;

/**
* @name Arithmetic operators
*
*
*/
///@{
BArray<Cell_Type,Data_Type>& operator+=(const BArray<Cell_Type,Data_Type>& rhs);
BArray<Cell_Type,Data_Type>& operator+=(const Cell_Type & rhs);

BArray<Cell_Type,Data_Type>& operator-=(const BArray<Cell_Type,Data_Type>& rhs);
BArray<Cell_Type,Data_Type>& operator-=(const Cell_Type & rhs);

BArray<Cell_Type,Data_Type>& operator/=(const Cell_Type & rhs);
BArray<Cell_Type,Data_Type>& operator*=(const Cell_Type & rhs);
///@}

// /**
// * @name Casting between types
// */
Expand Down
14 changes: 7 additions & 7 deletions include/barry/barray-iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
// #include "typedefs.hpp"
// #include "barray-bones.hpp"

#ifndef BARRAY_ITERATOR_HPP
#ifndef BARRAY_ITERATOR_HPP
#define BARRAY_ITERATOR_HPP 1

template<typename Cell_Type, typename Data_Type>
class ConstBArrayRowIter {
public:

size_t current_row, current_col;
typename Row_type<Cell_Type>::const_iterator iter;
const BArray<Cell_Type,Data_Type> * Array;

ConstBArrayRowIter(const BArray<Cell_Type,Data_Type> * Array_) : Array(Array_) {

// Finding the first entry of the iterator
for (size_t i = 0u; i < Array->nrow(); ++i)
if (A_ROW(i).size() != 0u) {
iter = A_ROW(i).begin();
break;
}

return;

};
~ConstBArrayRowIter() {};

// operat

};

#endif
6 changes: 3 additions & 3 deletions include/barry/barray-meat-operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BARRAY_TEMPLATE(BARRAY_TYPE()&, operator+=) (

// Must be compatible
checkdim_(*this, rhs);

for (size_t i = 0u; i < nrow(); ++i)
for (size_t j = 0u; j < ncol(); ++j)
this->operator()(i, j) += rhs.get_cell(i, j);
Expand All @@ -62,7 +62,7 @@ BARRAY_TEMPLATE(BARRAY_TYPE()&, operator-=) (

// Must be compatible
checkdim_(*this, rhs);

for (size_t i = 0u; i < nrow(); ++i) {
for (size_t j = 0u; j < ncol(); ++j) {
this->operator()(i, j) -= rhs.get_cell(i, j);
Expand Down Expand Up @@ -126,4 +126,4 @@ BARRAY_TEMPLATE(BARRAY_TYPE()&, operator/=) (
#undef ROW
#undef COL

#endif
#endif
Loading
Loading