ARTS  2.2.66
matpackV.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 matpackV_h
32 #define matpackV_h
33 
34 #include "matpackIV.h"
35 
38 class Iterator5D {
39 public:
40  // Constructors:
41  // Functions for Iterator5D
42  // ------------------------
43 
45  Iterator5D() : msv(), mstride(0) { /* Nothing to do here. */ }
46 
48  Iterator5D(const Tensor4View& x, Index stride) : msv(x), mstride(stride)
49  { /* Nothing to do here. */ }
50 
51  // Operators:
53  Iterator5D& operator++() { msv.mdata += mstride; return *this; }
54 
56  bool operator!=(const Iterator5D& other) const
57  { if ( msv.mdata +
58  msv.mbr.mstart +
59  msv.mpr.mstart +
60  msv.mrr.mstart +
61  msv.mcr.mstart
62  !=
63  other.msv.mdata +
64  other.msv.mbr.mstart +
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  Tensor4View* operator->() { return &msv; }
76 
78  Tensor4View& operator*() { return msv; }
79 
80 private:
85 };
86 
89 public:
90  // Constructors:
92  ConstIterator5D() : msv(), mstride(0) { /* Nothing to do here. */ }
93 
96  : msv(x), mstride(stride)
97  { /* Nothing to do here. */ }
98 
99  // Operators:
101  ConstIterator5D& operator++() { msv.mdata += mstride; return *this; }
102 
104  bool operator!=(const ConstIterator5D& other) const
105  { if ( msv.mdata +
106  msv.mbr.mstart +
107  msv.mpr.mstart +
108  msv.mrr.mstart +
109  msv.mcr.mstart
110  !=
111  other.msv.mdata +
112  other.msv.mbr.mstart +
113  other.msv.mpr.mstart +
114  other.msv.mrr.mstart +
115  other.msv.mcr.mstart )
116  return true;
117  else
118  return false;
119  }
120 
123  const ConstTensor4View* operator->() const { return &msv; }
124 
126  const ConstTensor4View& operator*() const { return msv; }
127 
128 private:
133 };
134 
135 
136 // Declare class Tensor5:
137 class Tensor5;
138 
139 
153 public:
154  // Member functions:
155  Index nshelves() const;
156  Index nbooks() const;
157  Index npages() const;
158  Index nrows() const;
159  Index ncols() const;
160 
161  // Const index operators:
162  ConstTensor5View operator()( const Range& s, const Range& b, const Range& p, const Range& r, const Range& c ) const;
163 
164  ConstTensor4View operator()( const Range& s, const Range& b, const Range& p, const Range& r, Index c ) const;
165  ConstTensor4View operator()( const Range& s, const Range& b, const Range& p, Index r, const Range& c ) const;
166  ConstTensor4View operator()( const Range& s, const Range& b, Index p, const Range& r, const Range& c ) const;
167  ConstTensor4View operator()( const Range& s, Index b, const Range& p, const Range& r, const Range& c ) const;
168  ConstTensor4View operator()( Index s, const Range& b, const Range& p, const Range& r, const Range& c ) const;
169 
170  ConstTensor3View operator()( const Range& s, const Range& b, const Range& p, Index r, Index c ) const;
171  ConstTensor3View operator()( const Range& s, const Range& b, Index p, const Range& r, Index c ) const;
172  ConstTensor3View operator()( const Range& s, const Range& b, Index p, Index r, const Range& c ) const;
173  ConstTensor3View operator()( const Range& s, Index b, const Range& p, Index r, const Range& c ) const;
174  ConstTensor3View operator()( const Range& s, Index b, const Range& p, const Range& r, Index c ) const;
175  ConstTensor3View operator()( const Range& s, Index b, Index p, const Range& r, const Range& c ) const;
176  ConstTensor3View operator()( Index s, const Range& b, Index p, const Range& r, const Range& c ) const;
177  ConstTensor3View operator()( Index s, const Range& b, const Range& p, Index r, const Range& c ) const;
178  ConstTensor3View operator()( Index s, const Range& b, const Range& p, const Range& r, Index c ) const;
179  ConstTensor3View operator()( Index s, Index b, const Range& p, const Range& r, const Range& c ) const;
180 
181  ConstMatrixView operator()( const Range& s, const Range& b, Index p, Index r, Index c ) const;
182  ConstMatrixView operator()( const Range& s, Index b, const Range& p, Index r, Index c ) const;
183  ConstMatrixView operator()( const Range& s, Index b, Index p, const Range& r, Index c ) const;
184  ConstMatrixView operator()( const Range& s, Index b, Index p, Index r, const Range& c ) const;
185  ConstMatrixView operator()( Index s, const Range& b, Index p, Index r, const Range& c ) const;
186  ConstMatrixView operator()( Index s, const Range& b, Index p, const Range& r, Index c ) const;
187  ConstMatrixView operator()( Index s, const Range& b, const Range& p, Index r, Index c ) const;
188  ConstMatrixView operator()( Index s, Index b, const Range& p, const Range& r, Index c ) const;
189  ConstMatrixView operator()( Index s, Index b, const Range& p, Index r, const Range& c ) const;
190  ConstMatrixView operator()( Index s, Index b, Index p, const Range& r, const Range& c ) const;
191 
192  ConstVectorView operator()( const Range& s, Index b, Index p, Index r, Index c ) const;
193  ConstVectorView operator()( Index s, const Range& b, Index p, Index r, Index c ) const;
194  ConstVectorView operator()( Index s, Index b, const Range& p, Index r, Index c ) const;
195  ConstVectorView operator()( Index s, Index b, Index p, const Range& r, Index c ) const;
196  ConstVectorView operator()( Index s, Index b, Index p, Index r, const Range& c ) const;
197 
200  { // Check if indices are valid:
201  assert( 0 <= s );
202  assert( 0 <= b );
203  assert( 0 <= p );
204  assert( 0 <= r );
205  assert( 0 <= c );
206  assert( s < msr.mextent );
207  assert( b < mbr.mextent );
208  assert( p < mpr.mextent );
209  assert( r < mrr.mextent );
210  assert( c < mcr.mextent );
211 
212  return get(s, b, p, r, c);
213  }
214 
216  Numeric get(Index s, Index b, Index p, Index r, Index c) const
217  {
218  return *( mdata +
219  msr.mstart + s * msr.mstride +
220  mbr.mstart + b * mbr.mstride +
221  mpr.mstart + p * mpr.mstride +
222  mrr.mstart + r * mrr.mstride +
223  mcr.mstart + c * mcr.mstride );
224  }
225 
226  // Functions returning iterators:
227  ConstIterator5D begin() const;
228  ConstIterator5D end() const;
229 
231  virtual ~ConstTensor5View() {}
232 
233  // Friends:
234  friend class Tensor5View;
235  friend class ConstIterator6D;
236  friend class ConstTensor6View;
237  friend class ConstTensor7View;
238 
239  // Special constructor to make a Tensor5 view of a Tensor4.
241 
242 protected:
243  // Constructors:
246  const Range& s, const Range& b, const Range& p, const Range& r, const Range& c);
248  const Range& ps, const Range& pb, const Range& pp, const Range& pr, const Range& pc,
249  const Range& ns, const Range& nb, const Range& np, const Range& nr, const Range& nc);
250 
251  // Data members:
252  // -------------
265 };
266 
277 public:
278 
279  // Const index operators:
280  ConstTensor5View operator()( const Range& s, const Range& b, const Range& p, const Range& r, const Range& c ) const;
281 
282  ConstTensor4View operator()( const Range& s, const Range& b, const Range& p, const Range& r, Index c ) const;
283  ConstTensor4View operator()( const Range& s, const Range& b, const Range& p, Index r, const Range& c ) const;
284  ConstTensor4View operator()( const Range& s, const Range& b, Index p, const Range& r, const Range& c ) const;
285  ConstTensor4View operator()( const Range& s, Index b, const Range& p, const Range& r, const Range& c ) const;
286  ConstTensor4View operator()( Index s, const Range& b, const Range& p, const Range& r, const Range& c ) const;
287 
288  ConstTensor3View operator()( const Range& s, const Range& b, const Range& p, Index r, Index c ) const;
289  ConstTensor3View operator()( const Range& s, const Range& b, Index p, const Range& r, Index c ) const;
290  ConstTensor3View operator()( const Range& s, const Range& b, Index p, Index r, const Range& c ) const;
291  ConstTensor3View operator()( const Range& s, Index b, const Range& p, Index r, const Range& c ) const;
292  ConstTensor3View operator()( const Range& s, Index b, const Range& p, const Range& r, Index c ) const;
293  ConstTensor3View operator()( const Range& s, Index b, Index p, const Range& r, const Range& c ) const;
294  ConstTensor3View operator()( Index s, const Range& b, Index p, const Range& r, const Range& c ) const;
295  ConstTensor3View operator()( Index s, const Range& b, const Range& p, Index r, const Range& c ) const;
296  ConstTensor3View operator()( Index s, const Range& b, const Range& p, const Range& r, Index c ) const;
297  ConstTensor3View operator()( Index s, Index b, const Range& p, const Range& r, const Range& c ) const;
298 
299  ConstMatrixView operator()( const Range& s, const Range& b, Index p, Index r, Index c ) const;
300  ConstMatrixView operator()( const Range& s, Index b, const Range& p, Index r, Index c ) const;
301  ConstMatrixView operator()( const Range& s, Index b, Index p, const Range& r, Index c ) const;
302  ConstMatrixView operator()( const Range& s, Index b, Index p, Index r, const Range& c ) const;
303  ConstMatrixView operator()( Index s, const Range& b, Index p, Index r, const Range& c ) const;
304  ConstMatrixView operator()( Index s, const Range& b, Index p, const Range& r, Index c ) const;
305  ConstMatrixView operator()( Index s, const Range& b, const Range& p, Index r, Index c ) const;
306  ConstMatrixView operator()( Index s, Index b, const Range& p, const Range& r, Index c ) const;
307  ConstMatrixView operator()( Index s, Index b, const Range& p, Index r, const Range& c ) const;
308  ConstMatrixView operator()( Index s, Index b, Index p, const Range& r, const Range& c ) const;
309 
310  ConstVectorView operator()( const Range& s, Index b, Index p, Index r, Index c ) const;
311  ConstVectorView operator()( Index s, const Range& b, Index p, Index r, Index c ) const;
312  ConstVectorView operator()( Index s, Index b, const Range& p, Index r, Index c ) const;
313  ConstVectorView operator()( Index s, Index b, Index p, const Range& r, Index c ) const;
314  ConstVectorView operator()( Index s, Index b, Index p, Index r, const Range& c ) const;
315 
319  { return ConstTensor5View::operator()(s,b,p,r,c); }
320 
322  Numeric get(Index s, Index b, Index p, Index r, Index c) const
323  { return ConstTensor5View::get(s,b,p,r,c); }
324 
325  // Non-const index operators:
326 
327  Tensor5View operator()( const Range& s, const Range& b, const Range& p, const Range& r, const Range& c );
328 
329  Tensor4View operator()( const Range& s, const Range& b, const Range& p, const Range& r, Index c );
330  Tensor4View operator()( const Range& s, const Range& b, const Range& p, Index r, const Range& c );
331  Tensor4View operator()( const Range& s, const Range& b, Index p, const Range& r, const Range& c );
332  Tensor4View operator()( const Range& s, Index b, const Range& p, const Range& r, const Range& c );
333  Tensor4View operator()( Index s, const Range& b, const Range& p, const Range& r, const Range& c );
334 
335  Tensor3View operator()( const Range& s, const Range& b, const Range& p, Index r, Index c );
336  Tensor3View operator()( const Range& s, const Range& b, Index p, const Range& r, Index c );
337  Tensor3View operator()( const Range& s, const Range& b, Index p, Index r, const Range& c );
338  Tensor3View operator()( const Range& s, Index b, const Range& p, Index r, const Range& c );
339  Tensor3View operator()( const Range& s, Index b, const Range& p, const Range& r, Index c );
340  Tensor3View operator()( const Range& s, Index b, Index p, const Range& r, const Range& c );
341  Tensor3View operator()( Index s, const Range& b, Index p, const Range& r, const Range& c );
342  Tensor3View operator()( Index s, const Range& b, const Range& p, Index r, const Range& c );
343  Tensor3View operator()( Index s, const Range& b, const Range& p, const Range& r, Index c );
344  Tensor3View operator()( Index s, Index b, const Range& p, const Range& r, const Range& c );
345 
346  MatrixView operator()( const Range& s, const Range& b, Index p, Index r, Index c );
347  MatrixView operator()( const Range& s, Index b, const Range& p, Index r, Index c );
348  MatrixView operator()( const Range& s, Index b, Index p, const Range& r, Index c );
349  MatrixView operator()( const Range& s, Index b, Index p, Index r, const Range& c );
350  MatrixView operator()( Index s, const Range& b, Index p, Index r, const Range& c );
351  MatrixView operator()( Index s, const Range& b, Index p, const Range& r, Index c );
352  MatrixView operator()( Index s, const Range& b, const Range& p, Index r, Index c );
353  MatrixView operator()( Index s, Index b, const Range& p, const Range& r, Index c );
354  MatrixView operator()( Index s, Index b, const Range& p, Index r, const Range& c );
355  MatrixView operator()( Index s, Index b, Index p, const Range& r, const Range& c );
356 
357  VectorView operator()( const Range& s, Index b, Index p, Index r, Index c );
358  VectorView operator()( Index s, const Range& b, Index p, Index r, Index c );
359  VectorView operator()( Index s, Index b, const Range& p, Index r, Index c );
360  VectorView operator()( Index s, Index b, Index p, const Range& r, Index c );
361  VectorView operator()( Index s, Index b, Index p, Index r, const Range& c );
362 
365  { // Check if indices are valid:
366  assert( 0 <= s );
367  assert( 0 <= b );
368  assert( 0 <= p );
369  assert( 0 <= r );
370  assert( 0 <= c );
371  assert( s < msr.mextent );
372  assert( b < mbr.mextent );
373  assert( p < mpr.mextent );
374  assert( r < mrr.mextent );
375  assert( c < mcr.mextent );
376 
377  return get(s, b, p, r, c);
378  }
379 
381  Numeric& get(Index s, Index b, Index p, Index r, Index c)
382  {
383  return *( mdata +
384  msr.mstart + s * msr.mstride +
385  mbr.mstart + b * mbr.mstride +
386  mpr.mstart + p * mpr.mstride +
387  mrr.mstart + r * mrr.mstride +
388  mcr.mstart + c * mcr.mstride );
389  }
390 
391  // Conversion to a plain C-array
392  const Numeric *get_c_array() const;
393  Numeric *get_c_array();
394 
395  // Functions returning const iterators:
396  ConstIterator5D begin() const;
397  ConstIterator5D end() const;
398  // Functions returning iterators:
399  Iterator5D begin();
400  Iterator5D end();
401 
402  // Assignment operators:
403  Tensor5View& operator=(const ConstTensor5View& v);
404  Tensor5View& operator=(const Tensor5View& v);
405  Tensor5View& operator=(const Tensor5& v);
406  Tensor5View& operator=(Numeric x);
407 
408  // Other operators:
409  Tensor5View& operator*=(Numeric x);
410  Tensor5View& operator/=(Numeric x);
411  Tensor5View& operator+=(Numeric x);
412  Tensor5View& operator-=(Numeric x);
413 
414  Tensor5View& operator*=(const ConstTensor5View& x);
415  Tensor5View& operator/=(const ConstTensor5View& x);
416  Tensor5View& operator+=(const ConstTensor5View& x);
417  Tensor5View& operator-=(const ConstTensor5View& x);
418 
420  virtual ~Tensor5View() {}
421 
422  // Friends:
423  // friend class VectorView;
424  // friend ConstTensor5View transpose(ConstTensor5View m);
425  // friend Tensor5View transpose(Tensor5View m);
426  friend class Iterator6D;
427  friend class Tensor6View;
428  friend class Tensor7View;
429 
430  // Special constructor to make a Tensor5 view of a Tensor4.
431  Tensor5View(const Tensor4View& a);
432 
433 protected:
434  // Constructors:
435  Tensor5View();
436  Tensor5View(Numeric *data,
437  const Range& s, const Range& b, const Range& p, const Range& r, const Range& c);
438  Tensor5View(Numeric *data,
439  const Range& ps, const Range& pb, const Range& pp, const Range& pr, const Range& pc,
440  const Range& ns, const Range& nb, const Range& np, const Range& nr, const Range& nc);
441 };
442 
451 class Tensor5 : public Tensor5View {
452 public:
453  // Constructors:
454  Tensor5();
455  Tensor5(Index s, Index b, Index p, Index r, Index c);
456  Tensor5(Index s, Index b, Index p, Index r, Index c, Numeric fill);
457  Tensor5(const ConstTensor5View& v);
458  Tensor5(const Tensor5& v);
459 
460  // Assignment operators:
461  Tensor5& operator=(Tensor5 x);
462  Tensor5& operator=(Numeric x);
463 
464  // Resize function:
465  void resize(Index s, Index b, Index p, Index r, Index c);
466 
467  // Swap function:
468  friend void swap(Tensor5& t1, Tensor5& t2);
469 
470  // Destructor:
471  virtual ~Tensor5();
472 };
473 
474 
475 // Function declarations:
476 // ----------------------
477 
478 void copy(ConstIterator5D origin,
479  const ConstIterator5D& end,
480  Iterator5D target);
481 
482 void copy(Numeric x,
483  Iterator5D target,
484  const Iterator5D& end);
485 
486 void transform( Tensor5View y,
487  double (&my_func)(double),
488  ConstTensor5View x );
489 
490 Numeric max(const ConstTensor5View& x);
491 
492 Numeric min(const ConstTensor5View& x);
493 
494 std::ostream& operator<<(std::ostream& os, const ConstTensor5View& v);
495 
497 // Helper function for debugging
498 #ifndef NDEBUG
499 
501  Index r, Index c);
502 
503 #endif
504 
506 #endif // matpackV_h
Range mcr
The column range of mdata that is actually used.
Definition: matpackV.h:262
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
void swap(Vector &v1, Vector &v2)
Swaps two objects.
Definition: matpackI.cc:813
The VectorView class.
Definition: matpackI.h:372
void copy(ConstIterator5D origin, const ConstIterator5D &end, Iterator5D target)
Copy data between begin and end to target.
Definition: matpackV.cc:2290
The outermost iterator class for rank 6 tensors.
Definition: matpackVI.h:38
Index mstride
The stride.
Definition: matpackI.h:209
The Tensor4View class.
Definition: matpackIV.h:243
Numeric operator()(Index s, Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackV.h:199
Index mstride
Stride.
Definition: matpackV.h:84
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
Range mrr
The row range of mdata that is actually used.
Definition: matpackIV.h:227
The MatrixView class.
Definition: matpackI.h:679
A constant view of a Tensor6.
Definition: matpackVI.h:159
The range class.
Definition: matpackI.h:148
Const version of Iterator6D.
Definition: matpackVI.h:90
The Tensor6View class.
Definition: matpackVI.h:449
std::ostream & operator<<(std::ostream &os, const ConstTensor5View &v)
Output operator.
Definition: matpackV.cc:888
Numeric operator()(Index s, Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackV.h:318
Iterator5D & operator++()
Prefix increment operator.
Definition: matpackV.h:53
A constant view of a Tensor4.
Definition: matpackIV.h:141
ConstIterator5D(const ConstTensor4View &x, Index stride)
Explicit constructor.
Definition: matpackV.h:95
Numeric & operator()(Index s, Index b, Index p, Index r, Index c)
Plain const index operator.
Definition: matpackV.h:364
Range mpr
The page range of mdata that is actually used.
Definition: matpackIV.h:225
virtual ~ConstTensor5View()
Destructor.
Definition: matpackV.h:231
Tensor4View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 4D iterators.
Definition: matpackV.h:75
Tensor4View & operator*()
Dereferencing.
Definition: matpackV.h:78
Range mbr
The book range of mdata that is actually used.
Definition: matpackV.h:256
Range mpr
The page range of mdata that is actually used.
Definition: matpackV.h:258
bool operator!=(const Iterator5D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackV.h:56
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackV.h:264
Numeric max(const ConstTensor5View &x)
Max function, tensor version.
Definition: matpackV.cc:2530
virtual ~Tensor5View()
Destructor.
Definition: matpackV.h:420
The Tensor3View class.
Definition: matpackIII.h:232
Numeric min(const ConstTensor5View &x)
Min function, tensor version.
Definition: matpackV.cc:2552
Numeric debug_tensor5view_get_elem(Tensor5View &tv, Index s, Index b, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackV.cc:2593
bool operator!=(const ConstIterator5D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackV.h:104
ConstTensor5View operator()(const Range &s, const Range &b, const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackV.cc:67
ConstTensor4View msv
Current position.
Definition: matpackV.h:130
A constant view of a Tensor5.
Definition: matpackV.h:152
Index mstride
Stride.
Definition: matpackV.h:132
Range mbr
The book range of mdata that is actually used.
Definition: matpackIV.h:223
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
Iterator5D(const Tensor4View &x, Index stride)
Explicit constructor.
Definition: matpackV.h:48
Range mcr
The column range of mdata that is actually used.
Definition: matpackIV.h:229
ConstIterator5D()
Default constructor.
Definition: matpackV.h:92
Range msr
The shelf range of mdata that is actually used.
Definition: matpackV.h:254
const ConstTensor4View * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 4D iterators.
Definition: matpackV.h:123
Const version of Iterator5D.
Definition: matpackV.h:88
Tensor4View msv
Current position.
Definition: matpackV.h:82
The Tensor5View class.
Definition: matpackV.h:276
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIV.h:231
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
#define ns
Definition: continua.cc:21931
A constant view of a Tensor3.
Definition: matpackIII.h:139
const ConstTensor4View & operator*() const
Dereferencing.
Definition: matpackV.h:126
Range mrr
The row range of mdata that is actually used.
Definition: matpackV.h:260
A constant view of a Vector.
Definition: matpackI.h:292
A constant view of a Matrix.
Definition: matpackI.h:596
ConstIterator5D & operator++()
Prefix increment operator.
Definition: matpackV.h:101
Iterator5D()
Default constructor.
Definition: matpackV.h:45
Numeric get(Index s, Index b, Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackV.h:216
void transform(Tensor5View y, double(&my_func)(double), ConstTensor5View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackV.cc:2507
The Tensor5 class.
Definition: matpackV.h:451