ARTS 2.5.9 (git: 825fa5f2)
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#if defined(__clang__)
51#pragma GCC diagnostic ignored "-Wdeprecated-copy-with-dtor"
52#pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor"
53#else
54#pragma GCC diagnostic ignored "-Wclass-memaccess"
55#endif
56
57#include <Eigen/Core>
58#include <Eigen/SparseCore>
59
60#pragma GCC diagnostic pop
61
62#include "array.h"
63#include "matpackI.h"
64
66
75struct Sparse {
76 static constexpr bool matpack_type{true};
77
78 // Constructors:
79 Sparse();
80 Sparse(Index r, Index c);
81
82 void split(Index offset, Index nrows);
83
84 // Insert functions
85 void insert_row(Index r, Vector v);
87 const ArrayOfIndex& rowind,
88 const ArrayOfIndex& colind,
89 ConstVectorView data);
90
91 // Resize function:
92 void resize(Index r, Index c);
93
94 // Member functions:
95 [[nodiscard]] bool empty() const;
96 [[nodiscard]] Index nrows() const;
97 [[nodiscard]] Index ncols() const;
98 [[nodiscard]] Index nnz() const;
99
107
115 [[nodiscard]] Vector diagonal() const;
116
117 // Index Operators:
118 [[nodiscard]] Numeric& rw(Index r, Index c);
119 [[nodiscard]] Numeric ro(Index r, Index c) const;
120 [[nodiscard]] Numeric operator()(Index r, Index c) const;
121
122 // Arithmetic operators:
123 Sparse& operator+=(const Sparse& x);
124 Sparse& operator-=(const Sparse& x);
125
126 // Scaling operators:
129
130 // Conversion to Dense Matrix:
131 explicit operator Matrix() const;
132
133 // Matrix data access
134 void list_elements(Vector& values,
135 ArrayOfIndex& row_indices,
136 ArrayOfIndex& column_indices) const;
137
141
142 // Friends:
143 friend std::ostream& operator<<(std::ostream& os, const Sparse& v);
144 friend void abs(Sparse& A, const Sparse& B);
145 friend void mult(VectorView y, const Sparse& M, ConstVectorView x);
146 friend void transpose_mult(VectorView y, const Sparse& M, ConstVectorView x);
147 friend void mult(MatrixView A, const Sparse& B, const ConstMatrixView& C);
148 friend void mult(MatrixView A, const ConstMatrixView& B, const Sparse& C);
149 friend void mult(Sparse& A, const Sparse& B, const Sparse& C);
150 friend void add(Sparse& A, const Sparse& B, const Sparse& C);
151 friend void sub(Sparse& A, const Sparse& B, const Sparse& C);
152 friend void transpose(Sparse& A, const Sparse& B);
153 friend void id_mat(Sparse& A);
154
156 Eigen::SparseMatrix<Numeric, Eigen::RowMajor> matrix;
157};
158
159// Functions for general matrix operations
160void abs(Sparse& A, const Sparse& B);
161
162void mult(VectorView y, const Sparse& M, ConstVectorView x);
163
165
166void mult(MatrixView A, const Sparse& B, const ConstMatrixView& C);
167
168void mult(MatrixView A, const ConstMatrixView& B, const Sparse& C);
169
170void mult(Sparse& A, const Sparse& B, const Sparse& C);
171
172void add(Sparse& A, const Sparse& B, const Sparse& C);
173
174void sub(Sparse& A, const Sparse& B, const Sparse& C);
175
176void transpose(Sparse& A, const Sparse& B);
177
178void id_mat(Sparse& A);
179
182
183#endif
This file contains the definition of Array.
A constant view of a Matrix.
Definition: matpackI.h:1065
A constant view of a Vector.
Definition: matpackI.h:521
The MatrixView class.
Definition: matpackI.h:1188
The Matrix class.
Definition: matpackI.h:1285
The VectorView class.
Definition: matpackI.h:674
The Vector class.
Definition: matpackI.h:910
void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Definition: matpackII.cc:394
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 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.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#define M
Definition: rng.cc:165
The Sparse class.
Definition: matpackII.h:75
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:107
Eigen::SparseMatrix< Numeric, Eigen::RowMajor > matrix
The actual matrix.
Definition: matpackII.h:156
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:68
int * get_row_start_pointer()
Definition: matpackII.cc:293
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:144
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.cc:291
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:87
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:266
void insert_row(Index r, Vector v)
Insert row function.
Definition: matpackII.cc:314
int * get_column_index_pointer()
Definition: matpackII.cc:292
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:62
Vector diagonal() const
Diagonal elements as vector.
Definition: matpackII.cc:168
Numeric ro(Index r, Index c) const
Read only index operator.
Definition: matpackII.cc:126
Sparse & operator/=(Numeric x)
Scale matrix by reciprocal.
Definition: matpackII.cc:251
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:65
bool empty() const
Returns true if variable size is zero.
Definition: matpackII.cc:57
static constexpr bool matpack_type
Definition: matpackII.h:76
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:239
Sparse & operator-=(const Sparse &x)
Subtract sparse matrix.
Definition: matpackII.cc:227
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:211
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
#define v
#define c