5 #include <gsl/gsl_vector.h> 6 #include <gsl/gsl_vector_int.h> 7 #include <gsl/gsl_matrix.h> 9 #include <Eigen/Sparse> 19 typedef Eigen::SparseMatrix<double, Eigen::RowMajor>
SpMatCSR;
21 typedef Eigen::SparseMatrix<int, Eigen::RowMajor>
SpMatIntCSR;
23 typedef Eigen::SparseMatrix<double, Eigen::ColMajor>
SpMatCSC;
59 gsl_vector *rowSum = gsl_vector_calloc(N);
62 for (
int i = 0; i < N; i++)
63 for (SpMatCSR::InnerIterator it(*T, i); it; ++it)
64 gsl_vector_set(rowSum, i, gsl_vector_get(rowSum, i)+it.value());
83 gsl_vector_set_all(rowSum, 0.);
84 for (
int i = 0; i < N; i++)
85 for (SpMatCSR::InnerIterator it(*T, i); it; ++it)
86 gsl_vector_set(rowSum, i, gsl_vector_get(rowSum, i)+it.value());
102 gsl_vector_int *rowSum = gsl_vector_int_calloc(N);
104 for (
int i = 0; i < N; i++)
105 for (SpMatIntCSR::InnerIterator it(*T, i); it; ++it)
106 gsl_vector_int_set(rowSum, i, gsl_vector_int_get(rowSum, i)+it.value());
122 gsl_vector *colSum = gsl_vector_calloc(N);
125 for (
int irow = 0; irow < N; irow++)
126 for (SpMatCSR::InnerIterator it(*T, irow); it; ++it)
127 gsl_vector_set(colSum, it.col(),
128 gsl_vector_get(colSum, it.col()) + it.value());
147 gsl_vector_set_all(colSum, 0.);
148 for (
int irow = 0; irow < N; irow++)
149 for (SpMatCSR::InnerIterator it(*T, irow); it; ++it)
150 gsl_vector_set(colSum, it.col(),
151 gsl_vector_get(colSum, it.col()) + it.value());
167 gsl_vector *colSum = gsl_vector_calloc(N);
169 for (
int icol = 0; icol < N; icol++)
170 for (SpMatCSC::InnerIterator it(*T, icol); it; ++it)
171 gsl_vector_set(colSum, icol, gsl_vector_get(colSum, icol) + it.value());
189 for (
int irow = 0; irow < N; irow++)
190 for (SpMatCSR::InnerIterator it(*T, irow); it; ++it)
209 for (
size_t i = 0; i < v->size; i++)
210 sum += gsl_vector_get(v, i);
227 gsl_vector_scale(v, 1. / sum);
243 for (
int i = 0; i < T->rows(); i++){
244 rowSumi = gsl_vector_get(rowSum, i);
245 for (SpMatCSR::InnerIterator it(*T, i); it; ++it)
247 it.valueRef() /= rowSumi;
265 for (j = 0; j < T->cols(); j++)
266 for (SpMatCSC::InnerIterator it(*T, j); it; ++it)
267 cmpT->insert(it.row(), j) = it.value() > ref;
285 for (j = 0; j < T->cols(); j++)
286 for (SpMatCSC::InnerIterator it(*T, j); it; ++it)
287 cmpT->insert(it.row(), j) = it.value() < ref;
303 for (j = 0; j < T->cols(); j++)
304 for (SpMatCSCBool::InnerIterator it(*T, j); it; ++it)
322 SpMatCSC::InnerIterator it(*T, 0);
323 double maxValue = it.value();
324 for (j = 0; j < T->cols(); j++)
325 for (SpMatCSC::InnerIterator it(*T, j); it; ++it)
326 if (it.value() > maxValue)
327 maxValue = it.value();
344 SpMatCSC::InnerIterator it(*T, 0);
345 double minValue = it.value();
346 for (j = 0; j < T->cols(); j++)
347 for (SpMatCSC::InnerIterator it(*T, j); it; ++it)
348 if (it.value() < minValue)
349 minValue = it.value();
366 std::vector<int> *
argmax =
new std::vector<int>(2);
367 SpMatCSC::InnerIterator it(*T, 0);
368 double maxValue = it.value();
369 for (j = 0; j < T->cols(); j++){
370 for (SpMatCSC::InnerIterator it(*T, j); it; ++it){
371 if (it.value() > maxValue){
372 argmax->at(0) = it.row();
373 argmax->at(1) = it.col();
374 maxValue = it.value();
393 std::vector<int> *
argmin =
new std::vector<int>(2);
394 SpMatCSC::InnerIterator it(*T, 0);
395 double minValue = it.value();
396 for (j = 0; j < T->cols(); j++){
397 for (SpMatCSC::InnerIterator it(*T, j); it; ++it){
398 if (it.value() < minValue){
399 argmin->at(0) = it.row();
400 argmin->at(1) = it.col();
401 minValue = it.value();
bool any(SpMatCSCBool *)
Perform an any operation on an Eigen CSC matrix of boolean type.
Eigen::SparseMatrix< double, Eigen::RowMajor > SpMatCSR
Eigen CSR matrix of double type.
SpMatCSCBool * cwiseGT(SpMatCSC *, double)
Perform an element-wise greater than test on an Eigen CSC matrix.
SparseMatrix< bool, ColMajor > SpMatCSCBool
Eigen CSC matrix of boolean type.
std::vector< int > * argmax(SpMatCSC *)
Finds the position of the maximum element of an Eigen CSC matrix.
double min(SpMatCSC *)
Finds the minimum element of an Eigen CSC matrix.
gsl_vector * getColSum(SpMatCSR *)
Get the sum of each column of an Eigen CSR matrix.
SpMatCSCBool * cwiseLT(SpMatCSC *, double)
Perform an element-wise lower than test on an Eigen CSC matrix.
gsl_vector * getRowSum(SpMatCSR *)
Get the sum of each row of an Eigen CSR matrix.
double sumVectorElements(gsl_vector *)
Returns a the sum of the elements of an GSL vector.
std::vector< int > * argmin(SpMatCSC *)
Finds the position of the minimum element of an Eigen CSC matrix.
double getSum(SpMatCSR *)
Returns a the sum of the elements of an Eigen CSR matrix.
SparseMatrix< int, RowMajor > SpMatIntCSR
Eigen CSR matrix of integer type.
Eigen::SparseMatrix< int, Eigen::RowMajor > SpMatIntCSR
Eigen CSR matrix of integer type.
double max(SpMatCSC *)
Finds the maximum element of an Eigen CSC matrix.
Eigen::SparseMatrix< bool, Eigen::ColMajor > SpMatCSCBool
Eigen CSC matrix of boolean type.
void normalizeVector(gsl_vector *)
Normalize a GSL vector by the sum of its elements.
Eigen::SparseMatrix< double, Eigen::ColMajor > SpMatCSC
Eigen CSC matrix of double type.
void normalizeRows(SpMatCSR *, gsl_vector *)
Normalize each row of an Eigen CSR matrix by a GSL vector.
Eigen::SparseMatrix< double, Eigen::ColMajor > SpMatCSC
Eigen sparse CSC matrix of double type.