ARTS  2.0.49
matpackIII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2008 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 
42  { /* Nothing to do here. */ }
43 
45  Iterator3D(const MatrixView& x, Index stride) : msv(x), mstride(stride)
46  { /* Nothing to do here. */ }
47 
48  // Operators:
51  { msv.mdata += mstride; return *this; }
52 
54  bool operator!=(const Iterator3D& other) const
55  { if ( msv.mdata +
56  msv.mrr.mstart +
57  msv.mcr.mstart
58  !=
59  other.msv.mdata +
60  other.msv.mrr.mstart +
61  other.msv.mcr.mstart )
62  return true;
63  else
64  return false;
65  }
66 
69  MatrixView* operator->() { return &msv; }
70 
72  MatrixView& operator*() { return msv; }
73 
74 private:
79 };
80 
83 public:
84  // Constructors:
86  ConstIterator3D() : msv(), mstride(0) { /* Nothing to do here. */ }
87 
90  { /* Nothing to do here. */ }
91 
94  : msv(x), mstride(stride)
95  { /* Nothing to do here. */ }
96 
97  // Operators:
99  ConstIterator3D& operator++() { msv.mdata += mstride; return *this; }
100 
102  bool operator!=(const ConstIterator3D& other) const
103  { if ( msv.mdata +
104  msv.mrr.mstart +
105  msv.mcr.mstart
106  !=
107  other.msv.mdata +
108  other.msv.mrr.mstart +
109  other.msv.mcr.mstart )
110  return true;
111  else
112  return false;
113  }
114 
117  const ConstMatrixView* operator->() const { return &msv; }
118 
120  const ConstMatrixView& operator*() const { return msv; }
121 
122 
123 private:
128 };
129 
130 
131 // Declare class Tensor3:
132 class Tensor3;
133 
134 
148 public:
149  // Member functions:
151  Index npages() const { return mpr.mextent; }
152 
154  Index nrows() const { return mrr.mextent; }
155 
157  Index ncols() const { return mcr.mextent; }
158 
159  // Const index operators:
160  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
161 
162  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
163  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
164  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
165 
166  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
167  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
168  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
169 
172  { // Check if indices are valid:
173  assert( 0<=p );
174  assert( 0<=r );
175  assert( 0<=c );
176  assert( p<mpr.mextent );
177  assert( r<mrr.mextent );
178  assert( c<mcr.mextent );
179 
180  return *( mdata +
181  mpr.mstart + p*mpr.mstride +
182  mrr.mstart + r*mrr.mstride +
183  mcr.mstart + c*mcr.mstride );
184  }
185 
186  // Functions returning iterators:
187  ConstIterator3D begin() const;
188  ConstIterator3D end() const;
189 
191  virtual ~ConstTensor3View() {}
192 
193  // Friends:
194  friend class Tensor3View;
195  friend class ConstIterator4D;
196  friend class ConstTensor4View;
197  friend class ConstTensor5View;
198  friend class ConstTensor6View;
199  friend class ConstTensor7View;
200 
201  // Special constructor to make a Tensor3 view of a matrix.
203 
204 protected:
205  // Constructors:
208  const Range& p, const Range& r, const Range& c);
210  const Range& pp, const Range& pr, const Range& pc,
211  const Range& np, const Range& nr, const Range& nc);
212 
213  // Data members:
214  // -------------
223 };
224 
235 public:
236 
237  // Const index operators:
238  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
239 
240  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
241  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
242  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
243 
244  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
245  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
246  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
247 
251  { return ConstTensor3View::operator()(p,r,c); }
252 
253  // Non-const index operators:
254 
255  Tensor3View operator()( const Range& p, const Range& r, const Range& c );
256 
257  MatrixView operator()( const Range& p, const Range& r, Index c );
258  MatrixView operator()( const Range& p, Index r, const Range& c );
259  MatrixView operator()( Index p, const Range& r, const Range& c );
260 
261  VectorView operator()( Index p, Index r, const Range& c );
262  VectorView operator()( Index p, const Range& r, Index c );
263  VectorView operator()( const Range& p, Index r, Index c );
264 
267  {
268  // Check if indices are valid:
269  assert( 0<=p );
270  assert( 0<=r );
271  assert( 0<=c );
272  assert( p<mpr.mextent );
273  assert( r<mrr.mextent );
274  assert( c<mcr.mextent );
275 
276  return *( mdata +
277  mpr.mstart + p*mpr.mstride +
278  mrr.mstart + r*mrr.mstride +
279  mcr.mstart + c*mcr.mstride );
280  }
281 
282  // Conversion to a plain C-array
283  const Numeric *get_c_array() const;
284  Numeric *get_c_array();
285 
286  // Functions returning const iterators:
287  ConstIterator3D begin() const;
288  ConstIterator3D end() const;
289  // Functions returning iterators:
290  Iterator3D begin();
291  Iterator3D end();
292 
293  // Assignment operators:
295  Tensor3View& operator=(const Tensor3View& v);
296  Tensor3View& operator=(const Tensor3& v);
298 
299  // Other operators:
304 
309 
311  virtual ~Tensor3View() {}
312 
313  // Friends:
314  friend class Iterator4D;
315  friend class Tensor4View;
316  friend class Tensor5View;
317  friend class Tensor6View;
318  friend class Tensor7View;
319 
320  // Special constructor to make a Tensor3 view of a matrix.
321  Tensor3View(const MatrixView& a);
322 
323 protected:
324  // Constructors:
325  Tensor3View();
326  Tensor3View(Numeric *data, const Range& p, const Range& r, const Range& c);
327  Tensor3View(Numeric *data,
328  const Range& pp, const Range& pr, const Range& pc,
329  const Range& np, const Range& nr, const Range& nc);
330 };
331 
340 class Tensor3 : public Tensor3View {
341 public:
342  // Constructors:
343  Tensor3();
344  Tensor3(Index p, Index r, Index c);
345  Tensor3(Index p, Index r, Index c, Numeric fill);
346  Tensor3(const ConstTensor3View& v);
347  Tensor3(const Tensor3& v);
348 
349  // Assignment operators:
350  Tensor3& operator=(const Tensor3& x);
352 
353  // Resize function:
354  void resize(Index p, Index r, Index c);
355 
356  // Destructor:
357  virtual ~Tensor3();
358 };
359 
360 
361 // Function declarations:
362 // ----------------------
363 
364 void copy(ConstIterator3D origin,
365  const ConstIterator3D& end,
366  Iterator3D target);
367 
368 void copy(Numeric x,
369  Iterator3D target,
370  const Iterator3D& end);
371 
372 void transform( Tensor3View y,
373  double (&my_func)(double),
374  ConstTensor3View x );
375 
376 Numeric max(const ConstTensor3View& x);
377 
378 Numeric min(const ConstTensor3View& x);
379 
380 ostream& operator<<(ostream& os, const ConstTensor3View& v);
381 
383 // Helper function for debugging
384 #ifndef NDEBUG
385 
387  Index p, Index r, Index c);
388 
389 #endif
390 
392 #endif // matpackIII_h
Iterator3D::operator!=
bool operator!=(const Iterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:54
copy
void copy(ConstIterator3D origin, const ConstIterator3D &end, Iterator3D target)
Copy data between begin and end to target.
Definition: matpackIII.cc:725
Tensor3View::Tensor3View
Tensor3View()
Default constructor.
Definition: matpackIII.cc:675
Tensor7View
The Tensor7View class.
Definition: matpackVII.h:779
Tensor3View::end
ConstIterator3D end() const
Return const iterator behind last row.
Definition: matpackIII.cc:470
MatrixView
The MatrixView class.
Definition: matpackI.h:668
transform
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:915
Tensor3View::operator()
Numeric & operator()(Index p, Index r, Index c)
Plain non-const index operator.
Definition: matpackIII.h:266
ConstTensor3View::operator()
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.cc:34
operator<<
ostream & operator<<(ostream &os, const ConstTensor3View &v)
Output operator.
Definition: matpackIII.cc:218
ConstIterator3D::mstride
Index mstride
Stride.
Definition: matpackIII.h:127
Tensor3
The Tensor3 class.
Definition: matpackIII.h:340
Iterator3D::Iterator3D
Iterator3D()
Default constructor.
Definition: matpackIII.h:38
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:169
ConstIterator3D
Const version of Iterator3D.
Definition: matpackIII.h:82
ConstMatrixView::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:656
ConstTensor3View::ConstTensor3View
ConstTensor3View()
Default constructor.
Definition: matpackIII.cc:171
Tensor3View::operator()
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.cc:247
Tensor3::~Tensor3
virtual ~Tensor3()
Destructor for Tensor3.
Definition: matpackIII.cc:892
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:204
ConstIterator3D::ConstIterator3D
ConstIterator3D(const ConstIterator3D &o)
Copy constructor.
Definition: matpackIII.h:89
ConstMatrixView::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackI.h:654
ConstIterator3D::operator*
const ConstMatrixView & operator*() const
Dereferencing.
Definition: matpackIII.h:120
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:863
Tensor3View::operator-=
Tensor3View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackIII.cc:589
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:151
ConstMatrixView::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackI.h:652
min
Numeric min(const ConstTensor3View &x)
Min function, tensor version.
Definition: matpackIII.cc:958
ConstIterator4D
Const version of Iterator4D.
Definition: matpackIV.h:84
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:149
matpackI.h
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:234
Iterator3D
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:34
Iterator3D::operator*
MatrixView & operator*()
Dereferencing.
Definition: matpackIII.h:72
ConstTensor3View::begin
ConstIterator3D begin() const
Return const iterator to first page.
Definition: matpackIII.cc:141
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
debug_tensor3view_get_elem
Numeric debug_tensor3view_get_elem(Tensor3View &tv, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackIII.cc:998
VectorView
The VectorView class.
Definition: matpackI.h:373
Iterator3D::operator++
Iterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:50
Iterator3D::Iterator3D
Iterator3D(const MatrixView &x, Index stride)
Explicit constructor.
Definition: matpackIII.h:45
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
ConstTensor3View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIII.h:222
Tensor3View::operator/=
Tensor3View & operator/=(Numeric x)
Division by scalar.
Definition: matpackIII.cc:567
Iterator3D::msv
MatrixView msv
Current position.
Definition: matpackIII.h:76
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:154
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:591
Tensor3View::operator*=
Tensor3View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackIII.cc:556
Iterator3D::mstride
Index mstride
Stride.
Definition: matpackIII.h:78
Tensor3View::operator()
Numeric operator()(Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIII.h:250
ConstTensor3View::end
ConstIterator3D end() const
Return const iterator behind last page.
Definition: matpackIII.cc:150
max
Numeric max(const ConstTensor3View &x)
Max function, tensor version.
Definition: matpackIII.cc:936
Range
The range class.
Definition: matpackI.h:148
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:207
ConstIterator3D::msv
ConstMatrixView msv
Current position.
Definition: matpackIII.h:125
Iterator4D
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
Tensor3View::~Tensor3View
virtual ~Tensor3View()
Destructor.
Definition: matpackIII.h:311
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:157
Tensor3View::begin
ConstIterator3D begin() const
Return const iterator to first row.
Definition: matpackIII.cc:464
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:147
Tensor4View
The Tensor4View class.
Definition: matpackIV.h:245
ConstIterator3D::operator++
ConstIterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:99
Tensor3::operator=
Tensor3 & operator=(const Tensor3 &x)
Assignment operator from another tensor.
Definition: matpackIII.cc:842
ConstIterator3D::ConstIterator3D
ConstIterator3D()
Default constructor.
Definition: matpackIII.h:86
Tensor3View::operator+=
Tensor3View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackIII.cc:578
Iterator3D::Iterator3D
Iterator3D(const Iterator3D &o)
Copy constructor.
Definition: matpackIII.h:41
ConstTensor3View::~ConstTensor3View
virtual ~ConstTensor3View()
Destructor.
Definition: matpackIII.h:191
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ConstIterator3D::operator!=
bool operator!=(const ConstIterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:102
Tensor3View::operator=
Tensor3View & operator=(const ConstTensor3View &v)
Assignment operator.
Definition: matpackIII.cc:498
ConstIterator3D::operator->
const ConstMatrixView * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:117
Tensor3View::get_c_array
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIII.cc:452
ConstIterator3D::ConstIterator3D
ConstIterator3D(const ConstMatrixView &x, Index stride)
Explicit constructor.
Definition: matpackIII.h:93
Iterator3D::operator->
MatrixView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:69
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:209
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
Tensor3::Tensor3
Tensor3()
Default constructor.
Definition: matpackIII.cc:757
ConstTensor3View::operator()
Numeric operator()(Index p, Index r, Index c) const
Plain const index operator.
Definition: matpackIII.h:171
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:160
Tensor6View
The Tensor6View class.
Definition: matpackVI.h:450