ARTS  2.4.0(git:4fb77825)
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
Sparse::operator-=
Sparse & operator-=(const Sparse &x)
Subtract sparse matrix.
Definition: matpackII.cc:231
MatrixView
The MatrixView class.
Definition: matpackI.h:1093
Sparse::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:69
add
void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:630
Sparse::get_column_index_pointer
int * get_column_index_pointer()
Definition: matpackII.h:123
Sparse::abs
friend void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:394
Sparse::get_row_start_pointer
int * get_row_start_pointer()
Definition: matpackII.h:124
Sparse::add
friend void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:630
oem::Matrix
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
Definition: oem.h:34
Sparse::sub
friend void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:667
transpose
void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:582
Sparse
The Sparse class.
Definition: matpackII.h:60
Sparse::id_mat
friend void id_mat(Sparse &A)
Sparse identity matrix.
Definition: matpackII.cc:647
ARTS::Var::y
Vector y(Workspace &ws) noexcept
Definition: autoarts.h:7401
data
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Definition: arts_api_classes.cc:232
Sparse::Sparse
Sparse()
Default constructor.
Definition: matpackII.cc:148
Sparse::ro
Numeric ro(Index r, Index c) const
Read only index operator.
Definition: matpackII.cc:130
Sparse::operator<<
friend std::ostream & operator<<(std::ostream &os, const Sparse &v)
Output operator for Sparse.
Definition: matpackII.cc:375
Sparse::list_elements
void list_elements(Vector &values, ArrayOfIndex &row_indices, ArrayOfIndex &column_indices) const
List elements in matrix.
Definition: matpackII.cc:270
array.h
This file contains the definition of Array.
Sparse::insert_row
void insert_row(Index r, Vector v)
Insert row function.
Definition: matpackII.cc:314
matpackI.h
Implementation of Matrix, Vector, and such stuff.
Array< Index >
Sparse::insert_elements
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
sub
void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:667
Sparse::empty
bool empty() const
Returns true if variable size is zero.
Definition: matpackII.cc:61
Sparse::nnz
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:72
Sparse::operator*=
Sparse & operator*=(Numeric x)
Scale matrix.
Definition: matpackII.cc:243
Sparse::operator()
Numeric operator()(Index r, Index c) const
Plain index operator.
Definition: matpackII.cc:111
VectorView
The VectorView class.
Definition: matpackI.h:610
Sparse::get_element_pointer
Numeric * get_element_pointer()
Definition: matpackII.h:122
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:394
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:982
Sparse::diagonal
Vector diagonal() const
Diagonal elements as vector.
Definition: matpackII.cc:172
Sparse::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackII.cc:361
Sparse::transpose
friend void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:582
Sparse::operator/=
Sparse & operator/=(Numeric x)
Scale matrix by reciprocal.
Definition: matpackII.cc:255
Sparse::split
void split(Index offset, Index nrows)
Reduce matrix to the row range [offset, offset + nrows].
Definition: matpackII.cc:296
Sparse::mult
friend void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:417
Sparse::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:66
Sparse::rw
Numeric & rw(Index r, Index c)
Read and write index operator.
Definition: matpackII.cc:91
Sparse::matrix
Eigen::SparseMatrix< Numeric, Eigen::RowMajor > matrix
The actual matrix.
Definition: matpackII.h:141
id_mat
void id_mat(Sparse &A)
Sparse identity matrix.
Definition: matpackII.cc:647
Sparse::transpose_mult
friend void transpose_mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
Sparse::operator+=
Sparse & operator+=(const Sparse &x)
Add sparse matrix.
Definition: matpackII.cc:215
ARTS::Var::x
Vector x(Workspace &ws) noexcept
Definition: autoarts.h:7346
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
transpose_mult
void transpose_mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
mult
void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:417
M
#define M
Definition: rng.cc:165
Vector
The Vector class.
Definition: matpackI.h:860
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:476