14 template <
typename T,
typename indexT,
bool columnMajor>
15 SparseMatrix<T, indexT, 1, columnMajor> &
20 if (vals !=
nullptr) {
23 if (innerIdx !=
nullptr) {
26 if (outerPtr !=
nullptr) {
29 if (metadata !=
nullptr) {
34 metadata =
new uint32_t[NUM_META_DATA];
35 memcpy(metadata, other.metadata, NUM_META_DATA *
sizeof(uint32_t));
38 numRows = other.numRows;
39 numCols = other.numCols;
40 outerDim = other.outerDim;
41 innerDim = other.innerDim;
43 compSize = other.compSize;
47 index_t =
sizeof(indexT);
58 vals = (T *)malloc(nnz *
sizeof(T));
59 innerIdx = (indexT *)malloc(nnz *
sizeof(indexT));
60 outerPtr = (indexT *)malloc((outerDim + 1) *
sizeof(indexT));
61 }
catch (std::bad_alloc &e) {
62 std::cerr <<
"Error: Failed to allocate memory for the matrix"
68 memcpy(vals, other.vals, nnz *
sizeof(T));
69 memcpy(innerIdx, other.innerIdx, nnz *
sizeof(indexT));
70 memcpy(outerPtr, other.outerPtr, (outerDim + 1) *
sizeof(indexT));
78 template <
typename T,
typename indexT,
bool columnMajor>
79 bool SparseMatrix<T, indexT, 1, columnMajor>::operator==(
const SparseMatrix<T, indexT, 1, columnMajor> &other) {
81 if (numRows != other.numRows || numCols != other.numCols) {
86 if (nnz != other.nnz) {
91 if (memcmp(vals, other.vals, nnz *
sizeof(T)) != 0) {
94 if (memcmp(innerIdx, other.innerIdx, nnz *
sizeof(indexT)) != 0) {
97 if (memcmp(outerPtr, other.outerPtr, (outerDim + 1) *
sizeof(indexT)) != 0) {
106 template <
typename T,
typename indexT,
bool columnMajor>
107 bool SparseMatrix<T, indexT, 1, columnMajor>::operator!=(
const SparseMatrix<T, indexT, 1, columnMajor> &other) {
108 return !(*
this == other);
112 template <
typename T,
typename indexT,
bool columnMajor>
113 T SparseMatrix<T, indexT, 1, columnMajor>::operator()(uint32_t row, uint32_t col) {
115 #ifdef IVSPARSE_DEBUG
117 if (row >= numRows || col >= numCols) {
118 std::cerr <<
"Error: Index out of bounds" << std::endl;
124 uint32_t vector = columnMajor ? col : row;
125 uint32_t index = columnMajor ? row : col;
128 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator it(
131 if (it.getIndex() == (indexT)index) {
142 template <
typename T,
typename indexT,
bool columnMajor>
143 typename SparseMatrix<T, indexT, 1, columnMajor>::Vector
144 SparseMatrix<T, indexT, 1, columnMajor>::operator[](uint32_t vec) {
145 #ifdef IVSPARSE_DEBUG
147 assert((vec < outerDim && vec >= 0) &&
"Vector index out of bounds");
159 template <
typename T,
typename indexT,
bool columnMajor>
161 SparseMatrix<T, indexT, 1, columnMajor>::operator*(T scalar) {
162 return scalarMultiply(scalar);
166 template <
typename T,
typename indexT,
bool columnMajor>
167 void SparseMatrix<T, indexT, 1, columnMajor>::operator*=(T scalar) {
168 return inPlaceScalarMultiply(scalar);
172 template <
typename T,
typename indexT,
bool columnMajor>
173 Eigen::VectorXd SparseMatrix<T, indexT, 1, columnMajor>::operator*(SparseMatrix<T, indexT, 1, columnMajor>::Vector &vec) {
174 return vectorMultiply(vec);
178 template <
typename T,
typename indexT,
bool columnMajor>
179 Eigen::VectorXd SparseMatrix<T, indexT, 1, columnMajor>::operator*(Eigen::VectorXd &vec) {
180 return vectorMultiply(vec);
184 template <
typename T,
typename indexT,
bool columnMajor>
185 Eigen::Matrix<T, -1, -1> SparseMatrix<T, indexT, 1, columnMajor>::operator*(Eigen::Matrix<T, -1, -1> mat) {
186 return matrixMultiply(mat);
Definition: CSC_SparseMatrix.hpp:24
Definition: IVCSC_SparseMatrix.hpp:29