ARTS  2.3.1285(git:92a29ea9-dirty)
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() = default;
46 
48  Iterator5D(const Tensor4View& x, Index stride)
49  : msv(x), mstride(stride) { /* Nothing to do here. */
50  }
51 
52  // Operators:
55  msv.mdata += mstride;
56  return *this;
57  }
58 
60  bool operator!=(const Iterator5D& other) const {
62  msv.mcr.mstart !=
63  other.msv.mdata + other.msv.mbr.mstart + other.msv.mpr.mstart +
64  other.msv.mrr.mstart + other.msv.mcr.mstart)
65  return true;
66  else
67  return false;
68  }
69 
72  Tensor4View* operator->() { return &msv; }
73 
75  Tensor4View& operator*() { return msv; }
76 
77  private:
82 };
83 
86  public:
87  // Constructors:
89  ConstIterator5D() = default;
90 
93  : msv(x), mstride(stride) { /* Nothing to do here. */
94  }
95 
96  // Operators:
99  msv.mdata += mstride;
100  return *this;
101  }
102 
104  bool operator!=(const ConstIterator5D& other) const {
106  msv.mcr.mstart !=
107  other.msv.mdata + other.msv.mbr.mstart + other.msv.mpr.mstart +
108  other.msv.mrr.mstart + other.msv.mcr.mstart)
109  return true;
110  else
111  return false;
112  }
113 
116  const ConstTensor4View* operator->() const { return &msv; }
117 
119  const ConstTensor4View& operator*() const { return msv; }
120 
121  private:
126 };
127 
128 // Declare class Tensor5:
129 class Tensor5;
130 
144  public:
145  constexpr ConstTensor5View(const ConstTensor5View&) = default;
146  constexpr ConstTensor5View(ConstTensor5View&&) = default;
147  ConstTensor5View& operator=(const ConstTensor5View&) = default;
148  ConstTensor5View& operator=(ConstTensor5View&&) = default;
149 
150  // Member functions:
151  bool empty() const;
152  Index nshelves() const;
153  Index nbooks() const;
154  Index npages() const;
155  Index nrows() const;
156  Index ncols() const;
157 
158  // Const index operators:
159  ConstTensor5View operator()(const Range& s,
160  const Range& b,
161  const Range& p,
162  const Range& r,
163  const Range& c) const;
164 
165  ConstTensor4View operator()(const Range& s,
166  const Range& b,
167  const Range& p,
168  const Range& r,
169  Index c) const;
170  ConstTensor4View operator()(const Range& s,
171  const Range& b,
172  const Range& p,
173  Index r,
174  const Range& c) const;
175  ConstTensor4View operator()(const Range& s,
176  const Range& b,
177  Index p,
178  const Range& r,
179  const Range& c) const;
180  ConstTensor4View operator()(const Range& s,
181  Index b,
182  const Range& p,
183  const Range& r,
184  const Range& c) const;
185  ConstTensor4View operator()(Index s,
186  const Range& b,
187  const Range& p,
188  const Range& r,
189  const Range& c) const;
190 
191  ConstTensor3View operator()(
192  const Range& s, const Range& b, const Range& p, Index r, Index c) const;
193  ConstTensor3View operator()(
194  const Range& s, const Range& b, Index p, const Range& r, Index c) const;
195  ConstTensor3View operator()(
196  const Range& s, const Range& b, Index p, Index r, const Range& c) const;
197  ConstTensor3View operator()(
198  const Range& s, Index b, const Range& p, Index r, const Range& c) const;
199  ConstTensor3View operator()(
200  const Range& s, Index b, const Range& p, const Range& r, Index c) const;
201  ConstTensor3View operator()(
202  const Range& s, Index b, Index p, const Range& r, const Range& c) const;
203  ConstTensor3View operator()(
204  Index s, const Range& b, Index p, const Range& r, const Range& c) const;
205  ConstTensor3View operator()(
206  Index s, const Range& b, const Range& p, Index r, const Range& c) const;
207  ConstTensor3View operator()(
208  Index s, const Range& b, const Range& p, const Range& r, Index c) const;
209  ConstTensor3View operator()(
210  Index s, Index b, const Range& p, const Range& r, const Range& c) const;
211 
212  ConstMatrixView operator()(
213  const Range& s, const Range& b, Index p, Index r, Index c) const;
214  ConstMatrixView operator()(
215  const Range& s, Index b, const Range& p, Index r, Index c) const;
216  ConstMatrixView operator()(
217  const Range& s, Index b, Index p, const Range& r, Index c) const;
218  ConstMatrixView operator()(
219  const Range& s, Index b, Index p, Index r, const Range& c) const;
220  ConstMatrixView operator()(
221  Index s, const Range& b, Index p, Index r, const Range& c) const;
222  ConstMatrixView operator()(
223  Index s, const Range& b, Index p, const Range& r, Index c) const;
224  ConstMatrixView operator()(
225  Index s, const Range& b, const Range& p, Index r, Index c) const;
226  ConstMatrixView operator()(
227  Index s, Index b, const Range& p, const Range& r, Index c) const;
228  ConstMatrixView operator()(
229  Index s, Index b, const Range& p, Index r, const Range& c) const;
230  ConstMatrixView operator()(
231  Index s, Index b, Index p, const Range& r, const Range& c) const;
232 
233  ConstVectorView operator()(
234  const Range& s, Index b, Index p, Index r, Index c) const;
235  ConstVectorView operator()(
236  Index s, const Range& b, Index p, Index r, Index c) const;
237  ConstVectorView operator()(
238  Index s, Index b, const Range& p, Index r, Index c) const;
239  ConstVectorView operator()(
240  Index s, Index b, Index p, const Range& r, Index c) const;
241  ConstVectorView operator()(
242  Index s, Index b, Index p, Index r, const Range& c) const;
243 
246  Index b,
247  Index p,
248  Index r,
249  Index c) const { // Check if indices are valid:
250  assert(0 <= s);
251  assert(0 <= b);
252  assert(0 <= p);
253  assert(0 <= r);
254  assert(0 <= c);
255  assert(s < msr.mextent);
256  assert(b < mbr.mextent);
257  assert(p < mpr.mextent);
258  assert(r < mrr.mextent);
259  assert(c < mcr.mextent);
260 
261  return get(s, b, p, r, c);
262  }
263 
265  Numeric get(Index s, Index b, Index p, Index r, Index c) const {
266  return *(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
267  b * mbr.mstride + mpr.mstart + p * mpr.mstride + mrr.mstart +
268  r * mrr.mstride + mcr.mstart + c * mcr.mstride);
269  }
270 
271  // Functions returning iterators:
272  ConstIterator5D begin() const;
273  ConstIterator5D end() const;
274 
276  virtual ~ConstTensor5View() = default;
277 
278  // Friends:
279  friend class Tensor5View;
280  friend class ConstIterator6D;
281  friend class ConstTensor6View;
282  friend class ConstTensor7View;
283 
284  // Special constructor to make a Tensor5 view of a Tensor4.
286 
287  protected:
288  // Constructors:
289  ConstTensor5View() = default;
291  const Range& s,
292  const Range& b,
293  const Range& p,
294  const Range& r,
295  const Range& c);
297  const Range& ps,
298  const Range& pb,
299  const Range& pp,
300  const Range& pr,
301  const Range& pc,
302  const Range& ns,
303  const Range& nb,
304  const Range& np,
305  const Range& nr,
306  const Range& nc);
307 
308  // Data members:
309  // -------------
311  Range msr{0, 0, 1};
313  Range mbr{0, 0, 1};
315  Range mpr{0, 0, 1};
317  Range mrr{0, 0, 1};
319  Range mcr{0, 0, 1};
321  Numeric* mdata{nullptr};
322 };
323 
334  public:
335  // Make const methods visible from base class
337  using ConstTensor5View::end;
338  using ConstTensor5View::operator();
339  using ConstTensor5View::get;
340 
341  constexpr Tensor5View(const Tensor5View&) = default;
342 
343  // Non-const index operators:
344 
345  Tensor5View operator()(const Range& s,
346  const Range& b,
347  const Range& p,
348  const Range& r,
349  const Range& c);
350 
351  Tensor4View operator()(
352  const Range& s, const Range& b, const Range& p, const Range& r, Index c);
353  Tensor4View operator()(
354  const Range& s, const Range& b, const Range& p, Index r, const Range& c);
355  Tensor4View operator()(
356  const Range& s, const Range& b, Index p, const Range& r, const Range& c);
357  Tensor4View operator()(
358  const Range& s, Index b, const Range& p, const Range& r, const Range& c);
359  Tensor4View operator()(
360  Index s, const Range& b, const Range& p, const Range& r, const Range& c);
361 
362  Tensor3View operator()(
363  const Range& s, const Range& b, const Range& p, Index r, Index c);
364  Tensor3View operator()(
365  const Range& s, const Range& b, Index p, const Range& r, Index c);
366  Tensor3View operator()(
367  const Range& s, const Range& b, Index p, Index r, const Range& c);
368  Tensor3View operator()(
369  const Range& s, Index b, const Range& p, Index r, const Range& c);
370  Tensor3View operator()(
371  const Range& s, Index b, const Range& p, const Range& r, Index c);
372  Tensor3View operator()(
373  const Range& s, Index b, Index p, const Range& r, const Range& c);
374  Tensor3View operator()(
375  Index s, const Range& b, Index p, const Range& r, const Range& c);
376  Tensor3View operator()(
377  Index s, const Range& b, const Range& p, Index r, const Range& c);
378  Tensor3View operator()(
379  Index s, const Range& b, const Range& p, const Range& r, Index c);
380  Tensor3View operator()(
381  Index s, Index b, const Range& p, const Range& r, const Range& c);
382 
383  MatrixView operator()(
384  const Range& s, const Range& b, Index p, Index r, Index c);
385  MatrixView operator()(
386  const Range& s, Index b, const Range& p, Index r, Index c);
387  MatrixView operator()(
388  const Range& s, Index b, Index p, const Range& r, Index c);
389  MatrixView operator()(
390  const Range& s, Index b, Index p, Index r, const Range& c);
391  MatrixView operator()(
392  Index s, const Range& b, Index p, Index r, const Range& c);
393  MatrixView operator()(
394  Index s, const Range& b, Index p, const Range& r, Index c);
395  MatrixView operator()(
396  Index s, const Range& b, const Range& p, Index r, Index c);
397  MatrixView operator()(
398  Index s, Index b, const Range& p, const Range& r, Index c);
399  MatrixView operator()(
400  Index s, Index b, const Range& p, Index r, const Range& c);
401  MatrixView operator()(
402  Index s, Index b, Index p, const Range& r, const Range& c);
403 
404  VectorView operator()(const Range& s, Index b, Index p, Index r, Index c);
405  VectorView operator()(Index s, const Range& b, Index p, Index r, Index c);
406  VectorView operator()(Index s, Index b, const Range& p, Index r, Index c);
407  VectorView operator()(Index s, Index b, Index p, const Range& r, Index c);
408  VectorView operator()(Index s, Index b, Index p, Index r, const Range& c);
409 
412  Index b,
413  Index p,
414  Index r,
415  Index c) { // Check if indices are valid:
416  assert(0 <= s);
417  assert(0 <= b);
418  assert(0 <= p);
419  assert(0 <= r);
420  assert(0 <= c);
421  assert(s < msr.mextent);
422  assert(b < mbr.mextent);
423  assert(p < mpr.mextent);
424  assert(r < mrr.mextent);
425  assert(c < mcr.mextent);
426 
427  return get(s, b, p, r, c);
428  }
429 
431  Numeric& get(Index s, Index b, Index p, Index r, Index c) {
432  return *(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
433  b * mbr.mstride + mpr.mstart + p * mpr.mstride + mrr.mstart +
434  r * mrr.mstride + mcr.mstart + c * mcr.mstride);
435  }
436 
437  // Conversion to a plain C-array
438  const Numeric* get_c_array() const;
439  Numeric* get_c_array();
440 
441  // Functions returning iterators:
442  Iterator5D begin();
443  Iterator5D end();
444 
445  // Assignment operators:
446  Tensor5View& operator=(const ConstTensor5View& v);
447  Tensor5View& operator=(const Tensor5View& v);
448  Tensor5View& operator=(const Tensor5& v);
449  Tensor5View& operator=(Numeric x);
450 
451  // Other operators:
452  Tensor5View& operator*=(Numeric x);
453  Tensor5View& operator/=(Numeric x);
455  Tensor5View& operator-=(Numeric x);
456 
457  Tensor5View& operator*=(const ConstTensor5View& x);
458  Tensor5View& operator/=(const ConstTensor5View& x);
460  Tensor5View& operator-=(const ConstTensor5View& x);
461 
463  virtual ~Tensor5View() = default;
464 
465  // Friends:
466  // friend class VectorView;
467  // friend ConstTensor5View transpose(ConstTensor5View m);
468  // friend Tensor5View transpose(Tensor5View m);
469  friend class Iterator6D;
470  friend class Tensor6View;
471  friend class Tensor7View;
472 
473  // Special constructor to make a Tensor5 view of a Tensor4.
474  Tensor5View(const Tensor4View& a);
475 
476  protected:
477  // Constructors:
478  Tensor5View() = default;
480  const Range& s,
481  const Range& b,
482  const Range& p,
483  const Range& r,
484  const Range& c);
486  const Range& ps,
487  const Range& pb,
488  const Range& pp,
489  const Range& pr,
490  const Range& pc,
491  const Range& ns,
492  const Range& nb,
493  const Range& np,
494  const Range& nr,
495  const Range& nc);
496 };
497 
506 class Tensor5 : public Tensor5View {
507  public:
508  // Constructors:
509  Tensor5() = default;
510  Tensor5(Index s, Index b, Index p, Index r, Index c);
511  Tensor5(Index s, Index b, Index p, Index r, Index c, Numeric fill);
512  Tensor5(const ConstTensor5View& v);
513  Tensor5(const Tensor5& v);
514  Tensor5(Tensor5&& v) noexcept : Tensor5View(std::forward<Tensor5View>(v)) {
515  v.mdata = nullptr;
516  }
517 
518  // Assignment operators:
519  Tensor5& operator=(const Tensor5& x);
520  Tensor5& operator=(Tensor5&& x) noexcept;
521  Tensor5& operator=(Numeric x);
522 
523  // Resize function:
524  void resize(Index s, Index b, Index p, Index r, Index c);
525 
526  // Swap function:
527  friend void swap(Tensor5& t1, Tensor5& t2);
528 
529  // Destructor:
530  virtual ~Tensor5();
531 };
532 
533 // Function declarations:
534 // ----------------------
535 
536 void copy(ConstIterator5D origin,
537  const ConstIterator5D& end,
538  Iterator5D target);
539 
540 void copy(Numeric x, Iterator5D target, const Iterator5D& end);
541 
542 void transform(Tensor5View y, double (&my_func)(double), ConstTensor5View x);
543 
544 Numeric max(const ConstTensor5View& x);
545 
546 Numeric min(const ConstTensor5View& x);
547 
548 std::ostream& operator<<(std::ostream& os, const ConstTensor5View& v);
549 
551 // Helper function for debugging
552 #ifndef NDEBUG
553 
555  Tensor5View& tv, Index s, Index b, Index p, Index r, Index c);
556 
557 #endif
558 
560 #endif // matpackV_h
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
The VectorView class.
Definition: matpackI.h:610
void copy(ConstIterator5D origin, const ConstIterator5D &end, Iterator5D target)
Copy data between begin and end to target.
Definition: matpackV.cc:1593
#define ns
The outermost iterator class for rank 6 tensors.
Definition: matpackVI.h:40
Index mstride
The stride.
Definition: matpackI.h:355
The Tensor4View class.
Definition: matpackIV.h:284
Numeric operator()(Index s, Index b, Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackV.h:245
Index mstride
Stride.
Definition: matpackV.h:81
A constant view of a Tensor7.
Definition: matpackVII.h:147
The Tensor7View class.
Definition: matpackVII.h:1286
Index mstart
The start index.
Definition: matpackI.h:346
Range mrr
The row range of mdata that is actually used.
Definition: matpackIV.h:268
The MatrixView class.
Definition: matpackI.h:1093
A constant view of a Tensor6.
Definition: matpackVI.h:149
The range class.
Definition: matpackI.h:160
Const version of Iterator6D.
Definition: matpackVI.h:87
Iterator5D()=default
Default constructor.
The Tensor6View class.
Definition: matpackVI.h:621
ConstIterator5D end() const
Return const iterator behind last shelf.
Definition: matpackV.cc:696
std::ostream & operator<<(std::ostream &os, const ConstTensor5View &v)
Output operator.
Definition: matpackV.cc:758
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Iterator5D & operator++()
Prefix increment operator.
Definition: matpackV.h:54
A constant view of a Tensor4.
Definition: matpackIV.h:133
ConstIterator5D(const ConstTensor4View &x, Index stride)
Explicit constructor.
Definition: matpackV.h:92
Numeric & operator()(Index s, Index b, Index p, Index r, Index c)
Plain const index operator.
Definition: matpackV.h:411
Range mpr
The page range of mdata that is actually used.
Definition: matpackIV.h:266
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Definition: complex.cc:731
Tensor4View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 4D iterators.
Definition: matpackV.h:72
Tensor4View & operator*()
Dereferencing.
Definition: matpackV.h:75
bool operator!=(const Iterator5D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackV.h:60
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackV.h:321
Numeric max(const ConstTensor5View &x)
Max function, tensor version.
Definition: matpackV.cc:1829
The Tensor3View class.
Definition: matpackIII.h:239
Numeric min(const ConstTensor5View &x)
Min function, tensor version.
Definition: matpackV.cc:1848
Range mrr
The row range of mdata that is actually used.
Definition: matpackVII.h:1270
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:1886
Range mcr
The column range of mdata that is actually used.
Definition: matpackVII.h:1272
bool operator!=(const ConstIterator5D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackV.h:104
ConstTensor4View msv
Current position.
Definition: matpackV.h:123
A constant view of a Tensor5.
Definition: matpackV.h:143
Range mbr
The book range of mdata that is actually used.
Definition: matpackIV.h:264
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ConstIterator5D begin() const
Return const iterator to first shelf.
Definition: matpackV.cc:690
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:270
Tensor5(Tensor5 &&v) noexcept
Definition: matpackV.h:514
const ConstTensor4View * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 4D iterators.
Definition: matpackV.h:116
Const version of Iterator5D.
Definition: matpackV.h:85
Tensor4View msv
Current position.
Definition: matpackV.h:79
The Tensor5View class.
Definition: matpackV.h:333
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIV.h:272
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
Range msr
The shelf range of mdata that is actually used.
Definition: matpackVII.h:1264
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackVII.h:1274
A constant view of a Tensor3.
Definition: matpackIII.h:132
const ConstTensor4View & operator*() const
Dereferencing.
Definition: matpackV.h:119
A constant view of a Vector.
Definition: matpackI.h:476
A constant view of a Matrix.
Definition: matpackI.h:982
ConstIterator5D & operator++()
Prefix increment operator.
Definition: matpackV.h:98
Numeric get(Index s, Index b, Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackV.h:265
Range mpr
The page range of mdata that is actually used.
Definition: matpackVII.h:1268
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:108
Range mbr
The book range of mdata that is actually used.
Definition: matpackVII.h:1266
MatrixView & operator+=(MatrixView &A, const Block &B)
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:1810
The Tensor5 class.
Definition: matpackV.h:506