ARTS  2.2.66
matpackIII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2012 Stefan Buehler <sbuehler@ltu.se>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
27 #ifndef matpackIII_h
28 #define matpackIII_h
29 
30 #include "matpackI.h"
31 
34 class Iterator3D {
35 public:
36  // Constructors:
38  Iterator3D() : msv(), mstride(0) { /* Nothing to do here. */ }
39 
41  Iterator3D(const MatrixView& x, Index stride) : msv(x), mstride(stride)
42  { /* Nothing to do here. */ }
43 
44  // Operators:
47  { msv.mdata += mstride; return *this; }
48 
50  bool operator!=(const Iterator3D& other) const
51  { if ( msv.mdata +
52  msv.mrr.mstart +
53  msv.mcr.mstart
54  !=
55  other.msv.mdata +
56  other.msv.mrr.mstart +
57  other.msv.mcr.mstart )
58  return true;
59  else
60  return false;
61  }
62 
65  MatrixView* operator->() { return &msv; }
66 
68  MatrixView& operator*() { return msv; }
69 
70 private:
75 };
76 
79 public:
80  // Constructors:
82  ConstIterator3D() : msv(), mstride(0) { /* Nothing to do here. */ }
83 
86  : msv(x), mstride(stride)
87  { /* Nothing to do here. */ }
88 
89  // Operators:
91  ConstIterator3D& operator++() { msv.mdata += mstride; return *this; }
92 
94  bool operator!=(const ConstIterator3D& other) const
95  { if ( msv.mdata +
96  msv.mrr.mstart +
97  msv.mcr.mstart
98  !=
99  other.msv.mdata +
100  other.msv.mrr.mstart +
101  other.msv.mcr.mstart )
102  return true;
103  else
104  return false;
105  }
106 
109  const ConstMatrixView* operator->() const { return &msv; }
110 
112  const ConstMatrixView& operator*() const { return msv; }
113 
114 
115 private:
120 };
121 
122 
123 // Declare class Tensor3:
124 class Tensor3;
125 
126 
140 public:
141  // Member functions:
143  Index npages() const { return mpr.mextent; }
144 
146  Index nrows() const { return mrr.mextent; }
147 
149  Index ncols() const { return mcr.mextent; }
150 
151  // Const index operators:
152  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
153 
154  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
155  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
156  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
157 
158  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
159  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
160  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
161 
164  { // Check if indices are valid:
165  assert( 0<=p );
166  assert( 0<=r );
167  assert( 0<=c );
168  assert( p<mpr.mextent );
169  assert( r<mrr.mextent );
170  assert( c<mcr.mextent );
171 
172  return get(p, r, c);
173  }
174 
176  Numeric get(Index p, Index r, Index c) const
177  {
178  return *( mdata +
179  mpr.mstart + p*mpr.mstride +
180  mrr.mstart + r*mrr.mstride +
181  mcr.mstart + c*mcr.mstride );
182  }
183 
184  // Functions returning iterators:
185  ConstIterator3D begin() const;
186  ConstIterator3D end() const;
187 
189  virtual ~ConstTensor3View() {}
190 
191  // Friends:
192  friend class Tensor3View;
193  friend class ConstIterator4D;
194  friend class ConstTensor4View;
195  friend class ConstTensor5View;
196  friend class ConstTensor6View;
197  friend class ConstTensor7View;
198 
199  // Special constructor to make a Tensor3 view of a matrix.
201 
202 protected:
203  // Constructors:
206  const Range& p, const Range& r, const Range& c);
208  const Range& pp, const Range& pr, const Range& pc,
209  const Range& np, const Range& nr, const Range& nc);
210 
211  // Data members:
212  // -------------
221 };
222 
233 public:
234 
235  // Const index operators:
236  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
237 
238  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
239  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
240  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
241 
242  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
243  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
244  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
245 
249  { return ConstTensor3View::operator()(p,r,c); }
250 
252  Numeric get(Index p, Index r, Index c) const
253  { return ConstTensor3View::get(p,r,c); }
254 
255  // Non-const index operators:
256 
257  Tensor3View operator()( const Range& p, const Range& r, const Range& c );
258 
259  MatrixView operator()( const Range& p, const Range& r, Index c );
260  MatrixView operator()( const Range& p, Index r, const Range& c );
261  MatrixView operator()( Index p, const Range& r, const Range& c );
262 
263  VectorView operator()( Index p, Index r, const Range& c );
264  VectorView operator()( Index p, const Range& r, Index c );
265  VectorView operator()( const Range& p, Index r, Index c );
266 
269  {
270  // Check if indices are valid:
271  assert( 0<=p );
272  assert( 0<=r );
273  assert( 0<=c );
274  assert( p<mpr.mextent );
275  assert( r<mrr.mextent );
276  assert( c<mcr.mextent );
277 
278  return get(p, r, c);
279  }
280 
283  {
284  return *( mdata +
285  mpr.mstart + p*mpr.mstride +
286  mrr.mstart + r*mrr.mstride +
287  mcr.mstart + c*mcr.mstride );
288  }
289 
290  // Conversion to a plain C-array
291  const Numeric *get_c_array() const;
292  Numeric *get_c_array();
293 
294  // Functions returning const iterators:
295  ConstIterator3D begin() const;
296  ConstIterator3D end() const;
297  // Functions returning iterators:
298  Iterator3D begin();
299  Iterator3D end();
300 
301  // Assignment operators:
303  Tensor3View& operator=(const Tensor3View& v);
304  Tensor3View& operator=(const Tensor3& v);
306 
307  // Other operators:
312 
317 
319  virtual ~Tensor3View() {}
320 
321  // Friends:
322  friend class Iterator4D;
323  friend class Tensor4View;
324  friend class Tensor5View;
325  friend class Tensor6View;
326  friend class Tensor7View;
327 
328  // Special constructor to make a Tensor3 view of a matrix.
329  Tensor3View(const MatrixView& a);
330 
331 protected:
332  // Constructors:
333  Tensor3View();
334  Tensor3View(Numeric *data, const Range& p, const Range& r, const Range& c);
335  Tensor3View(Numeric *data,
336  const Range& pp, const Range& pr, const Range& pc,
337  const Range& np, const Range& nr, const Range& nc);
338 };
339 
348 class Tensor3 : public Tensor3View {
349 public:
350  // Constructors:
351  Tensor3();
352  Tensor3(Index p, Index r, Index c);
353  Tensor3(Index p, Index r, Index c, Numeric fill);
354  Tensor3(const ConstTensor3View& v);
355  Tensor3(const Tensor3& v);
356 
357  // Assignment operators:
360 
361  // Resize function:
362  void resize(Index p, Index r, Index c);
363 
364  // Swap function:
365  friend void swap(Tensor3& t1, Tensor3& t2);
366 
367  // Destructor:
368  virtual ~Tensor3();
369 };
370 
371 
372 // Function declarations:
373 // ----------------------
374 
375 void copy(ConstIterator3D origin,
376  const ConstIterator3D& end,
377  Iterator3D target);
378 
379 void copy(Numeric x,
380  Iterator3D target,
381  const Iterator3D& end);
382 
383 void transform( Tensor3View y,
384  double (&my_func)(double),
385  ConstTensor3View x );
386 
387 Numeric max(const ConstTensor3View& x);
388 
389 Numeric min(const ConstTensor3View& x);
390 
391 std::ostream& operator<<(std::ostream& os, const ConstTensor3View& v);
392 
394 // Helper function for debugging
395 #ifndef NDEBUG
396 
398  Index p, Index r, Index c);
399 
400 #endif
401 
403 void mult(Tensor3View A, const ConstVectorView B, const ConstMatrixView C);
404 
405 #endif // matpackIII_h
Iterator3D::operator!=
bool operator!=(const Iterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:50
copy
void copy(ConstIterator3D origin, const ConstIterator3D &end, Iterator3D target)
Copy data between begin and end to target.
Definition: matpackIII.cc:728
Tensor3View::Tensor3View
Tensor3View()
Default constructor.
Definition: matpackIII.cc:678
Tensor7View
The Tensor7View class.
Definition: matpackVII.h:780
Tensor3View::end
ConstIterator3D end() const
Return const iterator behind last row.
Definition: matpackIII.cc:473
MatrixView
The MatrixView class.
Definition: matpackI.h:679
transform
void transform(Tensor3View y, double(&my_func)(double), ConstTensor3View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackIII.cc:925
Tensor3View::operator()
Numeric & operator()(Index p, Index r, Index c)
Plain non-const index operator.
Definition: matpackIII.h:268
ConstTensor3View::operator()
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.cc:37
ConstIterator3D::mstride
Index mstride
Stride.
Definition: matpackIII.h:119
Tensor3
The Tensor3 class.
Definition: matpackIII.h:348
Iterator3D::Iterator3D
Iterator3D()
Default constructor.
Definition: matpackIII.h:38
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:162
ConstIterator3D
Const version of Iterator3D.
Definition: matpackIII.h:78
ConstMatrixView::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:667
ConstTensor3View::ConstTensor3View
ConstTensor3View()
Default constructor.
Definition: matpackIII.cc:174
Tensor3View::operator()
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.cc:250
Tensor3::~Tensor3
virtual ~Tensor3()
Destructor for Tensor3.
Definition: matpackIII.cc:902
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:204
ConstMatrixView::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackI.h:665
ConstIterator3D::operator*
const ConstMatrixView & operator*() const
Dereferencing.
Definition: matpackIII.h:112
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:862
Tensor3View::operator-=
Tensor3View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackIII.cc:592
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:143
ConstMatrixView::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackI.h:663
min
Numeric min(const ConstTensor3View &x)
Min function, tensor version.
Definition: matpackIII.cc:968
ConstIterator4D
Const version of Iterator4D.
Definition: matpackIV.h:80
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:141
matpackI.h
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:232
Iterator3D
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:34
Iterator3D::operator*
MatrixView & operator*()
Dereferencing.
Definition: matpackIII.h:68
ConstTensor3View::begin
ConstIterator3D begin() const
Return const iterator to first page.
Definition: matpackIII.cc:144
Tensor3View::get
Numeric get(Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackIII.h:252
ConstTensor3View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIII.h:216
ConstTensor3View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIII.h:218
debug_tensor3view_get_elem
Numeric debug_tensor3view_get_elem(Tensor3View &tv, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackIII.cc:1008
VectorView
The VectorView class.
Definition: matpackI.h:372
Iterator3D::operator++
Iterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:46
Iterator3D::Iterator3D
Iterator3D(const MatrixView &x, Index stride)
Explicit constructor.
Definition: matpackIII.h:41
ConstTensor3View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackIII.h:214
ConstTensor6View
A constant view of a Tensor6.
Definition: matpackVI.h:159
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
Tensor5View
The Tensor5View class.
Definition: matpackV.h:276
ConstTensor3View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIII.h:220
C
#define C(a, b)
Definition: Faddeeva.cc:254
Tensor3View::operator/=
Tensor3View & operator/=(Numeric x)
Division by scalar.
Definition: matpackIII.cc:570
Iterator3D::msv
MatrixView msv
Current position.
Definition: matpackIII.h:72
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:146
Tensor3::operator=
Tensor3 & operator=(Tensor3 x)
Assignment operator from another tensor.
Definition: matpackIII.cc:845
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:596
Tensor3View::operator*=
Tensor3View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackIII.cc:559
Iterator3D::mstride
Index mstride
Stride.
Definition: matpackIII.h:74
Tensor3View::operator()
Numeric operator()(Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIII.h:248
ConstTensor3View::end
ConstIterator3D end() const
Return const iterator behind last page.
Definition: matpackIII.cc:153
ConstTensor3View::get
Numeric get(Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackIII.h:176
max
Numeric max(const ConstTensor3View &x)
Max function, tensor version.
Definition: matpackIII.cc:946
Range
The range class.
Definition: matpackI.h:148
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:207
Tensor3::swap
friend void swap(Tensor3 &t1, Tensor3 &t2)
Swaps two objects.
Definition: matpackIII.cc:891
ConstIterator3D::msv
ConstMatrixView msv
Current position.
Definition: matpackIII.h:117
Iterator4D
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
Tensor3View::~Tensor3View
virtual ~Tensor3View()
Destructor.
Definition: matpackIII.h:319
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:149
Tensor3View::begin
ConstIterator3D begin() const
Return const iterator to first row.
Definition: matpackIII.cc:467
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:139
Tensor4View
The Tensor4View class.
Definition: matpackIV.h:243
operator<<
std::ostream & operator<<(std::ostream &os, const ConstTensor3View &v)
Output operator.
Definition: matpackIII.cc:221
Tensor3View::get
Numeric & get(Index p, Index r, Index c)
Get element implementation without assertions.
Definition: matpackIII.h:282
ConstIterator3D::operator++
ConstIterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:91
ConstIterator3D::ConstIterator3D
ConstIterator3D()
Default constructor.
Definition: matpackIII.h:82
Tensor3View::operator+=
Tensor3View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackIII.cc:581
ConstTensor3View::~ConstTensor3View
virtual ~ConstTensor3View()
Destructor.
Definition: matpackIII.h:189
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
ConstIterator3D::operator!=
bool operator!=(const ConstIterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:94
Tensor3View::operator=
Tensor3View & operator=(const ConstTensor3View &v)
Assignment operator.
Definition: matpackIII.cc:501
ConstIterator3D::operator->
const ConstMatrixView * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:109
Tensor3View::get_c_array
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIII.cc:455
ConstIterator3D::ConstIterator3D
ConstIterator3D(const ConstMatrixView &x, Index stride)
Explicit constructor.
Definition: matpackIII.h:85
Iterator3D::operator->
MatrixView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:65
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:209
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:292
Tensor3::Tensor3
Tensor3()
Default constructor.
Definition: matpackIII.cc:760
ConstTensor3View::operator()
Numeric operator()(Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIII.h:163
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:152
mult
void mult(Tensor3View A, const ConstVectorView B, const ConstMatrixView C)
mult Tensor3
Definition: matpackIII.cc:1033
Tensor6View
The Tensor6View class.
Definition: matpackVI.h:449