Xmipp  v3.23.11-Nereus
sparse_matrix2d.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Authors: Javier Vargas (jvargas@cnb.csic.es)
3  *
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef SPARSE_MATRIX2D_H_
27 #define SPARSE_MATRIX2D_H_
28 
29 #include "core/multidim_array.h"
30 
34 {
35 public:
36  size_t i;
37  size_t j;
38  double value;
39 };
40 
42 inline bool operator< (const SparseElement& _x, const SparseElement& _y)
43 {
44  return ( _x.i < _y.i) || (( _x.i== _y.i) && ( _x.j< _y.j));
45 }
46 
50 
81 {
82 public:
84  int N=0;
85 
92 public:
94  int nrows() const
95  {
96  return N;
97  }
98 
100  int ncols() const
101  {
102  return N;
103  }
104 
108  SparseMatrix2D(std::vector<SparseElement> &_elements, int _Nelements);
109 
111  void sparseMatrix2DFromVector(std::vector<SparseElement> &_elements);
112 
116  void multMv(double* x, double* y);
117 
119  void multMM(const SparseMatrix2D &X, SparseMatrix2D &Y);
120 
124  void multMMDiagonal(const MultidimArray<double> &D, SparseMatrix2D &Y);
125 
127  friend std::ostream & operator << (std::ostream &out, const SparseMatrix2D &X);
128 
132  double getElemIJ(int row, int col) const;
133 
145  void loadMatrix(const FileName &fn);
146 };
148 
149 #endif /* SPARSE_MATRIX2D_H_ */
MultidimArray< double > values
List of values.
static double * y
int ncols() const
X size of the matrix.
std::ostream & operator<<(std::ostream &os, const Message &sb)
doublereal * x
MultidimArray< int > iIdx
List of i positions.
int nrows() const
Y size of the matrix.
MultidimArray< int > jIdx
List of j positions.
bool operator<(const SparseElement &_x, const SparseElement &_y)