17 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
27 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
31 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
36 assert((vec >= 0 && vec < mat.
outerSize()) &&
"Vector index out of bounds");
57 catch (std::bad_alloc &e)
59 std::cerr << e.what() <<
'\n';
66 endPtr = (uint8_t *)data + size;
69 if (nnz == 0 && size > 0)
85 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
107 catch (std::bad_alloc &e)
109 std::cerr << e.what() <<
'\n';
113 memcpy(data, vec.data, size);
116 endPtr = (uint8_t *)data + size;
129 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
132 assert(std::is_floating_point<indexT>::value ==
false &&
"The index type must be a non-floating point type");
133 assert((compressionLevel == 1 || compressionLevel == 2 || compressionLevel == 3) &&
"The compression level must be either 1, 2, or 3");
134 assert((std::is_arithmetic<T>::value && std::is_arithmetic<indexT>::value) &&
"The value and index types must be numeric types");
135 assert((std::is_same<indexT, bool>::value ==
false) &&
"The index type must not be bool");
139 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
144 size +=
sizeof(
void *);
145 size +=
sizeof(
void *);
148 size += (uint8_t *)endPtr - (uint8_t *)data;
154 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
158 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
162 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
166 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
170 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
174 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
178 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
182 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
188 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
195 std::cout <<
"Vector is too large to print" << std::endl;
199 std::cout <<
"Vector: ";
200 std::cout << std::endl;
203 for (uint32_t i = 0; i < length; i++)
205 std::cout << (*this)[i] <<
" ";
208 std::cout << std::endl;
214 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
220 norm += it.value() * it.value();
226 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
238 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
245 dot += it.value() * other.coeff(it.row());
252 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
259 dot += it.value() * other.coeff(it.row());
267 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
283 if (other.data ==
nullptr)
288 length = other.length;
294 data = (uint8_t *)malloc(other.size);
295 memcpy(data, other.data, other.size);
298 length = other.length;
300 endPtr = (uint8_t *)data + size;
307 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
308 bool SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator==(
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector &other)
311 if (length != other.length)
317 if (nnz != other.nnz)
323 if (memcmp(data, other.data, size) != 0)
333 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
334 bool SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator!=(
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector &other)
336 return !(*
this == other);
340 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
341 T SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator[](uint32_t index)
346 assert(index < length &&
"The index is out of bounds");
355 if (it.getIndex() == (indexT)index)
367 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
368 void SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator*=(T scalar)
370 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(*
this); it; ++it)
374 it.coeff(it.value() * scalar);
380 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
385 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(newVector); it; ++it)
389 it.coeff(it.value() * scalar);
Definition: IVCSC_Iterator.hpp:25
Definition: IVCSC_Vector.hpp:27
uint32_t getLength()
Definition: IVCSC_Vector_Methods.hpp:183
T coeff(uint32_t index)
Definition: IVCSC_Vector_Methods.hpp:179
void print()
Definition: IVCSC_Vector_Methods.hpp:189
uint32_t innerSize()
Definition: IVCSC_Vector_Methods.hpp:155
T sum()
Definition: IVCSC_Vector_Methods.hpp:227
void * end()
Definition: IVCSC_Vector_Methods.hpp:171
size_t byteSize()
Definition: IVCSC_Vector_Methods.hpp:175
Vector()
Definition: IVCSC_Vector.hpp:61
double norm()
Definition: IVCSC_Vector_Methods.hpp:215
uint32_t nonZeros()
Definition: IVCSC_Vector_Methods.hpp:163
void * begin()
Definition: IVCSC_Vector_Methods.hpp:167
uint32_t outerSize()
Definition: IVCSC_Vector_Methods.hpp:159
~Vector()
Definition: IVCSC_Vector_Methods.hpp:18
double dot(Eigen::Vector< T, -1 > &other)
Definition: IVCSC_Vector_Methods.hpp:239
uint32_t innerSize() const
Definition: IVSparse_Base_Methods.hpp:28
uint32_t outerSize() const
Definition: IVSparse_Base_Methods.hpp:31
Definition: IVCSC_SparseMatrix.hpp:27
T sum()
Definition: IVCSC_BLAS.hpp:219
double norm()
Definition: IVCSC_BLAS.hpp:232
void * vectorPointer(uint32_t vec)
Definition: IVCSC_Methods.hpp:25
size_t getVectorSize(uint32_t vec) const
Definition: IVCSC_Methods.hpp:33