17 template <
typename T,
typename indexT,
bool columnMajor>
24 #pragma omp parallel for schedule(dynamic)
25 for (uint32_t i = 0; i < this->outerDim; ++i)
27 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator it(newMatrix, i); it; ++it)
31 it.coeff(it.value() * scalar);
39 template <
typename T,
typename indexT,
bool columnMajor>
40 inline void SparseMatrix<T, indexT, 1, columnMajor>::inPlaceScalarMultiply(T scalar)
43 #pragma omp parallel for schedule(dynamic)
44 for (
int i = 0; i < nnz; i++)
53 template <
typename T,
typename indexT,
bool columnMajor>
54 inline Eigen::VectorXd SparseMatrix<T, indexT, 1, columnMajor>::vectorMultiply(Eigen::VectorXd &vec)
57 assert(vec.rows() == outerDim &&
"The vector must be the same size as the number of columns in the matrix!");
59 Eigen::Matrix<T, -1, 1> eigenTemp(innerDim, 1);
63 #pragma omp parallel for schedule(dynamic)
64 for (
int i = 0; i < vec.rows(); ++i)
68 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator matIter(*
this, i); matIter; ++matIter)
70 eigenTemp.coeffRef(matIter.row()) += matIter.value() * vec(i);
77 template <
typename T,
typename indexT,
bool columnMajor>
78 inline Eigen::VectorXd SparseMatrix<T, indexT, 1, columnMajor>::vectorMultiply(
typename SparseMatrix<T, indexT, 1, columnMajor>::Vector &vec)
80 if (vec.length() != outerDim)
81 throw std::invalid_argument(
"The vector must be the same size as the number of columns in the matrix!");
83 Eigen::Matrix<T, -1, 1> newVector = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
86 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator vecIter(vec); vecIter; ++vecIter)
88 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator matIter(*
this, vecIter.row()); matIter; ++matIter)
90 newVector.coeffRef(matIter.row()) += matIter.value() * vecIter.value();
99 template <
typename T,
typename indexT,
bool columnMajor>
100 inline Eigen::Matrix<T, -1, -1> SparseMatrix<T, indexT, 1, columnMajor>::matrixMultiply(Eigen::Matrix<T, -1, -1> &mat)
103 if (mat.rows() != outerDim)
104 throw std::invalid_argument(
"The left matrix must be the same size as the number of columns in the right matrix!");
106 Eigen::Matrix<T, -1, -1> newMatrix = Eigen::Matrix<T, -1, -1>::Zero(innerDim, mat.cols());
108 #pragma omp parallel for schedule(dynamic)
109 for (
int col = 0; col < mat.cols(); col++)
111 for (
int row = 0; row < mat.rows(); row++)
113 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator matIter(*
this, row); matIter; ++matIter)
115 newMatrix.coeffRef(matIter.row(), col) += matIter.value() * mat(row, col);
124 template <
typename T,
typename indexT,
bool columnMajor>
127 std::vector<T>
outerSum = std::vector<T>(outerDim);
129 #pragma omp parallel for schedule(dynamic)
130 for (
int i = 0; i < outerDim; i++)
140 template <
typename T,
typename indexT,
bool columnMajor>
143 std::vector<T>
innerSum = std::vector<T>(innerDim);
145 #pragma omp parallel for schedule(dynamic)
146 for (
int i = 0; i < outerDim; i++)
157 template <
typename T,
typename indexT,
bool columnMajor>
160 std::vector<T> maxCoeff = std::vector<T>(innerDim);
162 #pragma omp parallel for schedule(dynamic)
163 for (
int i = 0; i < outerDim; i++)
167 if (it.value() > maxCoeff[i])
169 maxCoeff[i] = it.value();
176 template <
typename T,
typename indexT,
bool columnMajor>
179 std::vector<T> maxCoeff = std::vector<T>(innerDim);
181 #pragma omp parallel for schedule(dynamic)
182 for (
int i = 0; i < outerDim; i++)
186 if (it.value() > maxCoeff[it.row()])
188 maxCoeff[it.row()] = it.value();
195 template <
typename T,
typename indexT,
bool columnMajor>
198 std::vector<T> minCoeff = std::vector<T>(innerDim);
200 #pragma omp parallel for schedule(dynamic)
201 for (
int i = 0; i < outerDim; i++)
205 if (it.value() < minCoeff[i])
207 minCoeff[i] = it.value();
214 template <
typename T,
typename indexT,
bool columnMajor>
217 std::vector<T> minCoeff = std::vector<T>(innerDim);
218 memset(minCoeff.data(), 0xF, innerDim *
sizeof(T));
220 #pragma omp parallel for schedule(dynamic)
221 for (
int i = 0; i < outerDim; i++)
225 if (it.value() < minCoeff[it.row()])
227 minCoeff[it.row()] = it.value();
234 template <
typename T,
typename indexT,
bool columnMajor>
237 assert(innerDim == outerDim &&
"Trace is only defined for square matrices!");
240 #pragma omp parallel for schedule(dynamic)
241 for (
int i = 0; i < outerDim; i++)
249 else if (it.row() > i)
258 template <
typename T,
typename indexT,
bool columnMajor>
263 #pragma omp parallel for schedule(dynamic)
264 for (
int i = 0; i < outerDim; i++)
274 template <
typename T,
typename indexT,
bool columnMajor>
279 #pragma omp parallel for schedule(dynamic)
280 for (
int i = 0; i < outerDim; i++)
284 norm += it.value() * it.value();
290 template <
typename T,
typename indexT,
bool columnMajor>
298 norm += it.value() * it.value();
Definition: IVCSC_Iterator.hpp:25
Definition: CSC_SparseMatrix.hpp:24
std::vector< T > maxRowCoeff()
Definition: IVCSC_BLAS.hpp:159
std::vector< T > minRowCoeff()
Definition: IVCSC_BLAS.hpp:189
std::vector< T > innerSum()
Definition: IVCSC_BLAS.hpp:131
T sum()
Definition: IVCSC_BLAS.hpp:219
double norm()
Definition: IVCSC_BLAS.hpp:232
std::vector< T > minColCoeff()
Definition: IVCSC_BLAS.hpp:174
std::vector< T > outerSum()
Definition: IVCSC_BLAS.hpp:118
double vectorLength(uint32_t vec)
Definition: IVCSC_BLAS.hpp:245
std::vector< T > maxColCoeff()
Definition: IVCSC_BLAS.hpp:144
T trace()
Definition: IVCSC_BLAS.hpp:205