1 #ifndef BARRY_TYPEDEFS_HPP
2 #define BARRY_TYPEDEFS_HPP 1
51 typedef std::vector< std::pair< std::vector<double>,
size_t > >
Counts_type;
64 template <
class Type_A >
class Cell;
66 template<
typename Cell_Type>
69 template<
typename Cell_Type>
77 template<
typename Cell_Type>
82 std::vector< Cell_Type >
val;
104 template <
typename T>
112 std::size_t hash =
hasher(dat[0u]);
118 for (
size_t i = 1u;
i < dat.size(); ++
i)
119 hash ^=
hasher(dat[
i]) + 0x9e3779b9 + (hash<<6) + (hash>>2);
127 template<
typename Ta =
double,
typename Tb =
size_t>
149 std::vector<size_t> idx(nrows);
150 std::iota(idx.begin(), idx.end(), 0);
152 std::sort(idx.begin(), idx.end(),
153 [&v,nrows,ncols,start](
size_t i1,
size_t i2) {
155 for (size_t j = 0u; j < ncols; ++j)
157 if (*(v + (nrows * j + i1+start)) == *(v + (nrows * j + i2 + start)))
160 return *(v + (nrows * j + i1+start)) < *(v + (nrows * j + i2 + start));
172 template <
typename Cell_Type,
typename Data_Type>
class BArray;
173 template <
typename Array_Type,
typename Counter_Type>
class Counter;
174 template <
typename Cell_Type,
typename Data_Type>
class BArrayDense;
186 template <
typename Array_Type,
typename Data_Type>
187 using Counter_fun_type = std::function<double(
const Array_Type &,
size_t,
size_t, Data_Type &)>;
189 template <
typename Array_Type,
typename Data_Type>
190 using Rule_fun_type = std::function<bool(
const Array_Type &,
size_t,
size_t, Data_Type &)>;
199 template <
typename Array_Type,
typename Data_Type>
200 using Hasher_fun_type = std::function<std::vector<double>(
const Array_Type &, Data_Type *)>;
208 template <
typename T>
211 const std::vector< T > & a,
212 const std::vector< T > & b
215 if (a.size() != b.size())
218 std::string err =
"-a- and -b- should have the same length. length(a) = " +
219 std::to_string(a.size()) +
" and length(b) = " + std::to_string(b.size()) +
221 throw std::length_error(err);
226 while (a[
i] == b[
i]) {
234 template <
typename T>
236 const std::vector< T > & a,
237 const std::vector< T > & b,
241 if (a.size() != b.size())
243 std::string err =
"-a- and -b- should have the same length. length(a) = " +
244 std::to_string(a.size()) +
" and length(b) = " + std::to_string(b.size()) +
246 throw std::length_error(err);
250 while (
static_cast<double>(std::fabs(a[
i] - b[
i])) < eps) {
259 #if defined(__OPENMP) || defined(_OPENMP)
260 #pragma omp declare simd
262 template <
typename T>
270 #if defined(__OPENMP) || defined(_OPENMP)
271 #pragma omp simd reduction(+:res)
272 #elif defined(__GNUC__) && !defined(__clang__)
275 for (
size_t i = 0u;
i < n; ++
i)
276 res += (*(a +
i) * *(b +
i));
282 #if defined(__OPENMP) || defined(_OPENMP)
283 #pragma omp declare simd
293 #if defined(__OPENMP) || defined(_OPENMP)
294 #pragma omp simd reduction(+:res)
295 #elif defined(__GNUC__) && !defined(__clang__)
298 for (
size_t i = 0u;
i < n; ++
i)
299 res += (*(a +
i) * *(b +
i));
Baseline class for binary arrays.
Baseline class for binary arrays.
Entries in BArray. For now, it only has two members:
A counter function based on change statistics.
A wrapper class to store source, target, val from a BArray object.
std::vector< size_t > target
std::vector< size_t > source
std::vector< Cell_Type > val
Data_Type hasher(counter_.hasher)
Data_Type &&counter_ noexcept
Integer constants used to specify which cell should be check.
Integer constants used to specify which cell should be check to exist or not.
std::size_t operator()(std::vector< T > const &dat) const noexcept
std::unordered_map< std::vector< Ta >, Tb, vecHasher< Ta > > MapVec_type
bool vec_equal(const std::vector< T > &a, const std::vector< T > &b)
Compares if -a- and -b- are equal.
std::vector< std::pair< std::vector< double >, size_t > > Counts_type
Map< size_t, Cell< Cell_Type > > Row_type
std::function< bool(const Array_Type &, size_t, size_t, Data_Type &)> Rule_fun_type
std::function< std::vector< double >(const Array_Type &, Data_Type *)> Hasher_fun_type
Hasher function used by the counter.
std::vector< size_t > sort_array(const double *v, size_t start, size_t ncols, size_t nrows)
Ascending sorting an array.
T vec_inner_prod(const T *a, const T *b, size_t n)
std::function< double(const Array_Type &, size_t, size_t, Data_Type &)> Counter_fun_type
Counter and rule functions.
Map< size_t, Cell< Cell_Type > * > Col_type
bool vec_equal_approx(const std::vector< T > &a, const std::vector< T > &b, double eps=1e-100)