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