16 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
18 if (data !=
nullptr) {
24 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
27 assert((length > 0) &&
"Vector length must be greater than 0");
30 this->length = length;
34 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
39 assert((vec >= 0 && vec < mat.
outerSize()) &&
"Vector index out of bounds");
57 }
catch (std::bad_alloc &e) {
58 std::cerr << e.what() <<
'\n';
65 endPtr = (uint8_t *)data + size;
68 if (nnz == 0 && size > 0) {
83 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
103 }
catch (std::bad_alloc &e) {
104 std::cerr << e.what() <<
'\n';
108 memcpy(data, vec.data, size);
111 endPtr = (uint8_t *)data + size;
116 #ifdef IVSPARSE_DEBUG
124 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
126 assert(std::is_floating_point<indexT>::value ==
false &&
127 "The index type must be a non-floating point type");
128 assert((compressionLevel == 1 || compressionLevel == 2 ||
129 compressionLevel == 3) &&
130 "The compression level must be either 1, 2, or 3");
131 assert((std::is_arithmetic<T>::value && std::is_arithmetic<indexT>::value) &&
132 "The value and index types must be numeric types");
133 assert((std::is_same<indexT, bool>::value ==
false) &&
134 "The index type must not be bool");
138 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
142 size +=
sizeof(
void *);
143 size +=
sizeof(
void *);
146 size += (uint8_t *)endPtr - (uint8_t *)data;
152 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
158 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
164 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
170 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
176 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>
191 #ifdef IVSPARSE_DEBUG
192 assert(index < length && index >= 0 &&
"The index is out of bounds");
195 return (*
this)[index];
199 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
207 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
211 std::cout <<
"Vector is too large to print" << std::endl;
215 std::cout <<
"Vector: ";
216 std::cout << std::endl;
219 for (uint32_t i = 0; i < length; i++) {
220 std::cout << (*this)[i] <<
" ";
223 std::cout << std::endl;
229 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
234 norm += it.value() * it.value();
240 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
251 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
258 dot += it.value() * other.coeff(it.row());
265 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
272 dot += it.value() * other.coeff(it.row());
280 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
286 if (
this == &other) {
291 if (data !=
nullptr) {
296 if (other.data ==
nullptr) {
300 length = other.length;
306 data = (uint8_t *)malloc(other.size);
307 memcpy(data, other.data, other.size);
310 length = other.length;
312 endPtr = (uint8_t *)data + size;
319 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
320 bool SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator==(
321 typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector &other) {
324 if (length != other.length) {
329 if (nnz != other.nnz) {
334 if (memcmp(data, other.data, size) != 0) {
343 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
344 bool SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator!=(
345 typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector &other) {
347 return !(*
this == other);
351 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
352 T SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator[]( uint32_t index) {
354 #ifdef IVSPARSE_DEBUG
356 assert(index < length &&
"The index is out of bounds");
364 if (it.getIndex() == (indexT)index) {
375 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
376 void SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator*=(T scalar) {
378 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(*
this); it; ++it) {
380 it.coeff(it.value() * scalar);
386 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
388 SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector::operator*(T scalar) {
391 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(newVector);
394 it.coeff(it.value() * scalar);
Definition: IVCSC_Iterator.hpp:25
Definition: IVCSC_Vector.hpp:25
uint32_t getLength()
Definition: IVCSC_Vector_Methods.hpp:200
T coeff(uint32_t index)
Definition: IVCSC_Vector_Methods.hpp:189
void print()
Definition: IVCSC_Vector_Methods.hpp:208
uint32_t innerSize()
Definition: IVCSC_Vector_Methods.hpp:153
T sum()
Definition: IVCSC_Vector_Methods.hpp:241
void * end()
Definition: IVCSC_Vector_Methods.hpp:177
size_t byteSize()
Definition: IVCSC_Vector_Methods.hpp:183
Vector()
Definition: IVCSC_Vector.hpp:58
double norm()
Definition: IVCSC_Vector_Methods.hpp:230
uint32_t nonZeros()
Definition: IVCSC_Vector_Methods.hpp:165
void * begin()
Definition: IVCSC_Vector_Methods.hpp:171
uint32_t outerSize()
Definition: IVCSC_Vector_Methods.hpp:159
~Vector()
Definition: IVCSC_Vector_Methods.hpp:17
double dot(Eigen::Vector< T, -1 > &other)
Definition: IVCSC_Vector_Methods.hpp:252
uint32_t innerSize() const
Definition: IVSparse_Base_Methods.hpp:33
uint32_t outerSize() const
Definition: IVSparse_Base_Methods.hpp:36
Definition: IVCSC_SparseMatrix.hpp:29
T sum()
Definition: IVCSC_BLAS.hpp:239
double norm()
Definition: IVCSC_BLAS.hpp:256
void * vectorPointer(uint32_t vec)
Definition: IVCSC_Methods.hpp:36
size_t getVectorSize(uint32_t vec) const
Definition: IVCSC_Methods.hpp:57