Mackey  V3.3
A C++ library for computing RO(G) graded homology
General.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <vector>
3 #include "Types/Aliases.hpp"
4 #include <numeric> //lcm
5 #include <iostream> //cerr
6 
9 
11 namespace mackey
12 {
13 
19  template <typename T>
21  {
22  public:
24  InterpolatingVectorGenerator(const T& min, const T& max);
25 
27  size_t size() const;
28 
30  std::vector<T> operator()() const;
31 
35  {
36  public:
38  const T& operator*() const;
40  bool operator!=(const const_iterator& other) const;
42  auto& operator++();
43 
44  private:
45  const_iterator(const T& min, const T& max, bool completed);
46  const T& min, max;
47  bool completed;
48  T generated;
50  };
52  auto begin() const;
54  auto end() const;
55 
56  private:
57  const T& min, max;
58  };
59 
64  template <typename T>
65  std::vector<std::vector<T>> combinations(const std::vector<std::vector<T>>& v);
66 
69  template <typename T>
70  std::vector<T> tail(const T* const& ptr, int size, int start);
71 
73  template <typename rank_t>
74  rank_t basisElement(int length, int position, int multiple = 1);
75 
77  template <typename T, typename S>
78  T KeepRow(const T& A, const S& Z);
79 
81  template <typename T, typename S>
82  T KeepCol(const T& A, const S& Z);
83 
85  template <typename Derived>
86  int64_t summation(const Eigen::MatrixBase<Derived>& A);
87 
88  template <typename rank_t>
89  int64_t summation(const rank_t& u, int64_t limit);
90 
92  template <typename T>
93  void rotate(T& V);
94 
97  template <typename Matrix_t>
98  Matrix_t altmatrix(int m, int n, const std::vector<scalar_t<Matrix_t>>& v);
99 
101  template <typename T>
102  bool isZero(const std::vector<T>& a);
103 
105  template <typename T>
106  std::vector<T> operator+(const std::vector<T>& a, const std::vector<T>& b);
107 
109  template <typename T>
110  std::vector<T> operator-(const std::vector<T>& a, const std::vector<T>& b);
111 
113  template <typename T>
114  std::vector<T> operator-(const std::vector<T>& a);
115 
117  template <typename T>
118  std::vector<T> operator*(T a, const std::vector<T>& b);
119 
121  template <typename T>
122  std::ostream& operator<<(std::ostream& out, const std::vector<T>& a);
123 
125  template <typename T>
126  int lcm(const T& v);
127 
129  template <typename...>
130  class Hash;
131 
133  template <>
134  class Hash<>
135  {
136  public:
137  template <typename S>
138  size_t operator()(const S&) const;
139  };
140 
142  template <typename T>
143  class Hash<T>
144  {
145  const T max;
146 
147  public:
148  Hash(const T&);
149  size_t max_hash() const;
150  template <typename S>
151  size_t operator()(const S&) const;
152  };
153 
155  template <typename T>
157  {
158  const T min, max;
159 
160  public:
161  size_t max_hash() const;
162  Hash(const T&, const T&);
163  template <typename S>
164  size_t operator()(const S&) const;
165  };
166 
168  template <typename T, typename S>
169  int64_t perfect_hash(const T& deg, const S& min, const S& max);
170 
172  template <typename T>
173  std::vector<triplet_t<T>> make_triplets(const T& a);
174 
176  template <typename T, typename S>
177  std::vector<triplet_t<T>> keep_row_triplets(const T& a, const S& keep);
178 
179  namespace implementation_details
180  {
182  template <typename T, bool = mackey::SFINAE::is_Sparse<T>::value>
183  class it_nnz_conditional;
184  }
185 
193  template <typename T, bool row_only, bool col_only>
194  class IteratorNNZ : implementation_details::it_nnz_conditional<T>
195  {
196  typedef typename T::StorageIndex storage;
197  using implementation_details::it_nnz_conditional<T>::is_sparse;
198  using implementation_details::it_nnz_conditional<T>::inner_ind;
199  using implementation_details::it_nnz_conditional<T>::it;
200  public:
201  auto value();
202  auto row();
203  auto col();
205  operator bool();
206 
211  IteratorNNZ(const T& matrix, storage row_start, storage col_start);
212 
216  IteratorNNZ(const T& matrix, storage start);
217 
218  private:
219  const T& matrix;
220  const storage inner_start;
221  storage outer_ind;
222  void increase_until_it_works();
223  };
224 }
225 #include "impl/General.ipp"
Contains general template aliases.
Perfect hashes vectors between given min and max.
Definition: General.hpp:157
size_t max_hash() const
size_t operator()(const S &) const
Hash(const T &, const T &)
Perfect hashes vectors between 0 and given max.
Definition: General.hpp:144
size_t max_hash() const
size_t operator()(const S &) const
Hashes vectors with collisions.
Definition: General.hpp:135
size_t operator()(const S &) const
General template class for hashing vectors.
Definition: General.hpp:130
Constant iterator through generated vectors.
Definition: General.hpp:35
bool operator!=(const const_iterator &other) const
Inequality of iterators.
const T & operator*() const
Returns the generated vector.
Generates all vectors interpolating between given min and max vectors.
Definition: General.hpp:21
size_t size() const
Returns the total amount of elements that will be generated.
InterpolatingVectorGenerator(const T &min, const T &max)
Constructor using min, max and policy.
auto begin() const
Initial generator.
auto end() const
Terminal generator.
std::vector< T > operator()() const
Returns vector of all generated elements.
Iterator over nonzero entries of Eigen matrices.
Definition: General.hpp:195
IteratorNNZ(const T &matrix, storage row_start, storage col_start)
Constructor given matrix and block (lower right corner)
IteratorNNZ & operator++()
Increase iterator.
auto col()
The column index.
IteratorNNZ(const T &matrix, storage start)
Constructor given matrix and symmetric block.
auto row()
The row index.
auto value()
The entry of the matrix.
Everything in this library is under this namespace.
Definition: Box.hpp:9
typename T::Scalar scalar_t
Scalar of matrix.
Definition: Aliases.hpp:14
void rotate(T &V)
Transforms V[0],V[1],...,V[n] to V[1],V[2],...,V[n],V[0].
std::ostream & operator<<(std::ostream &, const Chains< rank_t, diff_t > &)
Prints chain complex.
Z_mod< N, T > operator-(Z_mod< N, T > a)
T KeepCol(const T &A, const S &Z)
Makes a new matrix out of A keeping only its columns indicated by Z.
T KeepRow(const T &A, const S &Z)
Makes a new matrix out of A keeping only its rows indicated by Z.
bool isZero(const std::vector< T > &a)
Tests if vector is zero.
int64_t summation(const Eigen::MatrixBase< Derived > &A)
Takes the sum of the entries of an Eigen vector at higher precision than its inputs.
std::vector< std::vector< T > > combinations(const std::vector< std::vector< T >> &v)
Given a vector of vectors v form all combinations of the form {v[0][?],v[1][?],......
Z_mod< N, T > operator*(Z_mod< N, T > a, Z_mod< N, T > b)
std::vector< triplet_t< T > > make_triplets(const T &a)
Turn sparse matrix into a vector of Eigen triplets.
std::vector< T > operator+(const std::vector< T > &a, const std::vector< T > &b)
Coordinate-wise sum of vectors (up to the minimum of their lengths)
std::vector< triplet_t< T > > keep_row_triplets(const T &a, const S &keep)
Turn sparse matrix into a vector of Eigen triplets.
std::vector< T > tail(const T *const &ptr, int size, int start)
Given vector or array returns vector starting from index start.
int64_t perfect_hash(const T &deg, const S &min, const S &max)
Perfect hash vectors given minimum and maximum values of entries.
rank_t basisElement(int length, int position, int multiple=1)
Makes the multiple of the basis vector 0,...,multiple,...,0.
Matrix_t altmatrix(int m, int n, const std::vector< scalar_t< Matrix_t >> &v)
Creates a matrix of size m x n that alternates the given vector v.
int lcm(const T &v)
Least common multiple of vector of elements.