ARTS  2.2.66
matpackIII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2012 Stefan Buehler <sbuehler@ltu.se>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
27 #ifndef matpackIII_h
28 #define matpackIII_h
29 
30 #include "matpackI.h"
31 
34 class Iterator3D {
35 public:
36  // Constructors:
38  Iterator3D() : msv(), mstride(0) { /* Nothing to do here. */ }
39 
41  Iterator3D(const MatrixView& x, Index stride) : msv(x), mstride(stride)
42  { /* Nothing to do here. */ }
43 
44  // Operators:
47  { msv.mdata += mstride; return *this; }
48 
50  bool operator!=(const Iterator3D& other) const
51  { if ( msv.mdata +
52  msv.mrr.mstart +
53  msv.mcr.mstart
54  !=
55  other.msv.mdata +
56  other.msv.mrr.mstart +
57  other.msv.mcr.mstart )
58  return true;
59  else
60  return false;
61  }
62 
65  MatrixView* operator->() { return &msv; }
66 
68  MatrixView& operator*() { return msv; }
69 
70 private:
75 };
76 
79 public:
80  // Constructors:
82  ConstIterator3D() : msv(), mstride(0) { /* Nothing to do here. */ }
83 
86  : msv(x), mstride(stride)
87  { /* Nothing to do here. */ }
88 
89  // Operators:
91  ConstIterator3D& operator++() { msv.mdata += mstride; return *this; }
92 
94  bool operator!=(const ConstIterator3D& other) const
95  { if ( msv.mdata +
96  msv.mrr.mstart +
97  msv.mcr.mstart
98  !=
99  other.msv.mdata +
100  other.msv.mrr.mstart +
101  other.msv.mcr.mstart )
102  return true;
103  else
104  return false;
105  }
106 
109  const ConstMatrixView* operator->() const { return &msv; }
110 
112  const ConstMatrixView& operator*() const { return msv; }
113 
114 
115 private:
120 };
121 
122 
123 // Declare class Tensor3:
124 class Tensor3;
125 
126 
140 public:
141  // Member functions:
143  Index npages() const { return mpr.mextent; }
144 
146  Index nrows() const { return mrr.mextent; }
147 
149  Index ncols() const { return mcr.mextent; }
150 
151  // Const index operators:
152  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
153 
154  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
155  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
156  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
157 
158  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
159  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
160  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
161 
164  { // Check if indices are valid:
165  assert( 0<=p );
166  assert( 0<=r );
167  assert( 0<=c );
168  assert( p<mpr.mextent );
169  assert( r<mrr.mextent );
170  assert( c<mcr.mextent );
171 
172  return get(p, r, c);
173  }
174 
176  Numeric get(Index p, Index r, Index c) const
177  {
178  return *( mdata +
179  mpr.mstart + p*mpr.mstride +
180  mrr.mstart + r*mrr.mstride +
181  mcr.mstart + c*mcr.mstride );
182  }
183 
184  // Functions returning iterators:
185  ConstIterator3D begin() const;
186  ConstIterator3D end() const;
187 
189  virtual ~ConstTensor3View() {}
190 
191  // Friends:
192  friend class Tensor3View;
193  friend class ConstIterator4D;
194  friend class ConstTensor4View;
195  friend class ConstTensor5View;
196  friend class ConstTensor6View;
197  friend class ConstTensor7View;
198 
199  // Special constructor to make a Tensor3 view of a matrix.
201 
202 protected:
203  // Constructors:
206  const Range& p, const Range& r, const Range& c);
208  const Range& pp, const Range& pr, const Range& pc,
209  const Range& np, const Range& nr, const Range& nc);
210 
211  // Data members:
212  // -------------
221 };
222 
233 public:
234 
235  // Const index operators:
236  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
237 
238  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
239  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
240  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
241 
242  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
243  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
244  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
245 
249  { return ConstTensor3View::operator()(p,r,c); }
250 
252  Numeric get(Index p, Index r, Index c) const
253  { return ConstTensor3View::get(p,r,c); }
254 
255  // Non-const index operators:
256 
257  Tensor3View operator()( const Range& p, const Range& r, const Range& c );
258 
259  MatrixView operator()( const Range& p, const Range& r, Index c );
260  MatrixView operator()( const Range& p, Index r, const Range& c );
261  MatrixView operator()( Index p, const Range& r, const Range& c );
262 
263  VectorView operator()( Index p, Index r, const Range& c );
264  VectorView operator()( Index p, const Range& r, Index c );
265  VectorView operator()( const Range& p, Index r, Index c );
266 
269  {
270  // Check if indices are valid:
271  assert( 0<=p );
272  assert( 0<=r );
273  assert( 0<=c );
274  assert( p<mpr.mextent );
275  assert( r<mrr.mextent );
276  assert( c<mcr.mextent );
277 
278  return get(p, r, c);
279  }
280 
282  Numeric& get(Index p, Index r, Index c)
283  {
284  return *( mdata +
285  mpr.mstart + p*mpr.mstride +
286  mrr.mstart + r*mrr.mstride +
287  mcr.mstart + c*mcr.mstride );
288  }
289 
290  // Conversion to a plain C-array
291  const Numeric *get_c_array() const;
292  Numeric *get_c_array();
293 
294  // Functions returning const iterators:
295  ConstIterator3D begin() const;
296  ConstIterator3D end() const;
297  // Functions returning iterators:
298  Iterator3D begin();
299  Iterator3D end();
300 
301  // Assignment operators:
302  Tensor3View& operator=(const ConstTensor3View& v);
303  Tensor3View& operator=(const Tensor3View& v);
304  Tensor3View& operator=(const Tensor3& v);
305  Tensor3View& operator=(Numeric x);
306 
307  // Other operators:
308  Tensor3View& operator*=(Numeric x);
309  Tensor3View& operator/=(Numeric x);
310  Tensor3View& operator+=(Numeric x);
311  Tensor3View& operator-=(Numeric x);
312 
313  Tensor3View& operator*=(const ConstTensor3View& x);
314  Tensor3View& operator/=(const ConstTensor3View& x);
315  Tensor3View& operator+=(const ConstTensor3View& x);
316  Tensor3View& operator-=(const ConstTensor3View& x);
317 
319  virtual ~Tensor3View() {}
320 
321  // Friends:
322  friend class Iterator4D;
323  friend class Tensor4View;
324  friend class Tensor5View;
325  friend class Tensor6View;
326  friend class Tensor7View;
327 
328  // Special constructor to make a Tensor3 view of a matrix.
329  Tensor3View(const MatrixView& a);
330 
331 protected:
332  // Constructors:
333  Tensor3View();
334  Tensor3View(Numeric *data, const Range& p, const Range& r, const Range& c);
335  Tensor3View(Numeric *data,
336  const Range& pp, const Range& pr, const Range& pc,
337  const Range& np, const Range& nr, const Range& nc);
338 };
339 
348 class Tensor3 : public Tensor3View {
349 public:
350  // Constructors:
351  Tensor3();
352  Tensor3(Index p, Index r, Index c);
353  Tensor3(Index p, Index r, Index c, Numeric fill);
354  Tensor3(const ConstTensor3View& v);
355  Tensor3(const Tensor3& v);
356 
357  // Assignment operators:
358  Tensor3& operator=(Tensor3 x);
359  Tensor3& operator=(Numeric x);
360 
361  // Resize function:
362  void resize(Index p, Index r, Index c);
363 
364  // Swap function:
365  friend void swap(Tensor3& t1, Tensor3& t2);
366 
367  // Destructor:
368  virtual ~Tensor3();
369 };
370 
371 
372 // Function declarations:
373 // ----------------------
374 
375 void copy(ConstIterator3D origin,
376  const ConstIterator3D& end,
377  Iterator3D target);
378 
379 void copy(Numeric x,
380  Iterator3D target,
381  const Iterator3D& end);
382 
383 void transform( Tensor3View y,
384  double (&my_func)(double),
385  ConstTensor3View x );
386 
387 Numeric max(const ConstTensor3View& x);
388 
389 Numeric min(const ConstTensor3View& x);
390 
391 std::ostream& operator<<(std::ostream& os, const ConstTensor3View& v);
392 
394 // Helper function for debugging
395 #ifndef NDEBUG
396 
398  Index p, Index r, Index c);
399 
400 #endif
401 
403 void mult(Tensor3View A, const ConstVectorView B, const ConstMatrixView C);
404 
405 #endif // matpackIII_h
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
const ConstMatrixView * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:109
void swap(Vector &v1, Vector &v2)
Swaps two objects.
Definition: matpackI.cc:813
The VectorView class.
Definition: matpackI.h:372
The Tensor4View class.
Definition: matpackIV.h:243
ConstMatrixView msv
Current position.
Definition: matpackIII.h:117
#define C(a, b)
Definition: Faddeeva.cc:254
Numeric & operator()(Index p, Index r, Index c)
Plain non-const index operator.
Definition: matpackIII.h:268
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
MatrixView & operator*()
Dereferencing.
Definition: matpackIII.h:68
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:667
Range mcr
The column range of mdata that is actually used.
Definition: matpackIII.h:218
Index mstride
Stride.
Definition: matpackIII.h:119
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
Numeric min(const ConstTensor3View &x)
Min function, tensor version.
Definition: matpackIII.cc:968
The range class.
Definition: matpackI.h:148
Numeric debug_tensor3view_get_elem(Tensor3View &tv, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackIII.cc:1008
MatrixView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:65
Numeric max(const ConstTensor3View &x)
Max function, tensor version.
Definition: matpackIII.cc:946
The Tensor6View class.
Definition: matpackVI.h:449
Range mpr
The page range of mdata that is actually used.
Definition: matpackIII.h:214
Numeric operator()(Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIII.h:163
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:146
A constant view of a Tensor4.
Definition: matpackIV.h:141
void copy(ConstIterator3D origin, const ConstIterator3D &end, Iterator3D target)
Copy data between begin and end to target.
Definition: matpackIII.cc:728
Iterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:46
Iterator3D()
Default constructor.
Definition: matpackIII.h:38
The Tensor3 class.
Definition: matpackIII.h:348
Range mrr
The row range of mdata that is actually used.
Definition: matpackI.h:663
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:149
MatrixView msv
Current position.
Definition: matpackIII.h:72
Index mstride
Stride.
Definition: matpackIII.h:74
The Tensor3View class.
Definition: matpackIII.h:232
virtual ~ConstTensor3View()
Destructor.
Definition: matpackIII.h:189
bool operator!=(const ConstIterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:94
void transform(Tensor3View y, double(&my_func)(double), ConstTensor3View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackIII.cc:925
A constant view of a Tensor5.
Definition: matpackV.h:152
const ConstMatrixView & operator*() const
Dereferencing.
Definition: matpackIII.h:112
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
Range mcr
The column range of mdata that is actually used.
Definition: matpackI.h:665
The Tensor5View class.
Definition: matpackV.h:276
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:143
std::ostream & operator<<(std::ostream &os, const ConstTensor3View &v)
Output operator.
Definition: matpackIII.cc:221
bool operator!=(const Iterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:50
A constant view of a Tensor3.
Definition: matpackIII.h:139
A constant view of a Vector.
Definition: matpackI.h:292
ConstIterator3D(const ConstMatrixView &x, Index stride)
Explicit constructor.
Definition: matpackIII.h:85
void mult(Tensor3View A, const ConstVectorView B, const ConstMatrixView C)
mult Tensor3
Definition: matpackIII.cc:1033
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.cc:37
Iterator3D(const MatrixView &x, Index stride)
Explicit constructor.
Definition: matpackIII.h:41
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
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:34
Numeric operator()(Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIII.h:248
Range mrr
The row range of mdata that is actually used.
Definition: matpackIII.h:216
virtual ~Tensor3View()
Destructor.
Definition: matpackIII.h:319
ConstIterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:91
Const version of Iterator3D.
Definition: matpackIII.h:78
Numeric get(Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackIII.h:176
ConstIterator3D()
Default constructor.
Definition: matpackIII.h:82