ARTS  2.2.66
matpackIV.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2012
2  Stefan Buehler <sbuehler@ltu.se>
3  Wolfram-Andre Haas <wolhaas@hermes.fho-emden.de>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18  USA. */
19 
31 #ifndef matpackIV_h
32 #define matpackIV_h
33 
34 #include "matpackIII.h"
35 
38 class Iterator4D {
39 public:
40  // Constructors:
42  Iterator4D() : msv(), mstride(0) { /* Nothing to do here. */ }
43 
45  Iterator4D(const Tensor3View& x, Index stride)
46  : msv(x), mstride(stride)
47  { /* Nothing to do here. */ }
48 
49  // Operators:
51  Iterator4D& operator++() { msv.mdata += mstride; return *this; }
52 
54  bool operator!=(const Iterator4D& other) const
55  { if ( msv.mdata +
56  msv.mpr.mstart +
57  msv.mrr.mstart +
58  msv.mcr.mstart
59  !=
60  other.msv.mdata +
61  other.msv.mpr.mstart +
62  other.msv.mrr.mstart +
63  other.msv.mcr.mstart )
64  return true;
65  else
66  return false;
67  }
68 
71 
72 private:
77 };
78 
81 public:
82  // Constructors:
83  // Functions for ConstIterator4D
84  // -----------------------------
85 
87  ConstIterator4D() : msv(), mstride(0) { /* Nothing to do here. */ }
88 
91  : msv(x), mstride(stride)
92  { /* Nothing to do here. */ }
93 
94  // Operators:
96  ConstIterator4D& operator++() { msv.mdata += mstride; return *this; }
97 
99  bool operator!=(const ConstIterator4D& other) const
100  { if ( msv.mdata +
101  msv.mpr.mstart +
102  msv.mrr.mstart +
103  msv.mcr.mstart
104  !=
105  other.msv.mdata +
106  other.msv.mpr.mstart +
107  other.msv.mrr.mstart +
108  other.msv.mcr.mstart )
109  return true;
110  else
111  return false;
112  }
113 
114  const ConstTensor3View* operator->() const;
115  const ConstTensor3View& operator*() const;
116 
117 private:
122 };
123 
124 
125 // Declare class Tensor4:
126 class Tensor4;
127 
128 
142 public:
143  // Member functions:
144  Index nbooks() const;
145  Index npages() const;
146  Index nrows() const;
147  Index ncols() const;
148 
149  // Const index operators:
150  ConstTensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c ) const;
151 
152  ConstTensor3View operator()( const Range& b, const Range& p, const Range& r, Index c ) const;
153  ConstTensor3View operator()( const Range& b, const Range& p, Index r, const Range& c ) const;
154  ConstTensor3View operator()( const Range& b, Index p, const Range& r, const Range& c ) const;
155  ConstTensor3View operator()( Index b, const Range& p, const Range& r, const Range& c ) const;
156 
157  ConstMatrixView operator()( const Range& b, const Range& p, Index r, Index c ) const;
158  ConstMatrixView operator()( const Range& b, Index p, const Range& r, Index c ) const;
159  ConstMatrixView operator()( const Range& b, Index p, Index r, const Range& c ) const;
160  ConstMatrixView operator()( Index b, const Range& p, Index r, const Range& c ) const;
161  ConstMatrixView operator()( Index b, const Range& p, const Range& r, Index c ) const;
162  ConstMatrixView operator()( Index b, Index p, const Range& r, const Range& c ) const;
163 
164  ConstVectorView operator()( const Range& b, Index p, Index r, Index c ) const;
165  ConstVectorView operator()( Index b, const Range& p, Index r, Index c ) const;
166  ConstVectorView operator()( Index b, Index p, const Range& r, Index c ) const;
167  ConstVectorView operator()( Index b, Index p, Index r, const Range& c ) const;
168 
171  { // Check if indices are valid:
172  assert( 0 <= b );
173  assert( 0 <= p );
174  assert( 0 <= r );
175  assert( 0 <= c );
176  assert( b < mbr.mextent );
177  assert( p < mpr.mextent );
178  assert( r < mrr.mextent );
179  assert( c < mcr.mextent );
180 
181  return get(b, p, r, c);
182  }
183 
185  Numeric get(Index b, Index p, Index r, Index c) const
186  {
187  return *( mdata +
188  mbr.mstart + b * mbr.mstride +
189  mpr.mstart + p * mpr.mstride +
190  mrr.mstart + r * mrr.mstride +
191  mcr.mstart + c * mcr.mstride );
192  }
193 
194  // Functions returning iterators:
195  ConstIterator4D begin() const;
196  ConstIterator4D end() const;
197 
199  virtual ~ConstTensor4View() {}
200 
201  // Friends:
202  friend class Tensor4View;
203  friend class ConstIterator5D;
204  friend class ConstTensor5View;
205  friend class ConstTensor6View;
206  friend class ConstTensor7View;
207 
208  // Special constructor to make a Tensor4 view of a Tensor3.
210 
211 protected:
212  // Constructors:
215  const Range& b, const Range& p, const Range& r, const Range& c);
217  const Range& pb, const Range& pp, const Range& pr, const Range& pc,
218  const Range& nb, const Range& np, const Range& nr, const Range& nc);
219 
220  // Data members:
221  // -------------
232 };
233 
244 public:
245 
246  // Const index operators:
247  ConstTensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c ) const;
248 
249  ConstTensor3View operator()( const Range& b, const Range& p, const Range& r, Index c ) const;
250  ConstTensor3View operator()( const Range& b, const Range& p, Index r, const Range& c ) const;
251  ConstTensor3View operator()( const Range& b, Index p, const Range& r, const Range& c ) const;
252  ConstTensor3View operator()( Index b, const Range& p, const Range& r, const Range& c ) const;
253 
254  ConstMatrixView operator()( const Range& b, const Range& p, Index r, Index c ) const;
255  ConstMatrixView operator()( const Range& b, Index p, const Range& r, Index c ) const;
256  ConstMatrixView operator()( const Range& b, Index p, Index r, const Range& c ) const;
257  ConstMatrixView operator()( Index b, const Range& p, Index r, const Range& c ) const;
258  ConstMatrixView operator()( Index b, const Range& p, const Range& r, Index c ) const;
259  ConstMatrixView operator()( Index b, Index p, const Range& r, const Range& c ) const;
260 
261  ConstVectorView operator()( const Range& b, Index p, Index r, Index c ) const;
262  ConstVectorView operator()( Index b, const Range& p, Index r, Index c ) const;
263  ConstVectorView operator()( Index b, Index p, const Range& r, Index c ) const;
264  ConstVectorView operator()( Index b, Index p, Index r, const Range& c ) const;
265 
269  { return ConstTensor4View::operator()(b,p,r,c); }
270 
272  Numeric get(Index b, Index p, Index r, Index c) const
273  { return ConstTensor4View::get(b,p,r,c); }
274 
275  // Non-const index operators:
276 
277  Tensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c );
278 
279  Tensor3View operator()( const Range& b, const Range& p, const Range& r, Index c );
280  Tensor3View operator()( const Range& b, const Range& p, Index r, const Range& c );
281  Tensor3View operator()( const Range& b, Index p, const Range& r, const Range& c );
282  Tensor3View operator()( Index b, const Range& p, const Range& r, const Range& c );
283 
284  MatrixView operator()( const Range& b, const Range& p, Index r, Index c );
285  MatrixView operator()( const Range& b, Index p, const Range& r, Index c );
286  MatrixView operator()( const Range& b, Index p, Index r, const Range& c );
287  MatrixView operator()( Index b, const Range& p, Index r, const Range& c );
288  MatrixView operator()( Index b, const Range& p, const Range& r, Index c );
289  MatrixView operator()( Index b, Index p, const Range& r, const Range& c );
290 
291  VectorView operator()( const Range& b, Index p, Index r, Index c );
292  VectorView operator()( Index b, const Range& p, Index r, Index c );
293  VectorView operator()( Index b, Index p, const Range& r, Index c );
294  VectorView operator()( Index b, Index p, Index r, const Range& c );
295 
298  { // Check if indices are valid:
299  assert( 0 <= b );
300  assert( 0 <= p );
301  assert( 0 <= r );
302  assert( 0 <= c );
303  assert( b < mbr.mextent );
304  assert( p < mpr.mextent );
305  assert( r < mrr.mextent );
306  assert( c < mcr.mextent );
307 
308  return get(b, p, r, c);
309  }
310 
313  {
314  return *( mdata +
315  mbr.mstart + b * mbr.mstride +
316  mpr.mstart + p * mpr.mstride +
317  mrr.mstart + r * mrr.mstride +
318  mcr.mstart + c * mcr.mstride );
319  }
320 
321  // Conversion to a plain C-array
322  const Numeric *get_c_array() const;
323  Numeric *get_c_array();
324 
325  // Functions returning const iterators:
326  ConstIterator4D begin() const;
327  ConstIterator4D end() const;
328  // Functions returning iterators:
329  Iterator4D begin();
330  Iterator4D end();
331 
332  // Assignment operators:
334  Tensor4View& operator=(const Tensor4View& v);
335  Tensor4View& operator=(const Tensor4& v);
337 
338  // Other operators:
343 
348 
350  virtual ~Tensor4View() {}
351 
352  // Friends:
353  // friend class VectorView;
354  // friend ConstTensor4View transpose(ConstTensor4View m);
355  // friend Tensor4View transpose(Tensor4View m);
356  friend class Iterator5D;
357  friend class Tensor5View;
358  friend class Tensor6View;
359  friend class Tensor7View;
360 
361  // Special constructor to make a Tensor4 view of a Tensor3.
362  Tensor4View(const Tensor3View& a);
363 
364 protected:
365  // Constructors:
366  Tensor4View();
367  Tensor4View(Numeric *data,
368  const Range& b, const Range& p, const Range& r, const Range& c);
369  Tensor4View(Numeric *data,
370  const Range& pb, const Range& pp, const Range& pr, const Range& pc,
371  const Range& nb, const Range& np, const Range& nr, const Range& nc);
372 };
373 
374 
383 class Tensor4 : public Tensor4View {
384 public:
385  // Constructors:
386  Tensor4();
387  Tensor4(Index b, Index p, Index r, Index c);
388  Tensor4(Index b, Index p, Index r, Index c, Numeric fill);
389  Tensor4(const ConstTensor4View& v);
390  Tensor4(const Tensor4& v);
391 
392  // Assignment operators:
395 
396  // Resize function:
397  void resize(Index b, Index p, Index r, Index c);
398 
399  // Swap function:
400  friend void swap(Tensor4& t1, Tensor4& t2);
401 
402  // Destructor:
403  virtual ~Tensor4();
404 };
405 
406 
407 // Function declarations:
408 // ----------------------
409 
410 void copy(ConstIterator4D origin,
411  const ConstIterator4D& end,
412  Iterator4D target);
413 
414 void copy(Numeric x,
415  Iterator4D target,
416  const Iterator4D& end);
417 
418 void transform( Tensor4View y,
419  double (&my_func)(double),
420  ConstTensor4View x );
421 
422 Numeric max(const ConstTensor4View& x);
423 
424 Numeric min(const ConstTensor4View& x);
425 
426 std::ostream& operator<<(std::ostream& os, const ConstTensor4View& v);
427 
429 // Helper function for debugging
430 #ifndef NDEBUG
431 
433  Index b, Index p, Index r, Index c);
434 
435 #endif
436 
438 #endif // matpackIV_h
Tensor7View
The Tensor7View class.
Definition: matpackVII.h:780
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1403
ConstTensor4View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackIV.h:225
MatrixView
The MatrixView class.
Definition: matpackI.h:679
ConstTensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:422
Tensor4::operator=
Tensor4 & operator=(Tensor4 x)
Assignment operator from another tensor.
Definition: matpackIV.cc:1386
Tensor4View::Tensor4View
Tensor4View()
Default constructor.
Definition: matpackIV.cc:1212
ConstIterator4D::mstride
Index mstride
Stride.
Definition: matpackIV.h:121
ConstIterator4D::operator++
ConstIterator4D & operator++()
Prefix increment operator.
Definition: matpackIV.h:96
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:162
Iterator4D::operator++
Iterator4D & operator++()
Prefix increment operator.
Definition: matpackIV.h:51
Tensor4View::operator*=
Tensor4View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackIV.cc:1085
ConstIterator4D::ConstIterator4D
ConstIterator4D()
Default constructor.
Definition: matpackIV.h:87
ConstTensor4View::mbr
Range mbr
The book range of mdata that is actually used.
Definition: matpackIV.h:223
ConstTensor4View::get
Numeric get(Index b, Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackIV.h:185
ConstTensor4View::operator()
ConstTensor4View operator()(const Range &b, const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIV.cc:89
ConstTensor4View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIV.h:229
Tensor4::~Tensor4
virtual ~Tensor4()
Destructor for Tensor4.
Definition: matpackIV.cc:1450
ConstTensor4View::operator()
Numeric operator()(Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIV.h:170
Tensor4::swap
friend void swap(Tensor4 &t1, Tensor4 &t2)
Swaps two objects.
Definition: matpackIV.cc:1438
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:204
Iterator5D
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
Tensor4
The Tensor4 class.
Definition: matpackIV.h:383
debug_tensor4view_get_elem
Numeric debug_tensor4view_get_elem(Tensor4View &tv, Index b, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackIV.cc:1558
Tensor4::Tensor4
Tensor4()
Default constructor.
Definition: matpackIV.cc:1297
Iterator4D::operator->
Tensor3View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 3D iterators.
Definition: matpackIV.cc:33
Iterator4D::Iterator4D
Iterator4D(const Tensor3View &x, Index stride)
Explicit constructor.
Definition: matpackIV.h:45
ConstIterator4D
Const version of Iterator4D.
Definition: matpackIV.h:80
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:141
transform
void transform(Tensor4View y, double(&my_func)(double), ConstTensor4View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackIV.cc:1473
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:232
Tensor4View::operator+=
Tensor4View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackIV.cc:1107
ConstIterator4D::operator->
const ConstTensor3View * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 3D iterators.
Definition: matpackIV.cc:46
ConstTensor3View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIII.h:216
operator<<
std::ostream & operator<<(std::ostream &os, const ConstTensor4View &v)
Output operator.
Definition: matpackIV.cc:499
ConstTensor3View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIII.h:218
ConstIterator4D::ConstIterator4D
ConstIterator4D(const ConstTensor3View &x, Index stride)
Explicit constructor.
Definition: matpackIV.h:90
VectorView
The VectorView class.
Definition: matpackI.h:372
max
Numeric max(const ConstTensor4View &x)
Max function, tensor version.
Definition: matpackIV.cc:1495
ConstIterator4D::operator!=
bool operator!=(const ConstIterator4D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIV.h:99
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:81
ConstTensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:414
Tensor4View::~Tensor4View
virtual ~Tensor4View()
Destructor.
Definition: matpackIV.h:350
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
Tensor4View::operator()
Numeric & operator()(Index b, Index p, Index r, Index c)
Plain non-const index operator.
Definition: matpackIV.h:297
ConstTensor3View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIII.h:220
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:69
matpackIII.h
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:63
Tensor4View::operator=
Tensor4View & operator=(const ConstTensor4View &v)
Assignment operator.
Definition: matpackIV.cc:1029
Tensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:1003
Tensor4View::get
Numeric & get(Index b, Index p, Index r, Index c)
Get element implementation without assertions.
Definition: matpackIV.h:312
Tensor4View::operator()
Numeric operator()(Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIV.h:268
Iterator4D::msv
Tensor3View msv
Current position.
Definition: matpackIV.h:74
Tensor4View::operator/=
Tensor4View & operator/=(Numeric x)
Division by scalar.
Definition: matpackIV.cc:1096
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:596
copy
void copy(ConstIterator4D origin, const ConstIterator4D &end, Iterator4D target)
Copy data between begin and end to target.
Definition: matpackIV.cc:1267
Tensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:997
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:75
Iterator4D::Iterator4D
Iterator4D()
Default constructor.
Definition: matpackIV.h:42
ConstIterator4D::operator*
const ConstTensor3View & operator*() const
Dereferencing.
Definition: matpackIV.cc:52
Range
The range class.
Definition: matpackI.h:148
min
Numeric min(const ConstTensor4View &x)
Min function, tensor version.
Definition: matpackIV.cc:1517
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:207
Iterator4D::operator*
Tensor3View & operator*()
Dereferencing.
Definition: matpackIV.cc:39
Iterator4D
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
ConstTensor4View::~ConstTensor4View
virtual ~ConstTensor4View()
Destructor.
Definition: matpackIV.h:199
Tensor4View::operator()
ConstTensor4View operator()(const Range &b, const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIV.cc:526
ConstTensor4View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIV.h:227
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:139
Tensor4View
The Tensor4View class.
Definition: matpackIV.h:243
ConstIterator4D::msv
ConstTensor3View msv
Current position.
Definition: matpackIV.h:119
Iterator4D::mstride
Index mstride
Stride.
Definition: matpackIV.h:76
Tensor4View::operator-=
Tensor4View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackIV.cc:1118
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
ConstIterator5D
Const version of Iterator5D.
Definition: matpackV.h:88
Iterator4D::operator!=
bool operator!=(const Iterator4D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIV.h:54
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:209
ConstTensor4View::ConstTensor4View
ConstTensor4View()
Default constructor.
Definition: matpackIV.cc:443
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:292
Tensor4View::get_c_array
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIV.cc:402
ConstTensor4View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIV.h:231
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:152
Tensor4View::get
Numeric get(Index b, Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackIV.h:272
Tensor6View
The Tensor6View class.
Definition: matpackVI.h:449