ARTS  2.0.49
matpackII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2008
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  Sparse(const Sparse& m);
61 
62  // Insert functions
63  void insert_row(Index r, Vector v);
64 
65  // Make identity function:
66  void make_I( Index r, Index c);
67 
68  // Resize function:
69  void resize(Index r, Index c);
70 
71  // Destructor:
72  ~Sparse();
73 
74  // Member functions:
75  Index nrows() const;
76  Index ncols() const;
77  Index nnz() const;
78 
79  const vector<Numeric> * data () const {return mdata;}
80  const vector<Index> * rowind () const {return mrowind;}
81  const vector<Index> * colptr () const {return mcolptr;}
82 
83  // Index Operators:
84  Numeric& rw(Index r, Index c);
85  Numeric ro(Index r, Index c) const;
86  Numeric operator() (Index r, Index c) const;
87 
88  // Assignment Operator:
89  Sparse& operator=(const Sparse& m);
90 
91  // Friends:
92  friend ostream& operator<<(ostream& os, const Sparse& v);
93  friend void abs (Sparse& A, const Sparse& B );
94  friend void mult (VectorView y, const Sparse& M, ConstVectorView x );
95  friend void mult (MatrixView A, const Sparse& B, ConstMatrixView C );
96  friend void mult (Sparse& A, const Sparse& B, const Sparse& C );
97  friend void add (Sparse& A, const Sparse& B, const Sparse& C );
98  friend void sub (Sparse& A, const Sparse& B, const Sparse& C );
99  friend void transpose (Sparse& A, const Sparse& B );
100 
101 private:
103  vector<Numeric> *mdata;
105  vector<Index> *mrowind;
107  vector<Index> *mcolptr;
112 };
113 
114 
115 // Functions for general matrix operations
116 void abs( Sparse& A,
117  const Sparse& B );
118 
119 void mult( VectorView y,
120  const Sparse& M,
121  ConstVectorView x );
122 
123 void mult( MatrixView A,
124  const Sparse& B,
125  ConstMatrixView C );
126 
127 void mult( Sparse& A,
128  const Sparse& B,
129  const Sparse& C );
130 
131 void add( Sparse& A,
132  const Sparse& B,
133  const Sparse& C );
134 
135 void sub( Sparse& A,
136  const Sparse& B,
137  const Sparse& C );
138 
139 void transpose( Sparse& A,
140  const Sparse& B );
141 
142 #endif
Sparse::mdata
vector< Numeric > * mdata
The actual data values.
Definition: matpackII.h:103
MatrixView
The MatrixView class.
Definition: matpackI.h:668
Sparse::colptr
const vector< Index > * colptr() const
Definition: matpackII.h:81
Sparse::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:59
add
void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:974
Sparse::abs
friend void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:641
Sparse::make_I
void make_I(Index r, Index c)
Make Identity matrix.
Definition: matpackII.cc:474
Sparse::add
friend void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:974
Sparse::sub
friend void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:1023
transpose
void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:792
Sparse
The Sparse class.
Definition: matpackII.h:55
Sparse::rowind
const vector< Index > * rowind() const
Definition: matpackII.h:80
Sparse::Sparse
Sparse()
Default constructor.
Definition: matpackII.cc:206
Sparse::mcolptr
vector< Index > * mcolptr
Pointers to first data element for each column.
Definition: matpackII.h:107
Sparse::ro
Numeric ro(Index r, Index c) const
Read only index operator.
Definition: matpackII.cc:167
Sparse::mrowind
vector< Index > * mrowind
Row indices.
Definition: matpackII.h:105
Sparse::operator=
Sparse & operator=(const Sparse &m)
Assignment from another Sparse.
Definition: matpackII.cc:551
Sparse::insert_row
void insert_row(Index r, Vector v)
Insert row function.
Definition: matpackII.cc:303
matpackI.h
sub
void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:1023
Sparse::mcr
Index mcr
Number of rows in the sparse matrix.
Definition: matpackII.h:111
Sparse::nnz
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:65
Sparse::operator()
Numeric operator()(Index r, Index c) const
Plain index operator.
Definition: matpackII.cc:149
VectorView
The VectorView class.
Definition: matpackI.h:373
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
abs
void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:641
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:591
Sparse::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackII.cc:516
Sparse::transpose
friend void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:792
Sparse::mult
friend void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:683
Sparse::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:53
Sparse::rw
Numeric & rw(Index r, Index c)
Read and write index operator.
Definition: matpackII.cc:90
Sparse::data
const vector< Numeric > * data() const
Definition: matpackII.h:79
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Sparse::~Sparse
~Sparse()
Destructor for Sparse.
Definition: matpackII.cc:281
mult
void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:683
M
#define M
Definition: rng.cc:196
Vector
The Vector class.
Definition: matpackI.h:555
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
Sparse::mrr
Index mrr
Number of rows in the sparse matrix.
Definition: matpackII.h:109
Sparse::operator<<
friend ostream & operator<<(ostream &os, const Sparse &v)
Output operator for Sparse.
Definition: matpackII.cc:599