ARTS  2.0.49
matpackIV.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008
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 
46  { /* Nothing to do here. */ }
47 
49  Iterator4D(const Tensor3View& x, Index stride)
50  : msv(x), mstride(stride)
51  { /* Nothing to do here. */ }
52 
53  // Operators:
55  Iterator4D& operator++() { msv.mdata += mstride; return *this; }
56 
58  bool operator!=(const Iterator4D& other) const
59  { if ( msv.mdata +
60  msv.mpr.mstart +
61  msv.mrr.mstart +
62  msv.mcr.mstart
63  !=
64  other.msv.mdata +
65  other.msv.mpr.mstart +
66  other.msv.mrr.mstart +
67  other.msv.mcr.mstart )
68  return true;
69  else
70  return false;
71  }
72 
75 
76 private:
81 };
82 
85 public:
86  // Constructors:
87  // Functions for ConstIterator4D
88  // -----------------------------
89 
91  ConstIterator4D() : msv(), mstride(0) { /* Nothing to do here. */ }
92 
95  { /* Nothing to do here. */ }
96 
99  : msv(x), mstride(stride)
100  { /* Nothing to do here. */ }
101 
102  // Operators:
104  ConstIterator4D& operator++() { msv.mdata += mstride; return *this; }
105 
107  bool operator!=(const ConstIterator4D& other) const
108  { if ( msv.mdata +
109  msv.mpr.mstart +
110  msv.mrr.mstart +
111  msv.mcr.mstart
112  !=
113  other.msv.mdata +
114  other.msv.mpr.mstart +
115  other.msv.mrr.mstart +
116  other.msv.mcr.mstart )
117  return true;
118  else
119  return false;
120  }
121 
122  const ConstTensor3View* operator->() const;
123  const ConstTensor3View& operator*() const;
124 
125 private:
130 };
131 
132 
133 // Declare class Tensor4:
134 class Tensor4;
135 
136 
150 public:
151  // Member functions:
152  Index nbooks() const;
153  Index npages() const;
154  Index nrows() const;
155  Index ncols() const;
156 
157  // Const index operators:
158  ConstTensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c ) const;
159 
160  ConstTensor3View operator()( const Range& b, const Range& p, const Range& r, Index c ) const;
161  ConstTensor3View operator()( const Range& b, const Range& p, Index r, const Range& c ) const;
162  ConstTensor3View operator()( const Range& b, Index p, const Range& r, const Range& c ) const;
163  ConstTensor3View operator()( Index b, const Range& p, const Range& r, const Range& c ) const;
164 
165  ConstMatrixView operator()( const Range& b, const Range& p, Index r, Index c ) const;
166  ConstMatrixView operator()( const Range& b, Index p, const Range& r, Index c ) const;
167  ConstMatrixView operator()( const Range& b, Index p, Index r, const Range& c ) const;
168  ConstMatrixView operator()( Index b, const Range& p, Index r, const Range& c ) const;
169  ConstMatrixView operator()( Index b, const Range& p, const Range& r, Index c ) const;
170  ConstMatrixView operator()( Index b, Index p, const Range& r, const Range& c ) const;
171 
172  ConstVectorView operator()( const Range& b, Index p, Index r, Index c ) const;
173  ConstVectorView operator()( Index b, const Range& p, Index r, Index c ) const;
174  ConstVectorView operator()( Index b, Index p, const Range& r, Index c ) const;
175  ConstVectorView operator()( Index b, Index p, Index r, const Range& c ) const;
176 
179  { // Check if indices are valid:
180  assert( 0 <= b );
181  assert( 0 <= p );
182  assert( 0 <= r );
183  assert( 0 <= c );
184  assert( b < mbr.mextent );
185  assert( p < mpr.mextent );
186  assert( r < mrr.mextent );
187  assert( c < mcr.mextent );
188 
189  return *( mdata +
190  mbr.mstart + b * mbr.mstride +
191  mpr.mstart + p * mpr.mstride +
192  mrr.mstart + r * mrr.mstride +
193  mcr.mstart + c * mcr.mstride );
194  }
195 
196  // Functions returning iterators:
197  ConstIterator4D begin() const;
198  ConstIterator4D end() const;
199 
201  virtual ~ConstTensor4View() {}
202 
203  // Friends:
204  friend class Tensor4View;
205  friend class ConstIterator5D;
206  friend class ConstTensor5View;
207  friend class ConstTensor6View;
208  friend class ConstTensor7View;
209 
210  // Special constructor to make a Tensor4 view of a Tensor3.
212 
213 protected:
214  // Constructors:
217  const Range& b, const Range& p, const Range& r, const Range& c);
219  const Range& pb, const Range& pp, const Range& pr, const Range& pc,
220  const Range& nb, const Range& np, const Range& nr, const Range& nc);
221 
222  // Data members:
223  // -------------
234 };
235 
246 public:
247 
248  // Const index operators:
249  ConstTensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c ) const;
250 
251  ConstTensor3View operator()( const Range& b, const Range& p, const Range& r, Index c ) const;
252  ConstTensor3View operator()( const Range& b, const Range& p, Index r, const Range& c ) const;
253  ConstTensor3View operator()( const Range& b, Index p, const Range& r, const Range& c ) const;
254  ConstTensor3View operator()( Index b, const Range& p, const Range& r, const Range& c ) const;
255 
256  ConstMatrixView operator()( const Range& b, const Range& p, Index r, Index c ) const;
257  ConstMatrixView operator()( const Range& b, Index p, const Range& r, Index c ) const;
258  ConstMatrixView operator()( const Range& b, Index p, Index r, const Range& c ) const;
259  ConstMatrixView operator()( Index b, const Range& p, Index r, const Range& c ) const;
260  ConstMatrixView operator()( Index b, const Range& p, const Range& r, Index c ) const;
261  ConstMatrixView operator()( Index b, Index p, const Range& r, const Range& c ) const;
262 
263  ConstVectorView operator()( const Range& b, Index p, Index r, Index c ) const;
264  ConstVectorView operator()( Index b, const Range& p, Index r, Index c ) const;
265  ConstVectorView operator()( Index b, Index p, const Range& r, Index c ) const;
266  ConstVectorView operator()( Index b, Index p, Index r, const Range& c ) const;
267 
271  { return ConstTensor4View::operator()(b,p,r,c); }
272 
273  // Non-const index operators:
274 
275  Tensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c );
276 
277  Tensor3View operator()( const Range& b, const Range& p, const Range& r, Index c );
278  Tensor3View operator()( const Range& b, const Range& p, Index r, const Range& c );
279  Tensor3View operator()( const Range& b, Index p, const Range& r, const Range& c );
280  Tensor3View operator()( Index b, const Range& p, const Range& r, const Range& c );
281 
282  MatrixView operator()( const Range& b, const Range& p, Index r, Index c );
283  MatrixView operator()( const Range& b, Index p, const Range& r, Index c );
284  MatrixView operator()( const Range& b, Index p, Index r, const Range& c );
285  MatrixView operator()( Index b, const Range& p, Index r, const Range& c );
286  MatrixView operator()( Index b, const Range& p, const Range& r, Index c );
287  MatrixView operator()( Index b, Index p, const Range& r, const Range& c );
288 
289  VectorView operator()( const Range& b, Index p, Index r, Index c );
290  VectorView operator()( Index b, const Range& p, Index r, Index c );
291  VectorView operator()( Index b, Index p, const Range& r, Index c );
292  VectorView operator()( Index b, Index p, Index r, const Range& c );
293 
296  { // Check if indices are valid:
297  assert( 0 <= b );
298  assert( 0 <= p );
299  assert( 0 <= r );
300  assert( 0 <= c );
301  assert( b < mbr.mextent );
302  assert( p < mpr.mextent );
303  assert( r < mrr.mextent );
304  assert( c < mcr.mextent );
305 
306  return *( mdata +
307  mbr.mstart + b * mbr.mstride +
308  mpr.mstart + p * mpr.mstride +
309  mrr.mstart + r * mrr.mstride +
310  mcr.mstart + c * mcr.mstride );
311  }
312 
313  // Conversion to a plain C-array
314  const Numeric *get_c_array() const;
315  Numeric *get_c_array();
316 
317  // Functions returning const iterators:
318  ConstIterator4D begin() const;
319  ConstIterator4D end() const;
320  // Functions returning iterators:
321  Iterator4D begin();
322  Iterator4D end();
323 
324  // Assignment operators:
326  Tensor4View& operator=(const Tensor4View& v);
327  Tensor4View& operator=(const Tensor4& v);
329 
330  // Other operators:
335 
340 
342  virtual ~Tensor4View() {}
343 
344  // Friends:
345  // friend class VectorView;
346  // friend ConstTensor4View transpose(ConstTensor4View m);
347  // friend Tensor4View transpose(Tensor4View m);
348  friend class Iterator5D;
349  friend class Tensor5View;
350  friend class Tensor6View;
351  friend class Tensor7View;
352 
353  // Special constructor to make a Tensor4 view of a Tensor3.
354  Tensor4View(const Tensor3View& a);
355 
356 protected:
357  // Constructors:
358  Tensor4View();
359  Tensor4View(Numeric *data,
360  const Range& b, const Range& p, const Range& r, const Range& c);
361  Tensor4View(Numeric *data,
362  const Range& pb, const Range& pp, const Range& pr, const Range& pc,
363  const Range& nb, const Range& np, const Range& nr, const Range& nc);
364 };
365 
366 
375 class Tensor4 : public Tensor4View {
376 public:
377  // Constructors:
378  Tensor4();
379  Tensor4(Index b, Index p, Index r, Index c);
380  Tensor4(Index b, Index p, Index r, Index c, Numeric fill);
381  Tensor4(const ConstTensor4View& v);
382  Tensor4(const Tensor4& v);
383 
384  // Assignment operators:
385  Tensor4& operator=(const Tensor4& x);
387 
388  // Resize function:
389  void resize(Index b, Index p, Index r, Index c);
390 
391  // Destructor:
392  virtual ~Tensor4();
393 };
394 
395 
396 // Function declarations:
397 // ----------------------
398 
399 void copy(ConstIterator4D origin,
400  const ConstIterator4D& end,
401  Iterator4D target);
402 
403 void copy(Numeric x,
404  Iterator4D target,
405  const Iterator4D& end);
406 
407 void transform( Tensor4View y,
408  double (&my_func)(double),
409  ConstTensor4View x );
410 
411 Numeric max(const ConstTensor4View& x);
412 
413 Numeric min(const ConstTensor4View& x);
414 
415 ostream& operator<<(ostream& os, const ConstTensor4View& v);
416 
418 // Helper function for debugging
419 #ifndef NDEBUG
420 
422  Index b, Index p, Index r, Index c);
423 
424 #endif
425 
427 #endif // matpackIV_h
Tensor7View
The Tensor7View class.
Definition: matpackVII.h:779
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1404
ConstTensor4View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackIV.h:227
MatrixView
The MatrixView class.
Definition: matpackI.h:668
ConstTensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:419
Tensor4View::Tensor4View
Tensor4View()
Default constructor.
Definition: matpackIV.cc:1209
ConstIterator4D::mstride
Index mstride
Stride.
Definition: matpackIV.h:129
ConstIterator4D::operator++
ConstIterator4D & operator++()
Prefix increment operator.
Definition: matpackIV.h:104
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:169
Iterator4D::operator++
Iterator4D & operator++()
Prefix increment operator.
Definition: matpackIV.h:55
Tensor4View::operator*=
Tensor4View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackIV.cc:1082
ConstIterator4D::ConstIterator4D
ConstIterator4D()
Default constructor.
Definition: matpackIV.h:91
ConstTensor4View::mbr
Range mbr
The book range of mdata that is actually used.
Definition: matpackIV.h:225
Iterator4D::Iterator4D
Iterator4D(const Iterator4D &o)
Copy constructor.
Definition: matpackIV.h:45
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:86
ConstTensor4View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIV.h:231
Tensor4::~Tensor4
virtual ~Tensor4()
Destructor for Tensor4.
Definition: matpackIV.cc:1439
ConstTensor4View::operator()
Numeric operator()(Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIV.h:178
ConstIterator4D::ConstIterator4D
ConstIterator4D(const ConstIterator4D &o)
Copy constructor.
Definition: matpackIV.h:94
Tensor4::operator=
Tensor4 & operator=(const Tensor4 &x)
Assignment operator from another tensor.
Definition: matpackIV.cc:1383
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:375
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:1547
Tensor4::Tensor4
Tensor4()
Default constructor.
Definition: matpackIV.cc:1294
Iterator4D::operator->
Tensor3View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 3D iterators.
Definition: matpackIV.cc:30
Iterator4D::Iterator4D
Iterator4D(const Tensor3View &x, Index stride)
Explicit constructor.
Definition: matpackIV.h:49
ConstIterator4D
Const version of Iterator4D.
Definition: matpackIV.h:84
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:149
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:1462
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:234
Tensor4View::operator+=
Tensor4View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackIV.cc:1104
operator<<
ostream & operator<<(ostream &os, const ConstTensor4View &v)
Output operator.
Definition: matpackIV.cc:496
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:43
ConstTensor3View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIII.h:218
ConstTensor3View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIII.h:220
ConstIterator4D::ConstIterator4D
ConstIterator4D(const ConstTensor3View &x, Index stride)
Explicit constructor.
Definition: matpackIV.h:98
VectorView
The VectorView class.
Definition: matpackI.h:373
max
Numeric max(const ConstTensor4View &x)
Max function, tensor version.
Definition: matpackIV.cc:1484
ConstIterator4D::operator!=
bool operator!=(const ConstIterator4D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIV.h:107
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:78
ConstTensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:411
Tensor4View::~Tensor4View
virtual ~Tensor4View()
Destructor.
Definition: matpackIV.h:342
ConstTensor3View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackIII.h:216
ConstTensor6View
A constant view of a Tensor6.
Definition: matpackVI.h:167
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Tensor5View
The Tensor5View class.
Definition: matpackV.h:278
Tensor4View::operator()
Numeric & operator()(Index b, Index p, Index r, Index c)
Plain non-const index operator.
Definition: matpackIV.h:295
ConstTensor3View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIII.h:222
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:66
matpackIII.h
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:60
Tensor4View::operator=
Tensor4View & operator=(const ConstTensor4View &v)
Assignment operator.
Definition: matpackIV.cc:1026
Tensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:1000
Tensor4View::operator()
Numeric operator()(Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIV.h:270
Iterator4D::msv
Tensor3View msv
Current position.
Definition: matpackIV.h:78
Tensor4View::operator/=
Tensor4View & operator/=(Numeric x)
Division by scalar.
Definition: matpackIV.cc:1093
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:591
copy
void copy(ConstIterator4D origin, const ConstIterator4D &end, Iterator4D target)
Copy data between begin and end to target.
Definition: matpackIV.cc:1264
Tensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:994
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:72
Iterator4D::Iterator4D
Iterator4D()
Default constructor.
Definition: matpackIV.h:42
ConstIterator4D::operator*
const ConstTensor3View & operator*() const
Dereferencing.
Definition: matpackIV.cc:49
Range
The range class.
Definition: matpackI.h:148
min
Numeric min(const ConstTensor4View &x)
Min function, tensor version.
Definition: matpackIV.cc:1506
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:207
Iterator4D::operator*
Tensor3View & operator*()
Dereferencing.
Definition: matpackIV.cc:36
Iterator4D
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
ConstTensor4View::~ConstTensor4View
virtual ~ConstTensor4View()
Destructor.
Definition: matpackIV.h:201
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:523
ConstTensor4View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIV.h:229
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:147
Tensor4View
The Tensor4View class.
Definition: matpackIV.h:245
ConstIterator4D::msv
ConstTensor3View msv
Current position.
Definition: matpackIV.h:127
Iterator4D::mstride
Index mstride
Stride.
Definition: matpackIV.h:80
Tensor4View::operator-=
Tensor4View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackIV.cc:1115
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ConstIterator5D
Const version of Iterator5D.
Definition: matpackV.h:92
Iterator4D::operator!=
bool operator!=(const Iterator4D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIV.h:58
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:209
ConstTensor4View::ConstTensor4View
ConstTensor4View()
Default constructor.
Definition: matpackIV.cc:440
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
Tensor4View::get_c_array
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIV.cc:399
ConstTensor4View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIV.h:233
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:160
Tensor6View
The Tensor6View class.
Definition: matpackVI.h:450