16 template <
typename T,
typename indexT,
bool columnMajor>
22 #ifdef IVSPARSE_HAS_OPENMP
23 #pragma omp parallel for
25 for (
int i = 0; i < outerDim; i++) {
26 for (
int j = 0; j < valueSizes[i]; j++) {
27 newMatrix.values[i][j] *= scalar;
34 template <
typename T,
typename indexT,
bool columnMajor>
35 inline void SparseMatrix<T, indexT, 2, columnMajor>::inPlaceScalarMultiply(T scalar) {
37 #ifdef IVSPARSE_HAS_OPENMP
38 #pragma omp parallel for
40 for (
int i = 0; i < outerDim; i++) {
41 for (
int j = 0; j < valueSizes[i]; j++) {
42 values[i][j] *= scalar;
50 template <
typename T,
typename indexT,
bool columnMajor>
51 inline Eigen::Matrix<T, -1, 1> SparseMatrix<T, indexT, 2, columnMajor>::vectorMultiply(Eigen::Matrix<T, -1, 1> &vec) {
55 assert(vec.rows() == outerDim &&
56 "The vector must be the same size as the number of columns in the "
60 Eigen::Matrix<T, -1, 1> eigenTemp = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
64 for (uint32_t i = 0; i < outerDim; i++) {
65 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator
68 eigenTemp(matIter.row()) += vec(matIter.col()) * matIter.value();
76 template <
typename T,
typename indexT,
bool columnMajor>
77 inline Eigen::Matrix<T, -1, 1> SparseMatrix<T, indexT, 2, columnMajor>::vectorMultiply(
78 typename SparseMatrix<T, indexT, 2, columnMajor>::Vector &vec) {
81 if (vec.length() != outerDim)
82 throw std::invalid_argument(
83 "The vector must be the same size as the number of columns in the "
87 Eigen::Matrix<T, -1, 1> newVector = Eigen::Matrix<T, -1, 1>::Zero(innerDim, 1);
89 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator vecIter(vec);
91 for (
typename SparseMatrix<T, indexT, 2, columnMajor>::InnerIterator
92 matIter(*
this, vecIter.row());
94 newVector(matIter.row()) += matIter.value() * vecIter.value();
106 template <
typename T,
typename indexT,
bool columnMajor>
108 std::vector<T>
outerSum = std::vector<T>(outerDim);
110 #ifdef IVSPARSE_HAS_OPENMP
111 #pragma omp parallel for
113 for (
int i = 0; i < outerDim; i++) {
114 for (
int j = 0; j < valueSizes[i]; j++) {
115 outerSum[i] += values[i][j] * counts[i][j];
122 template <
typename T,
typename indexT,
bool columnMajor>
124 std::vector<T>
innerSum = std::vector<T>(innerDim);
126 #ifdef IVSPARSE_HAS_OPENMP
127 #pragma omp parallel for
129 for (
int i = 0; i < outerDim; i++) {
140 template <
typename T,
typename indexT,
bool columnMajor>
142 std::vector<T> maxCoeff = std::vector<T>(innerDim);
144 #ifdef IVSPARSE_HAS_OPENMP
145 #pragma omp parallel for
147 for (
int i = 0; i < outerDim; i++) {
148 for (
int j = 0; j < valueSizes[i]; j++) {
149 if (values[i][j] > maxCoeff[i]) {
150 maxCoeff[i] = values[i][j];
158 template <
typename T,
typename indexT,
bool columnMajor>
160 std::vector<T> maxCoeff = std::vector<T>(innerDim);
162 #ifdef IVSPARSE_HAS_OPENMP
163 #pragma omp parallel for
165 for (
int i = 0; i < outerDim; i++) {
169 if (it.value() > maxCoeff[it.row()]) {
170 maxCoeff[it.row()] = it.value();
178 template <
typename T,
typename indexT,
bool columnMajor>
180 std::vector<T> minCoeff = std::vector<T>(innerDim);
182 #ifdef IVSPARSE_HAS_OPENMP
183 #pragma omp parallel for
185 for (
int i = 0; i < outerDim; i++) {
186 for (
int j = 0; j < valueSizes[i]; j++) {
187 if (values[i][j] < minCoeff[i]) {
188 minCoeff[i] = values[i][j];
196 template <
typename T,
typename indexT,
bool columnMajor>
198 std::vector<T> minCoeff = std::vector<T>(innerDim);
199 memset(minCoeff.data(), 0xF, innerDim *
sizeof(T));
201 #ifdef IVSPARSE_HAS_OPENMP
202 #pragma omp parallel for
204 for (
int i = 0; i < outerDim; i++) {
208 if (it.value() < minCoeff[it.row()]) {
209 minCoeff[it.row()] = it.value();
217 template <
typename T,
typename indexT,
bool columnMajor>
220 #ifdef IVSPARSE_DEBUG
221 assert(innerDim == outerDim &&
"Trace is only defined for square matrices!");
226 #ifdef IVSPARSE_HAS_OPENMP
227 #pragma omp parallel for reduction(+ : trace)
229 for (
int i = 0; i < outerDim; i++) {
235 }
else if (it.row() > i) {
244 template <
typename T,
typename indexT,
bool columnMajor>
249 #ifdef IVSPARSE_HAS_OPENMP
250 #pragma omp parallel for reduction(+ : sum)
252 for (
int i = 0; i < outerDim; i++) {
253 for (
int j = 0; j < valueSizes[i]; j++) {
254 sum += values[i][j] * counts[i][j];
261 template <
typename T,
typename indexT,
bool columnMajor>
265 #ifdef IVSPARSE_HAS_OPENMP
266 #pragma omp parallel for reduction(+ : norm)
268 for (
int i = 0; i < outerDim; i++) {
269 for (
int j = 0; j < valueSizes[i]; j++) {
270 norm += values[i][j] * values[i][j] * counts[i][j];
277 template <
typename T,
typename indexT,
bool columnMajor>
280 #ifdef IVSPARSE_DEBUG
281 assert(col < outerDim && col >= 0 &&
"Column index out of bounds!");
286 #ifdef IVSPARSE_HAS_OPENMP
287 #pragma omp parallel for reduction(+ : norm)
289 for (
int i = 0; i < valueSizes[col]; i++) {
290 norm += values[col][i] * values[col][i] * counts[col][i];
Definition: IVCSC_Iterator.hpp:25
Definition: VCSC_SparseMatrix.hpp:21
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