barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
BArray< Cell_Type, Data_Type > Class Template Reference

Baseline class for binary arrays. More...

#include <barray-bones.hpp>

Public Member Functions

bool operator== (const BArray< Cell_Type, Data_Type > &Array_)
 
 ~BArray ()
 
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
 
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
 
void get_row_vec (std::vector< Cell_Type > *x, size_t i, bool check_bounds=true) const
 
const Row_type< Cell_Type > & row (size_t i, bool check_bounds=true) const
 
const Col_type< Cell_Type > & col (size_t i, bool check_bounds=true) const
 
Entries< Cell_Type > get_entries () const
 Get the edgelist. More...
 
void transpose ()
 
void clear (bool hard=true)
 
void resize (size_t N_, size_t M_)
 
void reserve ()
 
void print (const char *fmt=nullptr,...) const
 
void print_n (size_t nrow, size_t ncol, const char *fmt=nullptr,...) const
 
bool is_dense () const noexcept
 
Constructors
Parameters
N_Number of rows
M_Number of columns
sourceAn unsigned vector ranging from 0 to N_
targetAn size_t vector ranging from 0 to M_
targetWhen true tries to add repeated observations.
 BArray ()
 Zero-size array. More...
 
 BArray (size_t N_, size_t M_)
 Empty array. More...
 
 BArray (size_t N_, size_t M_, const std::vector< size_t > &source, const std::vector< size_t > &target, const std::vector< Cell_Type > &value, bool add=true)
 Edgelist with data. More...
 
 BArray (size_t N_, size_t M_, const std::vector< size_t > &source, const std::vector< size_t > &target, bool add=true)
 Edgelist with no data (simpler) More...
 
 BArray (const BArray< Cell_Type, Data_Type > &Array_, bool copy_data=false)
 Copy constructor. More...
 
BArray< Cell_Type, Data_Type > & operator= (const BArray< Cell_Type, Data_Type > &Array_)
 Assignment constructor. More...
 
 BArray (BArray< Cell_Type, Data_Type > &&x) noexcept
 Move operator. More...
 
BArray< Cell_Type, Data_Type > & operator= (BArray< Cell_Type, Data_Type > &&x) noexcept
 Move assignment. More...
 
void set_data (Data_Type *data_, bool delete_data_=false)
 Set the data object. More...
 
Data_Type * D_ptr ()
 
const Data_Type * D_ptr () const
 
Data_Type & D ()
 
const Data_Type & D () const
 
void flush_data ()
 
Queries

is_empty queries a single cell. nrow, ncol, and nnozero return the number of rows, columns, and non-zero cells respectively.

Parameters
i,jCoordinates
check_boundsIf false avoids checking bounds.
bool is_empty (size_t i, size_t j, bool check_bounds=true) const
 
size_t nrow () const noexcept
 
size_t ncol () const noexcept
 
size_t nnozero () const noexcept
 
Cell< Cell_Type > default_val () const
 
Cell-wise insertion/deletion
Parameters
i,jRow,column
check_boundsWhen true and out of range, the function throws an error.
check_existsWither check if the cell exists (before trying to 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)
 
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)
 
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)
 

Public Attributes

bool visited = false
 

Friends

class BArrayCell< Cell_Type, Data_Type >
 
class BArrayCell_const< Cell_Type, Data_Type >
 

Detailed Description

template<typename Cell_Type = bool, typename Data_Type = bool>
class BArray< Cell_Type, Data_Type >

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_maps, i.e. std::vector< std::unordered_map<size_t,Cell_Type> >.

Template Parameters
Cell_TypeType of cell (any type).
Data_TypeData type of the array (bool default).

Definition at line 28 of file barray-bones.hpp.

Constructor & Destructor Documentation

◆ BArray() [1/6]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::BArray ( )
inline

Zero-size array.

Definition at line 69 of file barray-bones.hpp.

◆ BArray() [2/6]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::BArray ( size_t  N_,
size_t  M_ 
)
inline

Empty array.

Definition at line 72 of file barray-bones.hpp.

◆ BArray() [3/6]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::BArray ( size_t  N_,
size_t  M_,
const std::vector< size_t > &  source,
const std::vector< size_t > &  target,
const std::vector< Cell_Type > &  value,
bool  add = true 
)

Edgelist with data.

