barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
barray-meat-operators.hpp
Go to the documentation of this file.
1 // #include <stdexcept>
2 // #include "barray-bones.hpp"
3 
4 #ifndef BARRY_BARRAY_MEAT_OPERATORS_HPP
5 #define BARRY_BARRAY_MEAT_OPERATORS_HPP 1
6 
7 #define BARRAY_TYPE() BArray<Cell_Type, Data_Type>
8 
9 #define BARRAY_TEMPLATE_ARGS() <typename Cell_Type, typename Data_Type>
10 
11 #define BARRAY_TEMPLATE(a,b) \
12  template BARRAY_TEMPLATE_ARGS() inline a BARRAY_TYPE()::b
13 
14 #define ROW(a) this->el_ij[a]
15 #define COL(a) this->el_ji[a]
16 
18 inline void checkdim_(
19  const BARRAY_TYPE()& lhs,
20  const BARRAY_TYPE()& rhs
21 ) {
22 
23  if (lhs.ncol() != rhs.ncol())
24  throw std::length_error("Number of columns do not match.");
25 
26  if (lhs.nrow() != rhs.nrow())
27  throw std::length_error("Number of rows do not match.");
28 
29  return;
30 }
31 
32 BARRAY_TEMPLATE(BARRAY_TYPE()&, operator+=) (
34 ) {
35 
36  // Must be compatible
37  checkdim_(*this, rhs);
38 
39  for (size_t i = 0u; i < nrow(); ++i)
40  for (size_t j = 0u; j < ncol(); ++j)
41  this->operator()(i, j) += rhs.get_cell(i, j);
42 
43  return *this;
44 }
45 
46 BARRAY_TEMPLATE(BARRAY_TYPE()&, operator+=) (
47  const Cell_Type& rhs
48 ) {
49 
50  for (size_t i = 0u; i < nrow(); ++i) {
51  for (size_t j = 0u; j < ncol(); ++j) {
52  this->operator()(i, j) += rhs;
53  }
54  }
55 
56  return *this;
57 }
58 
59 BARRAY_TEMPLATE(BARRAY_TYPE()&, operator-=) (
61 ) {
62 
63  // Must be compatible
64  checkdim_(*this, rhs);
65 
66  for (size_t i = 0u; i < nrow(); ++i) {
67  for (size_t j = 0u; j < ncol(); ++j) {
68  this->operator()(i, j) -= rhs.get_cell(i, j);
69  }
70  }
71 
72  return *this;
73 }
74 
75 BARRAY_TEMPLATE(BARRAY_TYPE()&, operator-=) (
76  const Cell_Type& rhs
77 ) {
78 
79  for (size_t i = 0u; i < nrow(); ++i) {
80  for (size_t j = 0u; j < ncol(); ++j) {
81  this->operator()(i, j) -= rhs;
82  }
83  }
84 
85  return *this;
86 }
87 
88 BARRAY_TEMPLATE(BARRAY_TYPE()&, operator*=) (
89  const Cell_Type& rhs
90 ) {
91 
92  for (size_t i = 0u; i < nrow(); ++i) {
93 
94  if (ROW(i).size() == 0u)
95  continue;
96 
97  for (auto col = ROW(i).begin(); col != ROW(i).end(); ++col) {
98  this->operator()(i, col->first) *= rhs;
99  }
100  }
101 
102  return *this;
103 }
104 
105 BARRAY_TEMPLATE(BARRAY_TYPE()&, operator/=) (
106  const Cell_Type& rhs
107 ) {
108 
109  for (size_t i = 0u; i < nrow(); ++i) {
110 
111  if (ROW(i).size() == 0u)
112  continue;
113 
114  for (auto col = ROW(i).begin(); col != ROW(i).end(); ++col) {
115  this->operator()(i, col->first) /= rhs;
116  }
117  }
118 
119  return *this;
120 }
121 
122 #undef BARRAY_TYPE
123 #undef BARRAY_TEMPLATE_ARGS
124 #undef BARRAY_TEMPLATE
125 
126 #undef ROW
127 #undef COL
128 
129 #endif
j< ncol();++j) this-> operator()(i, j)+
#define ROW(a)
#define BARRAY_TEMPLATE_ARGS()
Data_Type & rhs
#define BARRAY_TYPE()
#define BARRAY_TEMPLATE(a, b)
size_t size_t j
size_t i