16 template <
typename T,
typename indexT,
bool columnMajor>
18 SparseMatrix<T, indexT, 1, columnMajor>::scalarMultiply(T scalar) {
24 #ifdef IVSPARSE_HAS_OPENMP
25 #pragma omp parallel for
27 for (uint32_t i = 0; i < this->outerDim; ++i) {
28 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator it(newMatrix, i); it; ++it) {
29 if (it.isNewRun()) { it.coeff(it.value() * scalar); }
36 template <
typename T,
typename indexT,
bool columnMajor>
37 inline void SparseMatrix<T, indexT, 1, columnMajor>::inPlaceScalarMultiply(T scalar) {
40 #ifdef IVSPARSE_HAS_OPENMP
41 #pragma omp parallel for
43 for (
int i = 0; i < nnz; i++) { vals[i] *= scalar; }
49 template <
typename T,
typename indexT,
bool columnMajor>
50 inline Eigen::VectorXd SparseMatrix<T, indexT, 1, columnMajor>::vectorMultiply(Eigen::VectorXd &vec) {
54 assert(vec.rows() == outerDim &&
55 "The vector must be the same size as the "
56 "number of columns in the matrix!");
59 Eigen::Matrix<T, -1, 1> eigenTemp(innerDim, 1);
64 #ifdef IVSPARSE_HAS_OPENMP
65 #pragma omp parallel for
67 for (
int i = 0; i < vec.rows(); ++i) {
68 if (vec(i) == 0)
continue;
69 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator matIter(*
this, i); matIter; ++matIter) {
70 eigenTemp.coeffRef(matIter.row()) += matIter.value() * vec(i);
78 template <
typename T,
typename indexT,
bool columnMajor>
79 inline Eigen::VectorXd SparseMatrix<T, indexT, 1, columnMajor>::vectorMultiply(
typename SparseMatrix<T, indexT, 1, columnMajor>::Vector &vec) {
82 if (vec.length() != outerDim)
83 throw std::invalid_argument(
84 "The vector must be the same size as the "
85 "number of columns in the matrix!");
88 Eigen::Matrix<T, -1, 1> newVector = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
93 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator vecIter(vec); vecIter; ++vecIter) {
94 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator matIter(*
this, vecIter.row()); matIter; ++matIter) {
95 newVector.coeffRef(matIter.row()) += matIter.value() * vecIter.value();
104 template <
typename T,
typename indexT,
bool columnMajor>
105 inline Eigen::Matrix<T, -1, -1> SparseMatrix<T, indexT, 1, columnMajor>::matrixMultiply(Eigen::Matrix<T, -1, -1> &mat) {
107 #ifdef IVSPARSE_DEBUG
109 if (mat.rows() != outerDim)
110 throw std::invalid_argument(
111 "The left matrix must be the same size as the number of columns in "
112 "the right matrix!");
115 Eigen::Matrix<T, -1, -1> newMatrix = Eigen::Matrix<T, -1, -1>::Zero(innerDim, mat.cols());
117 #ifdef IVSPARSE_HAS_OPENMP
118 #pragma omp parallel for
120 for (
int col = 0; col < mat.cols(); col++) {
121 for (
int row = 0; row < mat.rows(); row++) {
122 for (
typename SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator matIter(*
this, row); matIter; ++matIter) {
123 newMatrix.coeffRef(matIter.row(), col) += matIter.value() * mat(row, col);
133 template <
typename T,
typename indexT,
bool columnMajor>
136 std::vector<T>
outerSum = std::vector<T>(outerDim);
138 #ifdef IVSPARSE_HAS_OPENMP
139 #pragma omp parallel for
141 for (
int i = 0; i < outerDim; i++) {
150 template <
typename T,
typename indexT,
bool columnMajor>
153 std::vector<T>
innerSum = std::vector<T>(innerDim);
155 #ifdef IVSPARSE_HAS_OPENMP
156 #pragma omp parallel for
158 for (
int i = 0; i < outerDim; i++) {
167 template <
typename T,
typename indexT,
bool columnMajor>
170 std::vector<T> maxCoeff = std::vector<T>(innerDim);
172 #ifdef IVSPARSE_HAS_OPENMP
173 #pragma omp parallel for
175 for (
int i = 0; i < outerDim; i++) {
177 if (it.value() > maxCoeff[i]) { maxCoeff[i] = it.value(); }
184 template <
typename T,
typename indexT,
bool columnMajor>
187 std::vector<T> maxCoeff = std::vector<T>(innerDim);
189 #ifdef IVSPARSE_HAS_OPENMP
190 #pragma omp parallel for
192 for (
int i = 0; i < outerDim; i++) {
194 if (it.value() > maxCoeff[it.row()]) { maxCoeff[it.row()] = it.value(); }
201 template <
typename T,
typename indexT,
bool columnMajor>
204 std::vector<T> minCoeff = std::vector<T>(innerDim);
206 #ifdef IVSPARSE_HAS_OPENMP
207 #pragma omp parallel for
209 for (
int i = 0; i < outerDim; i++) {
211 if (it.value() < minCoeff[i]) { minCoeff[i] = it.value(); }
218 template <
typename T,
typename indexT,
bool columnMajor>
221 std::vector<T> minCoeff = std::vector<T>(innerDim);
222 memset(minCoeff.data(), 0xF, innerDim *
sizeof(T));
224 #ifdef IVSPARSE_HAS_OPENMP
225 #pragma omp parallel for
227 for (
int i = 0; i < outerDim; i++) {
229 if (it.value() < minCoeff[it.row()]) { minCoeff[it.row()] = it.value(); }
236 template <
typename T,
typename indexT,
bool columnMajor>
239 #ifdef IVSPARSE_DEBUG
240 assert(innerDim == outerDim &&
"Trace is only defined for square matrices!");
244 #ifdef IVSPARSE_HAS_OPENMP
245 #pragma omp parallel for
247 for (
int i = 0; i < outerDim; i++) {
249 if (it.row() == i) {
trace += it.value(); }
250 else if (it.row() > i) {
continue; }
257 template <
typename T,
typename indexT,
bool columnMajor>
262 #ifdef IVSPARSE_HAS_OPENMP
263 #pragma omp parallel for
265 for (
int i = 0; i < outerDim; i++) {
274 template <
typename T,
typename indexT,
bool columnMajor>
279 for (
int i = 0; i < outerDim; i++) {
281 norm += it.value() * it.value();
288 template <
typename T,
typename indexT,
bool columnMajor>
291 #ifdef IVSPARSE_DEBUG
293 assert(col < outerDim && col >= 0 &&
"Column is out of bounds!");
299 norm += it.value() * it.value();
Definition: IVCSC_Iterator.hpp:25
Definition: CSC_SparseMatrix.hpp:24
std::vector< T > maxRowCoeff()
Definition: IVCSC_BLAS.hpp:161
std::vector< T > minRowCoeff()
Definition: IVCSC_BLAS.hpp:199
std::vector< T > innerSum()
Definition: IVCSC_BLAS.hpp:126
T sum()
Definition: IVCSC_BLAS.hpp:239
double norm()
Definition: IVCSC_BLAS.hpp:256
std::vector< T > minColCoeff()
Definition: IVCSC_BLAS.hpp:180
std::vector< T > outerSum()
Definition: IVCSC_BLAS.hpp:111
double vectorLength(uint32_t vec)
Definition: IVCSC_BLAS.hpp:272
std::vector< T > maxColCoeff()
Definition: IVCSC_BLAS.hpp:142
T trace()
Definition: IVCSC_BLAS.hpp:218