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 
312  Numeric& get(Index b, Index p, Index r, Index c)
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:
333  Tensor4View& operator=(const ConstTensor4View& v);
334  Tensor4View& operator=(const Tensor4View& v);
335  Tensor4View& operator=(const Tensor4& v);
336  Tensor4View& operator=(Numeric x);
337 
338  // Other operators:
339  Tensor4View& operator*=(Numeric x);
340  Tensor4View& operator/=(Numeric x);
341  Tensor4View& operator+=(Numeric x);
342  Tensor4View& operator-=(Numeric x);
343 
344  Tensor4View& operator*=(const ConstTensor4View& x);
345  Tensor4View& operator/=(const ConstTensor4View& x);
346  Tensor4View& operator+=(const ConstTensor4View& x);
347  Tensor4View& operator-=(const ConstTensor4View& x);
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:
393  Tensor4& operator=(Tensor4 x);
394  Tensor4& operator=(Numeric x);
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
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Iterator4D(const Tensor3View &x, Index stride)
Explicit constructor.
Definition: matpackIV.h:45
void swap(Vector &v1, Vector &v2)
Swaps two objects.
Definition: matpackI.cc:813
The VectorView class.
Definition: matpackI.h:372
std::ostream & operator<<(std::ostream &os, const ConstTensor4View &v)
Output operator.
Definition: matpackIV.cc:499
Index mstride
The stride.
Definition: matpackI.h:209
The Tensor4View class.
Definition: matpackIV.h:243
Const version of Iterator4D.
Definition: matpackIV.h:80
A constant view of a Tensor7.
Definition: matpackVII.h:162
The Tensor7View class.
Definition: matpackVII.h:780
Index mstart
The start index.
Definition: matpackI.h:204
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
Range mrr
The row range of mdata that is actually used.
Definition: matpackIV.h:227
ConstIterator4D(const ConstTensor3View &x, Index stride)
Explicit constructor.
Definition: matpackIV.h:90
Range mcr
The column range of mdata that is actually used.
Definition: matpackIII.h:218
The MatrixView class.
Definition: matpackI.h:679
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
A constant view of a Tensor6.
Definition: matpackVI.h:159
The Tensor4 class.
Definition: matpackIV.h:383
The range class.
Definition: matpackI.h:148
ConstIterator4D & operator++()
Prefix increment operator.
Definition: matpackIV.h:96
The Tensor6View class.
Definition: matpackVI.h:449
Range mpr
The page range of mdata that is actually used.
Definition: matpackIII.h:214
Numeric min(const ConstTensor4View &x)
Min function, tensor version.
Definition: matpackIV.cc:1517
void copy(ConstIterator4D origin, const ConstIterator4D &end, Iterator4D target)
Copy data between begin and end to target.
Definition: matpackIV.cc:1267
A constant view of a Tensor4.
Definition: matpackIV.h:141
Tensor3View & operator*()
Dereferencing.
Definition: matpackIV.cc:39
Range mpr
The page range of mdata that is actually used.
Definition: matpackIV.h:225
Numeric & operator()(Index b, Index p, Index r, Index c)
Plain non-const index operator.
Definition: matpackIV.h:297
The Tensor3View class.
Definition: matpackIII.h:232
virtual ~Tensor4View()
Destructor.
Definition: matpackIV.h:350
virtual ~ConstTensor4View()
Destructor.
Definition: matpackIV.h:199
Iterator4D()
Default constructor.
Definition: matpackIV.h:42
Numeric operator()(Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIV.h:268
Index mstride
Stride.
Definition: matpackIV.h:76
A constant view of a Tensor5.
Definition: matpackV.h:152
Range mbr
The book range of mdata that is actually used.
Definition: matpackIV.h:223
bool operator!=(const ConstIterator4D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIV.h:99
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
ConstTensor4View operator()(const Range &b, const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIV.cc:89
Range mcr
The column range of mdata that is actually used.
Definition: matpackIV.h:229
Numeric operator()(Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIV.h:170
Const version of Iterator5D.
Definition: matpackV.h:88
ConstTensor3View msv
Current position.
Definition: matpackIV.h:119
bool operator!=(const Iterator4D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIV.h:54
The Tensor5View class.
Definition: matpackV.h:276
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIV.h:231
ConstIterator4D()
Default constructor.
Definition: matpackIV.h:87
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
Index mstride
Stride.
Definition: matpackIV.h:121
A constant view of a Tensor3.
Definition: matpackIII.h:139
A constant view of a Vector.
Definition: matpackI.h:292
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIII.h:220
A constant view of a Matrix.
Definition: matpackI.h:596
Tensor3View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 3D iterators.
Definition: matpackIV.cc:33
Range mrr
The row range of mdata that is actually used.
Definition: matpackIII.h:216
Numeric max(const ConstTensor4View &x)
Max function, tensor version.
Definition: matpackIV.cc:1495
Iterator4D & operator++()
Prefix increment operator.
Definition: matpackIV.h:51
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
Tensor3View msv
Current position.
Definition: matpackIV.h:74
Numeric get(Index b, Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackIV.h:185