17 template <
typename T,
typename indexT,
bool columnMajor>
20 if (values !=
nullptr)
24 if (counts !=
nullptr)
28 if (indices !=
nullptr)
35 template <
typename T,
typename indexT,
bool columnMajor>
41 assert((vec >= 0 && vec < mat.
outerSize()) &&
"Vector index out of bounds");
70 values = (T *)malloc(valuesSize *
sizeof(T));
71 counts = (indexT *)malloc(valuesSize *
sizeof(indexT));
72 indices = (indexT *)malloc(indexSize *
sizeof(indexT));
74 catch (std::bad_alloc &e)
76 std::cerr << e.what() <<
'\n';
80 memcpy(values, mat.
getValues(vec), valuesSize *
sizeof(T));
81 memcpy(counts, mat.
getCounts(vec), valuesSize *
sizeof(indexT));
82 memcpy(indices, mat.
getIndices(vec), indexSize *
sizeof(indexT));
88 template <
typename T,
typename indexT,
bool columnMajor>
96 indexWidth = vec.indexWidth;
106 valuesSize = vec.valuesSize;
107 indexSize = vec.indexSize;
112 values = (T *)malloc(valuesSize *
sizeof(T));
113 counts = (indexT *)malloc(valuesSize *
sizeof(indexT));
114 indices = (indexT *)malloc(indexSize *
sizeof(indexT));
116 catch (std::bad_alloc &e)
118 std::cerr << e.what() <<
'\n';
122 memcpy(values, vec.values, valuesSize *
sizeof(T));
123 memcpy(counts, vec.counts, valuesSize *
sizeof(indexT));
124 memcpy(indices, vec.indices, indexSize *
sizeof(indexT));
135 template <
typename T,
typename indexT,
bool columnMajor>
138 assert(std::is_floating_point<indexT>::value ==
false &&
"The index type must be a non-floating point type");
139 assert((std::is_arithmetic<T>::value && std::is_arithmetic<indexT>::value) &&
"The value and index types must be numeric types");
140 assert((std::is_same<indexT, bool>::value ==
false) &&
"The index type must not be bool");
144 template <
typename T,
typename indexT,
bool columnMajor>
150 size +=
sizeof(T) * valuesSize;
151 size +=
sizeof(indexT) * valuesSize;
152 size +=
sizeof(indexT) * indexSize;
158 template <
typename T,
typename indexT,
bool columnMajor>
162 template <
typename T,
typename indexT,
bool columnMajor>
166 template <
typename T,
typename indexT,
bool columnMajor>
170 template <
typename T,
typename indexT,
bool columnMajor>
174 template <
typename T,
typename indexT,
bool columnMajor>
178 template <
typename T,
typename indexT,
bool columnMajor>
182 template <
typename T,
typename indexT,
bool columnMajor>
186 template <
typename T,
typename indexT,
bool columnMajor>
190 template <
typename T,
typename indexT,
bool columnMajor>
194 template <
typename T,
typename indexT,
bool columnMajor>
200 template <
typename T,
typename indexT,
bool columnMajor>
207 std::cout <<
"Vector is too large to print" << std::endl;
211 std::cout <<
"Vector: ";
212 std::cout << std::endl;
215 for (uint32_t i = 0; i < length; i++)
217 std::cout << (*this)[i] <<
" ";
220 std::cout << std::endl;
226 template <
typename T,
typename indexT,
bool columnMajor>
230 #pragma omp parallel for schedule(dynamic)
231 for (
int i = 0; i < valueSizes; i++)
233 norm += values[i] * values[i] * counts[i];
239 template <
typename T,
typename indexT,
bool columnMajor>
243 #pragma omp parallel for schedule(dynamic)
244 for (
int i = 0; i < valueSizes; i++)
246 sum += values[i] * counts[i];
252 template <
typename T,
typename indexT,
bool columnMajor>
260 dot += it.value() * other.coeff(it.row());
267 template <
typename T,
typename indexT,
bool columnMajor>
275 dot += it.value() * other.coeff(it.row());
283 template <
typename T,
typename indexT,
bool columnMajor>
293 if (values !=
nullptr)
297 if (counts !=
nullptr)
301 if (indices !=
nullptr)
307 length = other.length;
310 indexWidth = other.indexWidth;
320 valuesSize = other.valuesSize;
321 indexSize = other.indexSize;
326 values = (T *)malloc(valuesSize *
sizeof(T));
327 counts = (indexT *)malloc(valuesSize *
sizeof(indexT));
328 indices = (indexT *)malloc(indexSize *
sizeof(indexT));
330 catch (std::bad_alloc &e)
332 std::cerr << e.what() <<
'\n';
336 memcpy(values, other.values, valuesSize *
sizeof(T));
337 memcpy(counts, other.counts, valuesSize *
sizeof(indexT));
338 memcpy(indices, other.indices, indexSize *
sizeof(indexT));
350 template <
typename T,
typename indexT,
bool columnMajor>
351 bool SparseMatrix<T, indexT, 2, columnMajor>::Vector::operator==(
typename SparseMatrix<T, indexT, 2, columnMajor>::Vector &other)
355 if (length != other.length)
361 if (nnz != other.nnz)
367 for (uint32_t i = 0; i < valuesSize; i++)
369 if (values[i] != other.values[i])
376 for (uint32_t i = 0; i < valuesSize; i++)
378 if (counts[i] != other.counts[i])
385 for (uint32_t i = 0; i < indexSize; i++)
387 if (indices[i] != other.indices[i])
398 template <
typename T,
typename indexT,
bool columnMajor>
399 bool SparseMatrix<T, indexT, 2, columnMajor>::Vector::operator!=(
typename SparseMatrix<T, indexT, 2, columnMajor>::Vector &other)
401 return !(*
this == other);
405 template <
typename T,
typename indexT,
bool columnMajor>
406 T SparseMatrix<T, indexT, 2, columnMajor>::Vector::operator[](uint32_t index)
411 assert(index < length &&
"The index is out of bounds");
420 if (it.getIndex() == (indexT)index)
432 template <
typename T,
typename indexT,
bool columnMajor>
433 void SparseMatrix<T, indexT, 2, columnMajor>::Vector::operator*=(T scalar)
435 #pragma omp parallel for schedule(dynamic)
436 for (
int i = 0; i < valueSizes; i++)
443 template <
typename T,
typename indexT,
bool columnMajor>
449 #pragma omp parallel for schedule(dynamic)
450 for (
int i = 0; i < outerDim; i++)
452 for (
int j = 0; j < valueSizes; j++)
454 newVector.values[i][j] *= 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
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
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
Definition: VCSC_SparseMatrix.hpp:22
indexT getNumUniqueVals(uint32_t vec) const
Definition: VCSC_Methods.hpp:38
indexT * getCounts(uint32_t vec) const
Definition: VCSC_Methods.hpp:30
indexT getNumIndices(uint32_t vec) const
Definition: VCSC_Methods.hpp:46
indexT * getIndices(uint32_t vec) const
Definition: VCSC_Methods.hpp:34
T * getValues(uint32_t vec) const
Definition: VCSC_Methods.hpp:26
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