◆ BArray() [4/6]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::BArray ( size_t  N_,
size_t  M_,
const std::vector< size_t > &  source,
const std::vector< size_t > &  target,
bool  add = true 
)

Edgelist with no data (simpler)

◆ BArray() [5/6]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::BArray ( const BArray< Cell_Type, Data_Type > &  Array_,
bool  copy_data = false 
)

Copy constructor.

◆ BArray() [6/6]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::BArray ( BArray< Cell_Type, Data_Type > &&  x)
noexcept

Move operator.

◆ ~BArray()

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray< Cell_Type, Data_Type >::~BArray ( )

Member Function Documentation

◆ clear()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::clear ( bool  hard = true)

◆ col()

template<typename Cell_Type = bool, typename Data_Type = bool>
const Col_type< Cell_Type >& BArray< Cell_Type, Data_Type >::col ( size_t  i,
bool  check_bounds = true 
) const

◆ D() [1/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
Data_Type& BArray< Cell_Type, Data_Type >::D ( )

◆ D() [2/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
const Data_Type& BArray< Cell_Type, Data_Type >::D ( ) const

◆ D_ptr() [1/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
Data_Type* BArray< Cell_Type, Data_Type >::D_ptr ( )

◆ D_ptr() [2/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
const Data_Type* BArray< Cell_Type, Data_Type >::D_ptr ( ) const

◆ default_val()

template<typename Cell_Type = bool, typename Data_Type = bool>
Cell<Cell_Type> BArray< Cell_Type, Data_Type >::default_val ( ) const

◆ flush_data()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::flush_data ( )

◆ get_cell()

template<typename Cell_Type = bool, typename Data_Type = bool>
Cell_Type BArray< Cell_Type, Data_Type >::get_cell ( size_t  i,
size_t  j,
bool  check_bounds = true 
) const

◆ get_col_vec() [1/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
std::vector< Cell_Type > BArray< Cell_Type, Data_Type >::get_col_vec ( size_t  i,
bool  check_bounds = true 
) const

◆ get_col_vec() [2/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::get_col_vec ( std::vector< Cell_Type > *  x,
size_t  i,
bool  check_bounds = true 
) const

◆ get_entries()

template<typename Cell_Type = bool, typename Data_Type = bool>
Entries<Cell_Type> BArray< Cell_Type, Data_Type >::get_entries ( ) const

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.

Returns
Entries<Cell_Type>

◆ get_row_vec() [1/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
std::vector< Cell_Type > BArray< Cell_Type, Data_Type >::get_row_vec ( size_t  i,
bool  check_bounds = true 
) const

◆ get_row_vec() [2/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::get_row_vec ( std::vector< Cell_Type > *  x,
size_t  i,
bool  check_bounds = true 
) const

◆ insert_cell() [1/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::insert_cell ( size_t  i,
size_t  j,
Cell< Cell_Type > &&  v,
bool  check_bounds,
bool  check_exists 
)

◆ insert_cell() [2/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::insert_cell ( size_t  i,
size_t  j,
Cell_Type  v,
bool  check_bounds,
bool  check_exists 
)

◆ insert_cell() [3/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::insert_cell ( size_t  i,
size_t  j,
const Cell< Cell_Type > &  v,
bool  check_bounds,
bool  check_exists 
)

◆ is_dense()

template<typename Cell_Type = bool, typename Data_Type = bool>
bool BArray< Cell_Type, Data_Type >::is_dense ( ) const
inlinenoexcept

Definition at line 241 of file barray-bones.hpp.

◆ is_empty()

template<typename Cell_Type = bool, typename Data_Type = bool>
bool BArray< Cell_Type, Data_Type >::is_empty ( size_t  i,
size_t  j,
bool  check_bounds = true 
) const

◆ ncol()

template<typename Cell_Type = bool, typename Data_Type = bool>
size_t BArray< Cell_Type, Data_Type >::ncol ( ) const
noexcept

◆ nnozero()

template<typename Cell_Type = bool, typename Data_Type = bool>
size_t BArray< Cell_Type, Data_Type >::nnozero ( ) const
noexcept

◆ nrow()

template<typename Cell_Type = bool, typename Data_Type = bool>
size_t BArray< Cell_Type, Data_Type >::nrow ( ) const
noexcept

◆ operator()() [1/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArrayCell<Cell_Type,Data_Type> BArray< Cell_Type, Data_Type >::operator() ( size_t  i,
size_t  j,
bool  check_bounds = true 
)

◆ operator()() [2/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
const Cell_Type BArray< Cell_Type, Data_Type >::operator() ( size_t  i,
size_t  j,
bool  check_bounds = true 
) const

◆ operator*=()

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator*= ( const Cell_Type &  rhs)

◆ operator+=() [1/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator+= ( const BArray< Cell_Type, Data_Type > &  rhs)

◆ operator+=() [2/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator+= ( const Cell_Type &  rhs)

◆ operator+=() [3/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator+= ( const std::pair< size_t, size_t > &  coords)

◆ operator-=() [1/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator-= ( const BArray< Cell_Type, Data_Type > &  rhs)

◆ operator-=() [2/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator-= ( const Cell_Type &  rhs)

◆ operator-=() [3/3]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator-= ( const std::pair< size_t, size_t > &  coords)

◆ operator/=()

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator/= ( const Cell_Type &  rhs)

◆ operator=() [1/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator= ( BArray< Cell_Type, Data_Type > &&  x)
noexcept

Move assignment.

◆ operator=() [2/2]

template<typename Cell_Type = bool, typename Data_Type = bool>
BArray<Cell_Type,Data_Type>& BArray< Cell_Type, Data_Type >::operator= ( const BArray< Cell_Type, Data_Type > &  Array_)

Assignment constructor.

◆ operator==()

template<typename Cell_Type = bool, typename Data_Type = bool>
bool BArray< Cell_Type, Data_Type >::operator== ( const BArray< Cell_Type, Data_Type > &  Array_)

◆ out_of_range()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::out_of_range ( size_t  i,
size_t  j 
) const

◆ print()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::print ( const char *  fmt = nullptr,
  ... 
) const

◆ print_n()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::print_n ( size_t  nrow,
size_t  ncol,
const char *  fmt = nullptr,
  ... 
) const

◆ reserve()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::reserve ( )

◆ resize()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::resize ( size_t  N_,
size_t  M_ 
)

◆ rm_cell()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::rm_cell ( size_t  i,
size_t  j,
bool  check_bounds = true,
bool  check_exists = true 
)

◆ row()

template<typename Cell_Type = bool, typename Data_Type = bool>
const Row_type< Cell_Type >& BArray< Cell_Type, Data_Type >::row ( size_t  i,
bool  check_bounds = true 
) const

◆ set_data()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::set_data ( Data_Type *  data_,
bool  delete_data_ = false 
)

Set the data object.

Parameters
data_
delete_data_

◆ swap_cells()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::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 
)

◆ swap_cols()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::swap_cols ( size_t  j0,
size_t  j1,
bool  check_bounds = true 
)

◆ swap_rows()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::swap_rows ( size_t  i0,
size_t  i1,
bool  check_bounds = true 
)

◆ toggle_cell()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::toggle_cell ( size_t  i,
size_t  j,
bool  check_bounds = true,
int  check_exists = EXISTS::UKNOWN 
)

◆ toggle_lock()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::toggle_lock ( size_t  i,
size_t  j,
bool  check_bounds = true 
)

◆ transpose()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::transpose ( )

◆ zero_col()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::zero_col ( size_t  j,
bool  check_bounds = true 
)

◆ zero_row()

template<typename Cell_Type = bool, typename Data_Type = bool>
void BArray< Cell_Type, Data_Type >::zero_row ( size_t  i,
bool  check_bounds = true 
)

Friends And Related Function Documentation

◆ BArrayCell< Cell_Type, Data_Type >

template<typename Cell_Type = bool, typename Data_Type = bool>
friend class BArrayCell< Cell_Type, Data_Type >
friend

Definition at line 1 of file barray-bones.hpp.

◆ BArrayCell_const< Cell_Type, Data_Type >

template<typename Cell_Type = bool, typename Data_Type = bool>
friend class BArrayCell_const< Cell_Type, Data_Type >
friend

Definition at line 1 of file barray-bones.hpp.

Member Data Documentation

◆ visited

template<typename Cell_Type = bool, typename Data_Type = bool>
bool BArray< Cell_Type, Data_Type >::visited = false

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.

Definition at line 54 of file barray-bones.hpp.


The documentation for this class was generated from the following file: