16 template <
typename T,
typename indexT,
bool columnMajor>
23 #pragma omp parallel for schedule(dynamic)
24 for (
int i = 0; i < outerDim; i++) {
25 for (
int j = 0; j < valueSizes[i]; j++) {
26 newMatrix.values[i][j] *= scalar;
33 template <
typename T,
typename indexT,
bool columnMajor>
34 inline void SparseMatrix<T, indexT, 2, columnMajor>::inPlaceScalarMultiply(T scalar) {
37 #pragma omp parallel for schedule(dynamic)
38 for (
int i = 0; i < outerDim; i++) {
39 for (
int j = 0; j < valueSizes[i]; j++) {
40 values[i][j] *= scalar;
48 template <
typename T,
typename indexT,
bool columnMajor>
49 inline Eigen::VectorXd SparseMatrix<T, indexT, 2, columnMajor>::vectorMultiply(Eigen::VectorXd &vec) {
51 assert(vec.rows() == outerDim &&
"The vector must be the same size as the number of columns in the matrix!");
53 Eigen::Matrix<T, -1, 1> eigenTemp(innerDim, 1);
57 #pragma omp parallel for schedule(dynamic)
58 for (
int i = 0; i < vec.rows(); ++i) {
61 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator matIter(*
this, i); matIter; ++matIter) {
62 eigenTemp.coeffRef(matIter.row()) += matIter.value() * vec(i);
69 template <
typename T,
typename indexT,
bool columnMajor>
70 inline Eigen::VectorXd SparseMatrix<T, indexT, 2, columnMajor>::vectorMultiply(
typename SparseMatrix<T, indexT, 2, columnMajor>::Vector &vec)
72 if (vec.length() != outerDim)
73 throw std::invalid_argument(
"The vector must be the same size as the number of columns in the matrix!");
75 Eigen::Matrix<T, -1, 1> newVector = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
78 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator vecIter(vec); vecIter; ++vecIter)
80 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator matIter(*
this, vecIter.row()); matIter; ++matIter)
82 newVector.coeffRef(matIter.row()) += matIter.value() * vecIter.value();
91 template <
typename T,
typename indexT,
bool columnMajor>
92 inline Eigen::Matrix<T, -1, -1> SparseMatrix<T, indexT, 2, columnMajor>::matrixMultiply(Eigen::Matrix<T, -1, -1> &mat)
95 if (mat.rows() != outerDim)
96 throw std::invalid_argument(
"The left matrix must be the same size as the number of columns in the right matrix!");
98 Eigen::Matrix<T, -1, -1> newMatrix = Eigen::Matrix<T, -1, -1>::Zero(innerDim, mat.cols());
100 #pragma omp parallel for schedule(dynamic)
101 for (
int col = 0; col < mat.cols(); col++)
103 for (
int row = 0; row < mat.rows(); row++)
105 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator matIter(*
this, row); matIter; ++matIter)
107 newMatrix.coeffRef(matIter.row(), col) += matIter.value() * mat(row, col);
117 template <
typename T,
typename indexT,
bool columnMajor>
120 std::vector<T>
outerSum = std::vector<T>(outerDim);
122 #pragma omp parallel for schedule(dynamic)
123 for (
int i = 0; i < outerDim; i++)
125 for (
int j = 0; j < valueSizes[i]; j++)
127 outerSum[i] += values[i][j] * counts[i][j];
134 template <
typename T,
typename indexT,
bool columnMajor>
137 std::vector<T>
innerSum = std::vector<T>(innerDim);
139 #pragma omp parallel for schedule(dynamic)
140 for (
int i = 0; i < outerDim; i++)
151 template <
typename T,
typename indexT,
bool columnMajor>
154 std::vector<T> maxCoeff = std::vector<T>(innerDim);
156 #pragma omp parallel for schedule(dynamic)
157 for (
int i = 0; i < outerDim; i++)
159 for (
int j = 0; j < valueSizes[i]; j++)
161 if (values[i][j] > maxCoeff[i])
163 maxCoeff[i] = values[i][j];
171 template <
typename T,
typename indexT,
bool columnMajor>
174 std::vector<T> maxCoeff = std::vector<T>(innerDim);
176 #pragma omp parallel for schedule(dynamic)
177 for (
int i = 0; i < outerDim; i++)
181 if (it.value() > maxCoeff[it.row()])
183 maxCoeff[it.row()] = it.value();
191 template <
typename T,
typename indexT,
bool columnMajor>
194 std::vector<T> minCoeff = std::vector<T>(innerDim);
196 #pragma omp parallel for schedule(dynamic)
197 for (
int i = 0; i < outerDim; i++)
199 for (
int j = 0; j < valueSizes[i]; j++)
201 if (values[i][j] < minCoeff[i])
203 minCoeff[i] = values[i][j];
211 template <
typename T,
typename indexT,
bool columnMajor>
214 std::vector<T> minCoeff = std::vector<T>(innerDim);
215 memset(minCoeff.data(), 0xF, innerDim *
sizeof(T));
217 for (
int i = 0; i < outerDim; i++)
221 if (it.value() < minCoeff[it.row()])
223 minCoeff[it.row()] = it.value();
231 template <
typename T,
typename indexT,
bool columnMajor>
234 assert(innerDim == outerDim &&
"Trace is only defined for square matrices!");
237 for (
int i = 0; i < outerDim; i++)
245 else if (it.row() > i)
255 template <
typename T,
typename indexT,
bool columnMajor>
260 #pragma omp parallel for schedule(dynamic)
261 for (
int i = 0; i < outerDim; i++)
263 for (
int j = 0; j < valueSizes[i]; j++)
265 sum += values[i][j] * counts[i][j];
272 template <
typename T,
typename indexT,
bool columnMajor>
277 #pragma omp parallel for schedule(dynamic)
278 for (
int i = 0; i < outerDim; i++)
280 for (
int j = 0; j < valueSizes[i]; j++)
282 norm += values[i][j] * values[i][j] * counts[i][j];
289 template <
typename T,
typename indexT,
bool columnMajor>
294 #pragma omp parallel for schedule(dynamic)
295 for (
int i = 0; i < valueSizes[col]; i++)
297 norm += values[col][i] * values[col][i] * counts[col][i];
Definition: IVCSC_Iterator.hpp:25
Definition: VCSC_SparseMatrix.hpp:22
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