ARTS  2.3.1285(git:92a29ea9-dirty)
matpackII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2016
2  Stefan Buehler <sbuehler@ltu.se>
3  Mattias Ekstroem <ekstrom@rss.chalmers.se>
4  Simon Pfreundschuh <simonpf@chalmers.se>
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the
8  Free Software Foundation; either version 2, or (at your option) any
9  later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19  USA. */
20 
41 #ifndef matpackII_h
42 #define matpackII_h
43 
44 #include <iostream>
45 #include "Eigen/Core"
46 #include "Eigen/SparseCore"
47 #include "array.h"
48 #include "matpackI.h"
49 
51 
60 class Sparse {
61  public:
62  // Constructors:
63  Sparse();
64  Sparse(Index r, Index c);
65 
66  void split(Index offset, Index nrows);
67 
68  // Insert functions
69  void insert_row(Index r, Vector v);
71  const ArrayOfIndex& rowind,
72  const ArrayOfIndex& colind,
74 
75  // Resize function:
76  void resize(Index r, Index c);
77 
78  // Member functions:
79  bool empty() const;
80  Index nrows() const;
81  Index ncols() const;
82  Index nnz() const;
83 
91 
99  Vector diagonal() const;
100 
101  // Index Operators:
102  Numeric& rw(Index r, Index c);
103  Numeric ro(Index r, Index c) const;
104  Numeric operator()(Index r, Index c) const;
105 
106  // Arithmetic operators:
107  Sparse& operator+=(const Sparse& x);
108  Sparse& operator-=(const Sparse& x);
109 
110  // Scaling operators:
113 
114  // Conversion to Dense Matrix:
115  explicit operator Matrix() const;
116 
117  // Matrix data access
118  void list_elements(Vector& values,
119  ArrayOfIndex& row_indices,
120  ArrayOfIndex& column_indices) const;
121 
122  Numeric* get_element_pointer() { return matrix.valuePtr(); }
123  int* get_column_index_pointer() { return matrix.innerIndexPtr(); }
124  int* get_row_start_pointer() { return matrix.outerIndexPtr(); }
125 
126  // Friends:
127  friend std::ostream& operator<<(std::ostream& os, const Sparse& v);
128  friend void abs(Sparse& A, const Sparse& B);
129  friend void mult(VectorView y, const Sparse& M, ConstVectorView x);
130  friend void transpose_mult(VectorView y, const Sparse& M, ConstVectorView x);
131  friend void mult(MatrixView A, const Sparse& B, const ConstMatrixView& C);
132  friend void mult(MatrixView A, const ConstMatrixView& B, const Sparse& C);
133  friend void mult(Sparse& A, const Sparse& B, const Sparse& C);
134  friend void add(Sparse& A, const Sparse& B, const Sparse& C);
135  friend void sub(Sparse& A, const Sparse& B, const Sparse& C);
136  friend void transpose(Sparse& A, const Sparse& B);
137  friend void id_mat(Sparse& A);
138 
139  private:
141  Eigen::SparseMatrix<Numeric, Eigen::RowMajor> matrix;
142 };
143 
144 // Functions for general matrix operations
145 void abs(Sparse& A, const Sparse& B);
146 
147 void mult(VectorView y, const Sparse& M, ConstVectorView x);
148 
150 
151 void mult(MatrixView A, const Sparse& B, const ConstMatrixView& C);
152 
153 void mult(MatrixView A, const ConstMatrixView& B, const Sparse& C);
154 
155 void mult(Sparse& A, const Sparse& B, const Sparse& C);
156 
157 void add(Sparse& A, const Sparse& B, const Sparse& C);
158 
159 void sub(Sparse& A, const Sparse& B, const Sparse& C);
160 
161 void transpose(Sparse& A, const Sparse& B);
162 
163 void id_mat(Sparse& A);
164 
165 #endif
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
friend void id_mat(Sparse &A)
Sparse identity matrix.
Definition: matpackII.cc:647
The VectorView class.
Definition: matpackI.h:610
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:72
Numeric operator()(Index r, Index c) const
Plain index operator.
Definition: matpackII.cc:111
Vector diagonal() const
Diagonal elements as vector.
Definition: matpackII.cc:172
The Vector class.
Definition: matpackI.h:860
The MatrixView class.
Definition: matpackI.h:1093
The Sparse class.
Definition: matpackII.h:60
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:69
Numeric & rw(Index r, Index c)
Read and write index operator.
Definition: matpackII.cc:91
int * get_column_index_pointer()
Definition: matpackII.h:123
bool empty() const
Returns true if variable size is zero.
Definition: matpackII.cc:61
Eigen::SparseMatrix< Numeric, Eigen::RowMajor > matrix
The actual matrix.
Definition: matpackII.h:141
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
friend void transpose_mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
This file contains the definition of Array.
Sparse()
Default constructor.
Definition: matpackII.cc:148
friend void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:582
void split(Index offset, Index nrows)
Reduce matrix to the row range [offset, offset + nrows].
Definition: matpackII.cc:296
friend void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:394
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:66
Sparse & operator/=(Numeric x)
Scale matrix by reciprocal.
Definition: matpackII.cc:255
friend void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:417
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Sparse & operator-=(const Sparse &x)
Subtract sparse matrix.
Definition: matpackII.cc:231
int * get_row_start_pointer()
Definition: matpackII.h:124
friend void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:667
Implementation of Matrix, Vector, and such stuff.
Sparse & operator+=(const Sparse &x)
Add sparse matrix.
Definition: matpackII.cc:215
friend std::ostream & operator<<(std::ostream &os, const Sparse &v)
Output operator for Sparse.
Definition: matpackII.cc:375
Numeric ro(Index r, Index c) const
Read only index operator.
Definition: matpackII.cc:130
A constant view of a Vector.
Definition: matpackI.h:476
void list_elements(Vector &values, ArrayOfIndex &row_indices, ArrayOfIndex &column_indices) const
List elements in matrix.
Definition: matpackII.cc:270
A constant view of a Matrix.
Definition: matpackI.h:982
void resize(Index r, Index c)
Resize function.
Definition: matpackII.cc:361
friend void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:630
void insert_row(Index r, Vector v)
Insert row function.
Definition: matpackII.cc:314
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
Definition: oem.h:34
Numeric * get_element_pointer()
Definition: matpackII.h:122
void insert_elements(Index nnz, const ArrayOfIndex &rowind, const ArrayOfIndex &colind, ConstVectorView data)
Insert vector of elements with given row and column indices.
Definition: matpackII.cc:337
Sparse & operator*=(Numeric x)
Scale matrix.
Definition: matpackII.cc:243