barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
rules-meat.hpp
Go to the documentation of this file.
1 #ifndef BARRY_RULES_MEAT_HPP
2 #define BARRY_RULES_MEAT_HPP 1
3 
4 template <typename Array_Type, typename Data_Type>
6  const Rules<Array_Type,Data_Type> & rules_
7 ) {
8 
9  // Copy all rules, if a rule is tagged as
10  // to be deleted, then copy the value
11  for (auto i = 0u; i != rules_.size(); ++i)
12  this->add_rule(rules_.data[i]);
13 
14  return;
15 
16 }
17 
18 template <typename Array_Type, typename Data_Type>
20  const Rules<Array_Type,Data_Type> & rules_
21 ) {
22 
23  if (this != &rules_) {
24 
25  // Copy all rules, if a rule is tagged as
26  // to be deleted, then copy the value
27  for (auto i = 0u; i != rules_.size(); ++i)
28  this->add_rule(rules_.data[i]);
29 
30  }
31 
32  return *this;
33 
34 }
35 
36 template<typename Array_Type, typename Data_Type>
37 inline Data_Type & Rule<Array_Type,Data_Type>::D()
38 {
39  return dat;
40 }
41 
42 template<typename Array_Type, typename Data_Type>
43 inline bool Rule<Array_Type,Data_Type>::operator()(const Array_Type & a, size_t i, size_t j) {
44  return fun(a, i, j, dat);
45 }
46 
47 template<typename Array_Type, typename Data_Type>
49 {
50  return name;
51 }
52 
53 template<typename Array_Type, typename Data_Type>
55 {
56  return desc;
57 }
58 
59 template<typename Array_Type, typename Data_Type>
60 inline std::string Rule<Array_Type,Data_Type>::get_name() const
61 {
62  return name;
63 }
64 
65 template<typename Array_Type, typename Data_Type>
67 {
68  return desc;
69 }
70 
71 template <typename Array_Type, typename Data_Type>
74 ) {
75 
76  data.push_back(rule);
77 
78  return;
79 }
80 
81 template <typename Array_Type, typename Data_Type>
84  Data_Type data_,
85  std::string name_,
86  std::string description_
87 ) {
88 
90  rule_,
91  data_,
92  name_,
93  description_
94  ));
95 
96  return;
97 
98 }
99 
100 template <typename Array_Type, typename Data_Type>
102  const Array_Type & a, size_t i, size_t j
103 ) {
104 
105  if (data.size()==0u)
106  return true;
107 
108  for (auto & f: data)
109  if (!f.operator()(a, i, j))
110  return false;
111 
112  return true;
113 
114 }
115 
116 template <typename Array_Type, typename Data_Type>
118  const Array_Type & a,
119  std::vector< size_t > * free,
120  std::vector< size_t > * locked
121 ) {
122 
123 
124  size_t N = a.nrow();
125  size_t K = a.ncol();
126 
127  // Reserving some space
128  (void) free->empty();
129  (void) free->reserve(2u * N * K);
130 
131  for (size_t i = 0u; i < N; ++i)
132  {
133 
134  for (size_t j = 0u; j < K; ++j)
135  {
136 
137  // Locked cells are skipped
138  if (!this->operator()(a, i, j))
139  {
140 
141  if (locked != nullptr)
142  {
143 
144  locked->push_back(i);
145  locked->push_back(j);
146 
147  }
148 
149  continue;
150 
151  }
152 
153  free->push_back(i);
154  free->push_back(j);
155 
156  }
157 
158  }
159 
160  free->shrink_to_fit();
161 
162  return;
163 
164 }
165 
166 template<typename Array_Type, typename Data_Type>
167 inline std::vector<std::string> Rules<Array_Type, Data_Type>::get_names() const
168 {
169 
170  std::vector< std::string > out;
171  out.reserve(this->size());
172  for (size_t i = 0u; i < this->size(); ++i)
173  out.push_back(this->data.at(i).get_name());
174 
175  return out;
176 
177 }
178 
179 template<typename Array_Type, typename Data_Type>
180 inline std::vector<std::string> Rules<Array_Type, Data_Type>::get_descriptions() const
181 {
182 
183  std::vector< std::string > out;
184  out.reserve(this->size());
185  for (size_t i = 0u; i < out.size(); ++i)
186  out.push_back(data.at(i).get_description());
187 
188  return out;
189 
190 }
191 
192 #endif
return * this
Rule for determining if a cell should be included in a sequence.
Definition: rules-bones.hpp:20
bool operator()(const Array_Type &a, size_t i, size_t j)
Definition: rules-meat.hpp:43
Data_Type & D()
Read/Write access to the data.
Definition: rules-meat.hpp:37
std::string & get_description()
Definition: rules-meat.hpp:54
std::string & get_name()
Definition: rules-meat.hpp:48
Vector of objects of class Rule.
Definition: rules-bones.hpp:71
size_t size() const noexcept
Definition: rules-bones.hpp:84
bool operator()(const Array_Type &a, size_t i, size_t j)
Check whether a given cell is free or locked.
Definition: rules-meat.hpp:101
void add_rule(Rule< Array_Type, Data_Type > rule)
Definition: rules-meat.hpp:72
std::vector< std::string > get_descriptions() const
Definition: rules-meat.hpp:180
void get_seq(const Array_Type &a, std::vector< size_t > *free, std::vector< size_t > *locked=nullptr)
Computes the sequence of free and locked cells in an BArray.
Definition: rules-meat.hpp:117
std::vector< std::string > get_names() const
Definition: rules-meat.hpp:167
Rules< Array_Type, Data_Type > operator=(const Rules< Array_Type, Data_Type > &rules_)
Definition: rules-meat.hpp:19
Data_Type &&counter_ desc(std::move(counter_.desc))
Move constructor.
Data_Type &&counter_ name(std::move(counter_.name))
Data_Type fun
Data_Type &&counter_ data(std::move(counter_.data))
Data_Type Counter_fun_type< Array_Type, Data_Type > Hasher_fun_type< Array_Type, Data_Type > Data_Type std::string name_
size_t size_t j
size_t i
Data_Type Counter_fun_type< Array_Type, Data_Type > Hasher_fun_type< Array_Type, Data_Type > Data_Type data_
std::function< bool(const Array_Type &, size_t, size_t, Data_Type &)> Rule_fun_type
Definition: typedefs.hpp:190