ARTS 2.5.0 (git: 9ee3ac6c)
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
46#pragma GCC diagnostic push
47#pragma GCC diagnostic ignored "-Wshadow"
48#pragma GCC diagnostic ignored "-Wconversion"
49#pragma GCC diagnostic ignored "-Wfloat-conversion"
50#include <Eigen/Core>
51#include <Eigen/SparseCore>
52#pragma GCC diagnostic pop
53
54#include "array.h"
55#include "matpackI.h"
56
58
67class Sparse {
68 public:
69 // Constructors:
70 Sparse();
71 Sparse(Index r, Index c);
72
73 void split(Index offset, Index nrows);
74
75 // Insert functions
76 void insert_row(Index r, Vector v);
78 const ArrayOfIndex& rowind,
79 const ArrayOfIndex& colind,
81
82 // Resize function:
83 void resize(Index r, Index c);
84
85 // Member functions:
86 bool empty() const;
87 Index nrows() const;
88 Index ncols() const;
89 Index nnz() const;
90
98
106 Vector diagonal() const;
107
108 // Index Operators:
109 Numeric& rw(Index r, Index c);
110 Numeric ro(Index r, Index c) const;
111 Numeric operator()(Index r, Index c) const;
112
113 // Arithmetic operators:
114 Sparse& operator+=(const Sparse& x);
115 Sparse& operator-=(const Sparse& x);
116
117 // Scaling operators:
120
121 // Conversion to Dense Matrix:
122 explicit operator Matrix() const;
123
124 // Matrix data access
125 void list_elements(Vector& values,
126 ArrayOfIndex& row_indices,
127 ArrayOfIndex& column_indices) const;
128
129 Numeric* get_element_pointer() { return matrix.valuePtr(); }
130 int* get_column_index_pointer() { return matrix.innerIndexPtr(); }
131 int* get_row_start_pointer() { return matrix.outerIndexPtr(); }
132
133 // Friends:
134 friend std::ostream& operator<<(std::ostream& os, const Sparse& v);
135 friend void abs(Sparse& A, const Sparse& B);
136 friend void mult(VectorView y, const Sparse& M, ConstVectorView x);
137 friend void transpose_mult(VectorView y, const Sparse& M, ConstVectorView x);
138 friend void mult(MatrixView A, const Sparse& B, const ConstMatrixView& C);
139 friend void mult(MatrixView A, const ConstMatrixView& B, const Sparse& C);
140 friend void mult(Sparse& A, const Sparse& B, const Sparse& C);
141 friend void add(Sparse& A, const Sparse& B, const Sparse& C);
142 friend void sub(Sparse& A, const Sparse& B, const Sparse& C);
143 friend void transpose(Sparse& A, const Sparse& B);
144 friend void id_mat(Sparse& A);
145
146 private:
148 Eigen::SparseMatrix<Numeric, Eigen::RowMajor> matrix;
149};
150
151// Functions for general matrix operations
152void abs(Sparse& A, const Sparse& B);
153
154void mult(VectorView y, const Sparse& M, ConstVectorView x);
155
157
158void mult(MatrixView A, const Sparse& B, const ConstMatrixView& C);
159
160void mult(MatrixView A, const ConstMatrixView& B, const Sparse& C);
161
162void mult(Sparse& A, const Sparse& B, const Sparse& C);
163
164void add(Sparse& A, const Sparse& B, const Sparse& C);
165
166void sub(Sparse& A, const Sparse& B, const Sparse& C);
167
168void transpose(Sparse& A, const Sparse& B);
169
170void id_mat(Sparse& A);
171
172#endif
This file contains the definition of Array.
void * data
A constant view of a Matrix.
Definition: matpackI.h:1014
A constant view of a Vector.
Definition: matpackI.h:489
The MatrixView class.
Definition: matpackI.h:1125
The Sparse class.
Definition: matpackII.h:67
friend void id_mat(Sparse &A)
Sparse identity matrix.
Definition: matpackII.cc:647
Numeric operator()(Index r, Index c) const
Plain index operator.
Definition: matpackII.cc:111
Eigen::SparseMatrix< Numeric, Eigen::RowMajor > matrix
The actual matrix.
Definition: matpackII.h:148
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:72
int * get_row_start_pointer()
Definition: matpackII.h:131
friend void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:582
friend void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:394
Sparse()
Default constructor.
Definition: matpackII.cc:148
void split(Index offset, Index nrows)
Reduce matrix to the row range [offset, offset + nrows].
Definition: matpackII.cc:296
Numeric * get_element_pointer()
Definition: matpackII.h:129
friend void transpose_mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
Numeric & rw(Index r, Index c)
Read and write index operator.
Definition: matpackII.cc:91
friend std::ostream & operator<<(std::ostream &os, const Sparse &v)
Output operator for Sparse.
Definition: matpackII.cc:375
void resize(Index r, Index c)
Resize function.
Definition: matpackII.cc:361
void list_elements(Vector &values, ArrayOfIndex &row_indices, ArrayOfIndex &column_indices) const
List elements in matrix.
Definition: matpackII.cc:270
void insert_row(Index r, Vector v)
Insert row function.
Definition: matpackII.cc:314
int * get_column_index_pointer()
Definition: matpackII.h:130
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:66
Vector diagonal() const
Diagonal elements as vector.
Definition: matpackII.cc:172
Numeric ro(Index r, Index c) const
Read only index operator.
Definition: matpackII.cc:130
Sparse & operator/=(Numeric x)
Scale matrix by reciprocal.
Definition: matpackII.cc:255
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:69
bool empty() const
Returns true if variable size is zero.
Definition: matpackII.cc:61
friend void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:667
friend void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:417
Sparse & operator*=(Numeric x)
Scale matrix.
Definition: matpackII.cc:243
Sparse & operator-=(const Sparse &x)
Subtract sparse matrix.
Definition: matpackII.cc:231
friend void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:630
Sparse & operator+=(const Sparse &x)
Add sparse matrix.
Definition: matpackII.cc:215
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
The VectorView class.
Definition: matpackI.h:626
The Vector class.
Definition: matpackI.h:876
void id_mat(Sparse &A)
Sparse identity matrix.
Definition: matpackII.cc:647
void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
Definition: matpackII.cc:582
void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:394
void transpose_mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
Definition: matpackII.cc:667
void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:417
void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
Definition: matpackII.cc:630
Implementation of Matrix, Vector, and such stuff.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
Definition: oem.h:33
#define v
#define c
#define M
Definition: rng.cc:165