17 template <
typename T,
typename indexT,
bool columnMajor>
24 if (innerIdx !=
nullptr)
31 template <
typename T,
typename indexT,
bool columnMajor>
37 assert((vec >= 0 && vec < mat.
outerSize()) &&
"Vector index out of bounds");
53 nnz = mat.outerPtr[vec + 1] - mat.outerPtr[vec];
57 vals = (T *)malloc(nnz *
sizeof(T));
58 innerIdx = (indexT *)malloc(nnz *
sizeof(indexT));
60 catch (std::bad_alloc &e)
62 std::cerr <<
"Allocation failed: " << e.what() <<
'\n';
65 memcpy(vals, mat.vals + mat.outerPtr[vec], nnz *
sizeof(T));
66 memcpy(innerIdx, mat.innerIdx + mat.outerPtr[vec], nnz *
sizeof(indexT));
76 template <
typename T,
typename indexT,
bool columnMajor>
85 vals = (T *)malloc(nnz *
sizeof(T));
86 innerIdx = (indexT *)malloc(nnz *
sizeof(indexT));
88 catch (std::bad_alloc &e)
90 std::cerr <<
"Allocation failed: " << e.what() <<
'\n';
93 memcpy(vals, vec.vals, nnz *
sizeof(T));
94 memcpy(innerIdx, vec.innerIdx, nnz *
sizeof(indexT));
104 template <
typename T,
typename indexT,
bool columnMajor>
107 assert(std::is_floating_point<indexT>::value ==
false &&
"The index type must be a non-floating point type");
108 assert((std::is_arithmetic<T>::value && std::is_arithmetic<indexT>::value) &&
"The value and index types must be numeric types");
109 assert((std::is_same<indexT, bool>::value ==
false) &&
"The index type must not be bool");
113 template <
typename T,
typename indexT,
bool columnMajor>
119 size +=
sizeof(T) * nnz;
120 size +=
sizeof(indexT) * nnz;
126 template <
typename T,
typename indexT,
bool columnMajor>
130 template <
typename T,
typename indexT,
bool columnMajor>
134 template <
typename T,
typename indexT,
bool columnMajor>
138 template <
typename T,
typename indexT,
bool columnMajor>
142 template <
typename T,
typename indexT,
bool columnMajor>
146 template <
typename T,
typename indexT,
bool columnMajor>
150 template <
typename T,
typename indexT,
bool columnMajor>
154 template <
typename T,
typename indexT,
bool columnMajor>
160 template <
typename T,
typename indexT,
bool columnMajor>
163 std::cout <<
"Vector: " << std::endl;
164 std::cout << std::endl;
167 for (uint32_t i = 0; i < std::min(length, (uint32_t)100); i++)
169 std::cout << (*this)[i] <<
" ";
172 std::cout << std::endl;
178 template <
typename T,
typename indexT,
bool columnMajor>
192 if (innerIdx !=
nullptr)
211 vals = (T *)malloc(nnz *
sizeof(T));
212 innerIdx = (indexT *)malloc(nnz *
sizeof(indexT));
214 catch (std::bad_alloc &e)
216 std::cerr <<
"Allocation failed: " << e.what() <<
'\n';
219 memcpy(vals, vec.vals, nnz *
sizeof(T));
220 memcpy(innerIdx, vec.innerIdx, nnz *
sizeof(indexT));
230 template <
typename T,
typename indexT,
bool columnMajor>
231 bool SparseMatrix<T, indexT, 1, columnMajor>::Vector::operator==(
typename SparseMatrix<T, indexT, 1, columnMajor>::Vector &vec)
234 if (length != vec.length || nnz != vec.nnz)
240 for (uint32_t i = 0; i < nnz; i++)
242 if (vals[i] != vec.vals[i] || innerIdx[i] != vec.innerIdx[i])
253 template <
typename T,
typename indexT,
bool columnMajor>
254 bool SparseMatrix<T, indexT, 1, columnMajor>::Vector::operator!=(
typename SparseMatrix<T, indexT, 1, columnMajor>::Vector &vec)
256 return !(*
this == vec);
260 template <
typename T,
typename indexT,
bool columnMajor>
261 T SparseMatrix<T, indexT, 1, columnMajor>::Vector::operator[](uint32_t index)
264 assert((index >= 0 && index < length) &&
"Index out of bounds");
267 for (uint32_t i = 0; i < nnz; i++)
269 if (innerIdx[i] == index)
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
size_t byteSize()
Definition: IVCSC_Vector_Methods.hpp:175
Vector()
Definition: IVCSC_Vector.hpp:61
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
Definition: CSC_SparseMatrix.hpp:24
uint32_t innerSize() const
Definition: IVSparse_Base_Methods.hpp:28
size_t byteSize() const
Definition: IVSparse_Base_Methods.hpp:37
uint32_t outerSize() const
Definition: IVSparse_Base_Methods.hpp:31
Definition: IVCSC_SparseMatrix.hpp:27