ARTS  2.2.66
matpackII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2012
2  Stefan Buehler <sbuehler@ltu.se>
3  Mattias Ekstroem <ekstrom@rss.chalmers.se>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18  USA. */
19 
40 #ifndef matpackII_h
41 #define matpackII_h
42 
43 #include "matpackI.h"
44 
46 
55 class Sparse {
56 public:
57  // Constructors:
58  Sparse();
59  Sparse(Index r, Index c);
60 
61  // Insert functions
62  void insert_row(Index r, Vector v);
63 
64  // Make identity function:
65  void make_I( Index r, Index c);
66 
67  // Resize function:
68  void resize(Index r, Index c);
69 
70  // Member functions:
71  Index nrows() const;
72  Index ncols() const;
73  Index nnz() const;
74 
75  const std::vector<Numeric> & data () const {return mdata;}
76  const std::vector<Index> & rowind () const {return mrowind;}
77  const std::vector<Index> & colptr () const {return mcolptr;}
78 
79  // Index Operators:
80  Numeric& rw(Index r, Index c);
81  Numeric ro(Index r, Index c) const;
82  Numeric operator() (Index r, Index c) const;
83 
84  // Friends:
85  friend std::ostream& operator<<(std::ostream& os, const Sparse& v);
86  friend void abs (Sparse& A, const Sparse& B );
87  friend void mult (VectorView y, const Sparse& M, ConstVectorView x );
88  friend void mult (MatrixView A, const Sparse& B, ConstMatrixView C );
89  friend void mult (Sparse& A, const Sparse& B, const Sparse& C );
90  friend void add (Sparse& A, const Sparse& B, const Sparse& C );
91  friend void sub (Sparse& A, const Sparse& B, const Sparse& C );
92  friend void transpose (Sparse& A, const Sparse& B );
93 
94 private:
96  std::vector<Numeric> mdata;
98  std::vector<Index> mrowind;
100  std::vector<Index> mcolptr;
105 };
106 
107 
108 // Functions for general matrix operations
109 void abs( Sparse& A,
110  const Sparse& B );
111 
112 void mult( VectorView y,
113  const Sparse& M,
114  ConstVectorView x );
115 
116 void mult( MatrixView A,
117  const Sparse& B,
118  ConstMatrixView C );
119 
120 void mult( Sparse& A,
121  const Sparse& B,
122  const Sparse& C );
123 
124 void add( Sparse& A,
125  const Sparse& B,
126  const Sparse& C );
127 
128 void sub( Sparse& A,
129  const Sparse& B,
130  const Sparse& C );
131 
132 void transpose( Sparse& A,
133  const Sparse& B );
134 
135 #endif
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
The VectorView class.
Definition: matpackI.h:372
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:68
Numeric operator()(Index r, Index c) const
Plain index operator.
Definition: matpackII.cc:152
#define C(a, b)
Definition: Faddeeva.cc:254
#define M
Definition: rng.cc:196
Index mrr
Number of rows in the sparse matrix.
Definition: matpackII.h:102
The Vector class.
Definition: matpackI.h:556
The MatrixView class.
Definition: matpackI.h:679
The Sparse class.
Definition: matpackII.h:55
const std::vector< Index > & rowind() const
Definition: matpackII.h:76
const std::vector< Numeric > & data() const
Definition: matpackII.h:75
Index mcr
Number of rows in the sparse matrix.
Definition: matpackII.h:104
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:62
Numeric & rw(Index r, Index c)
Read and write index operator.
Definition: matpackII.cc:93
void make_I(Index r, Index c)
Make Identity matrix.
Definition: matpackII.cc:430
Sparse()
Default constructor.
Definition: matpackII.cc:209
friend void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:689
friend void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:537
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:56
friend void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:579
std::vector< Index > mcolptr
Pointers to first data element for each column.
Definition: matpackII.h:100
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
friend void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:920
friend std::ostream & operator<<(std::ostream &os, const Sparse &v)
Output operator for Sparse.
Definition: matpackII.cc:495
const std::vector< Index > & colptr() const
Definition: matpackII.h:77
std::vector< Index > mrowind
Row indices.
Definition: matpackII.h:98
Numeric ro(Index r, Index c) const
Read only index operator.
Definition: matpackII.cc:170
A constant view of a Vector.
Definition: matpackI.h:292
A constant view of a Matrix.
Definition: matpackI.h:596
void resize(Index r, Index c)
Resize function.
Definition: matpackII.cc:469
std::vector< Numeric > mdata
The actual data values.
Definition: matpackII.h:96
friend void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:871
void insert_row(Index r, Vector v)
Insert row function.
Definition: matpackII.cc:264