16 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
22 #ifdef IVSPARSE_HAS_OPENMP
23 #pragma omp parallel for
25 for (uint32_t i = 0; i < this->outerDim; ++i) {
26 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(newMatrix, i); it; ++it) {
28 it.coeff(it.value() * scalar);
36 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
37 inline void SparseMatrix<T, indexT, compressionLevel, columnMajor>::inPlaceScalarMultiply(T scalar) {
40 #ifdef IVSPARSE_HAS_OPENMP
41 #pragma omp parallel for
43 for (uint32_t i = 0; i < outerDim; ++i) {
44 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator it(*
this, i); it; ++it) {
46 it.coeff(it.value() * scalar);
55 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
56 inline Eigen::Matrix<T, -1, 1> SparseMatrix<T, indexT, compressionLevel, columnMajor>::vectorMultiply(Eigen::Matrix<T, -1, 1> vec) {
60 assert(vec.rows() == outerDim &&
61 "The vector must be the same size as the number of columns in the "
65 Eigen::Matrix<T, -1, 1> eigenTemp = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
70 for (uint32_t i = 0; i < outerDim; i++) {
71 for (
typename SparseMatrix<T, indexT, 3, columnMajor>::InnerIterator
74 eigenTemp(matIter.row()) += vec(matIter.col()) * matIter.value();
82 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
83 inline Eigen::Matrix<T, -1, 1> SparseMatrix<T, indexT, compressionLevel, columnMajor>::vectorMultiply(
84 typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::Vector &vec) {
87 if (vec.length() != outerDim)
88 throw std::invalid_argument(
89 "The vector must be the same size as the number of columns in the "
93 Eigen::Matrix<T, -1, 1> eigenTemp = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
95 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator vecIter(vec);
97 for (
typename SparseMatrix<T, indexT, compressionLevel, columnMajor>::InnerIterator matIter(*
this, vecIter.row());
99 eigenTemp(matIter.row()) += matIter.value() * vecIter.value();
110 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
112 std::vector<T> outerSum = std::vector<T>(outerDim);
114 #ifdef IVSPARSE_HAS_OPENMP
115 #pragma omp parallel for
117 for (
int i = 0; i < outerDim; i++) {
119 outerSum[i] += it.value();
125 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
127 std::vector<T> innerSum = std::vector<T>(innerDim);
129 #ifdef IVSPARSE_HAS_OPENMP
130 #pragma omp parallel for
132 for (
int i = 0; i < outerDim; i++) {
135 innerSum[it.row()] += it.value();
141 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
144 std::vector<T> maxCoeff = std::vector<T>(innerDim);
146 #ifdef IVSPARSE_HAS_OPENMP
147 #pragma omp parallel for
149 for (
int i = 0; i < outerDim; i++) {
152 if (it.value() > maxCoeff[i]) {
153 maxCoeff[i] = it.value();
160 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
163 std::vector<T> maxCoeff = std::vector<T>(innerDim);
165 #ifdef IVSPARSE_HAS_OPENMP
166 #pragma omp parallel for
168 for (
int i = 0; i < outerDim; i++) {
171 if (it.value() > maxCoeff[it.row()]) {
172 maxCoeff[it.row()] = it.value();
179 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
182 std::vector<T> minCoeff = std::vector<T>(innerDim);
184 #ifdef IVSPARSE_HAS_OPENMP
185 #pragma omp parallel for
187 for (
int i = 0; i < outerDim; i++) {
190 if (it.value() < minCoeff[i]) {
191 minCoeff[i] = it.value();
198 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
200 std::vector<T> minCoeff = std::vector<T>(innerDim);
201 memset(minCoeff.data(), 0xF, innerDim *
sizeof(T));
203 #ifdef IVSPARSE_HAS_OPENMP
204 #pragma omp parallel for
206 for (
int i = 0; i < outerDim; i++) {
209 if (it.value() < minCoeff[it.row()]) {
210 minCoeff[it.row()] = it.value();
217 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
220 #ifdef IVSPARSE_DEBUG
221 assert(innerDim == outerDim &&
"Trace is only defined for square matrices!");
225 for (
int i = 0; i < outerDim; i++) {
230 }
else if (it.row() > i) {
238 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
242 #ifdef IVSPARSE_HAS_OPENMP
243 #pragma omp parallel for reduction(+ : sum)
245 for (
int i = 0; i < outerDim; i++) {
255 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
259 #ifdef IVSPARSE_HAS_OPENMP
260 #pragma omp parallel for reduction(+ : norm)
262 for (
int i = 0; i < outerDim; i++) {
265 norm += it.value() * it.value();
271 template <
typename T,
typename indexT, u
int8_t compressionLevel,
bool columnMajor>
274 #ifdef IVSPARSE_DEBUG
275 assert(col < outerDim && col >= 0 &&
"The column index is out of bounds!");
282 norm += it.value() * it.value();
Definition: IVCSC_Iterator.hpp:25
Definition: IVCSC_SparseMatrix.hpp:29
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