16 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
22 #pragma omp parallel for schedule(dynamic)
23 for (uint32_t i = 0; i < this->outerDim; ++i)
25 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(newMatrix, i); it; ++it)
29 it.coeff(it.value() * scalar);
37 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
38 inline void SparseMatrix<T, indexT, compressionLevel, columnMajor>::inPlaceScalarMultiply(T scalar) {
40 #pragma omp parallel for schedule(dynamic)
41 for (uint32_t i = 0; i < outerDim; ++i)
43 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(*
this, i); it; ++it)
47 it.coeff(it.value() * scalar);
56 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
57 inline Eigen::VectorXd SparseMatrix<T, indexT, compressionLevel, columnMajor>::vectorMultiply(Eigen::VectorXd &vec) {
59 assert(vec.rows() == outerDim &&
"The vector must be the same size as the number of columns in the matrix!");
61 Eigen::Matrix<T, -1, 1> eigenTemp(innerDim, 1);
65 #pragma omp parallel for schedule(dynamic)
66 for (
int i = 0; i < vec.rows(); ++i) {
69 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator matIter(*
this, i); matIter; ++matIter) {
70 eigenTemp.coeffRef(matIter.row()) += matIter.value() * vec(i);
77 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
78 inline Eigen::VectorXd SparseMatrix<T, indexT, compressionLevel, columnMajor>::vectorMultiply(
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector &vec) {
79 if (vec.length() != outerDim)
80 throw std::invalid_argument(
"The vector must be the same size as the number of columns in the matrix!");
82 Eigen::Matrix<T, -1, 1> newVector = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
85 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator vecIter(vec); vecIter; ++vecIter) {
86 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator matIter(*
this, vecIter.row()); matIter; ++matIter) {
87 newVector.coeffRef(matIter.row()) += matIter.value() * vecIter.value();
96 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
97 inline Eigen::Matrix<T, -1, -1> SparseMatrix<T, indexT, compressionLevel, columnMajor>::matrixMultiply(Eigen::Matrix<T, -1, -1> &mat) {
99 if (mat.rows() != outerDim)
100 throw std::invalid_argument(
"The left matrix must be the same size as the number of columns in the right matrix!");
102 Eigen::Matrix<T, -1, -1> newMatrix = Eigen::Matrix<T, -1, -1>::Zero(innerDim, mat.cols());
104 #pragma omp parallel for schedule(dynamic)
105 for (
int col = 0; col < mat.cols(); col++) {
106 for (
int row = 0; row < mat.rows(); row++) {
107 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator matIter(*
this, row); matIter; ++matIter) {
108 newMatrix.coeffRef(matIter.row(), col) += matIter.value() * mat(row, col);
117 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
119 std::vector<T> outerSum = std::vector<T>(outerDim);
121 #pragma omp parallel for schedule(dynamic)
122 for (
int i = 0; i < outerDim; i++) {
124 outerSum[i] += it.value();
130 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
132 std::vector<T> innerSum = std::vector<T>(innerDim);
134 #pragma omp parallel for schedule(dynamic)
135 for (
int i = 0; i < outerDim; i++) {
137 innerSum[it.row()] += it.value();
143 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
145 std::vector<T> maxCoeff = std::vector<T>(innerDim);
147 #pragma omp parallel for schedule(dynamic)
148 for (
int i = 0; i < outerDim; i++) {
150 if (it.value() > maxCoeff[i]) {
151 maxCoeff[i] = it.value();
158 template <
typename T,
typename indexT, u
int8_t compressionLevel,
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++) {
165 if (it.value() > maxCoeff[it.row()]) {
166 maxCoeff[it.row()] = it.value();
173 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
175 std::vector<T> minCoeff = std::vector<T>(innerDim);
177 #pragma omp parallel for schedule(dynamic)
178 for (
int i = 0; i < outerDim; i++) {
180 if (it.value() < minCoeff[i]) {
181 minCoeff[i] = it.value();
188 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
190 std::vector<T> minCoeff = std::vector<T>(innerDim);
191 memset(minCoeff.data(), 0xF, innerDim *
sizeof(T));
193 #pragma omp parallel for schedule(dynamic)
194 for (
int i = 0; i < outerDim; i++) {
196 if (it.value() < minCoeff[it.row()]) {
197 minCoeff[it.row()] = it.value();
204 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
206 assert(innerDim == outerDim &&
"Trace is only defined for square matrices!");
209 for (
int i = 0; i < outerDim; i++) {
211 if (it.row() == i) { trace += it.value(); }
212 else if (it.row() > i) {
continue; }
218 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
222 #pragma omp parallel for schedule(dynamic)
223 for (
int i = 0; i < outerDim; i++) {
231 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
235 #pragma omp parallel for schedule(dynamic)
236 for (
int i = 0; i < outerDim; i++) {
238 norm += it.value() * it.value();
244 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
250 norm += it.value() * it.value();
Definition: IVCSC_Iterator.hpp:25
Definition: IVCSC_SparseMatrix.hpp:27
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