IVSparse  v1.0
A sparse matrix compression library.
IVCSC_Vector.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 namespace IVSparse {
12 
24 template <typename T, typename indexT, uint8_t compressionLevel, bool columnMajor>
25 class SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector {
26  private:
27  //* Private Class Variables *//
28 
29  size_t size = 0; // size of the vector in bytes
30 
31  void *data = nullptr; // data of the vector
32  void *endPtr = nullptr; // pointer to the end of the vector
33 
34  uint32_t length = 0; // length of the vector
35 
36  uint8_t indexWidth = 1; // width of the indices
37 
38  uint32_t nnz = 0; // number of non-zero elements in the vector
39 
40  //* Private Class Methods *//
41 
42  // User checks to confirm a valid vector
43  void userChecks();
44 
45  // Calculates the size of the vector in bytes
46  void calculateCompSize();
47 
48  public:
49  //* Constructors & Destructor *//
52 
58  Vector(){};
59 
64  Vector(uint32_t length);
65 
74 
80 
84  ~Vector();
85 
87 
88  //* Getters *//
91 
96  T coeff(uint32_t index);
97 
101  void *begin();
102 
106  void *end();
107 
111  size_t byteSize();
112 
116  uint32_t innerSize();
117 
121  uint32_t outerSize();
122 
126  uint32_t nonZeros();
127 
131  uint32_t getLength();
132 
134 
135  //* Utility Methods *//
138 
143  void print();
144 
146 
147  //* Calculations *//
150 
155  double norm();
156 
160  T sum();
161 
165  double dot(Eigen::Vector<T, -1> &other);
166 
170  double dot(Eigen::SparseVector<T, -1> &other);
171 
173 
174  //* Operator Overloads *//
175 
176  // In place scalar multiplication
177  void operator*=(T scalar);
178 
179  // scalar multiplication
181 
182  // equality operator
183  bool operator==(typename SparseMatrix<T, indexT, compressionLevel,
184  columnMajor>::Vector &vec);
185 
186  // inequality operator
187  bool operator!=(typename SparseMatrix<T, indexT, compressionLevel,
188  columnMajor>::Vector &vec);
189 
190  // coefficient access
191  T operator[](uint32_t index);
192 
193  // boolean operator
194  operator bool() { return (char *)endPtr - indexWidth > data; };
195 
196  // assignment operator
199 
200 }; // class Vector
201 
202 } // namespace IVSparse
Definition: IVCSC_Vector.hpp:25
Vector()
Definition: IVCSC_Vector.hpp:58
uint32_t innerSize() const
Definition: IVSparse_Base_Methods.hpp:33
uint32_t nonZeros() const
Definition: IVSparse_Base_Methods.hpp:39
size_t byteSize() const
Definition: IVSparse_Base_Methods.hpp:42
uint32_t outerSize() const
Definition: IVSparse_Base_Methods.hpp:36
Definition: IVCSC_SparseMatrix.hpp:29
T coeff(uint32_t row, uint32_t col)
Definition: IVCSC_Methods.hpp:17
void print()
Definition: IVCSC_Methods.hpp:97
T sum()
Definition: IVCSC_BLAS.hpp:239
double norm()
Definition: IVCSC_BLAS.hpp:256