00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00031 #ifndef matpackIV_h
00032 #define matpackIV_h
00033
00034 #include "matpackIII.h"
00035
00038 class Iterator4D {
00039 public:
00040
00042 Iterator4D() : msv(), mstride(0) { }
00043
00045 Iterator4D(const Iterator4D& o) : msv(o.msv), mstride(o.mstride)
00046 { }
00047
00049 Iterator4D(const Tensor3View& x, Index stride)
00050 : msv(x), mstride(stride)
00051 { }
00052
00053
00055 Iterator4D& operator++() { msv.mdata += mstride; return *this; }
00056
00058 bool operator!=(const Iterator4D& other) const
00059 { if ( msv.mdata +
00060 msv.mpr.mstart +
00061 msv.mrr.mstart +
00062 msv.mcr.mstart
00063 !=
00064 other.msv.mdata +
00065 other.msv.mpr.mstart +
00066 other.msv.mrr.mstart +
00067 other.msv.mcr.mstart )
00068 return true;
00069 else
00070 return false;
00071 }
00072
00073 Tensor3View* operator->();
00074 Tensor3View& operator*();
00075
00076 private:
00078 Tensor3View msv;
00080 Index mstride;
00081 };
00082
00084 class ConstIterator4D {
00085 public:
00086
00087
00088
00089
00091 ConstIterator4D() : msv(), mstride(0) { }
00092
00094 ConstIterator4D(const ConstIterator4D& o) : msv(o.msv), mstride(o.mstride)
00095 { }
00096
00098 ConstIterator4D(const ConstTensor3View& x, Index stride)
00099 : msv(x), mstride(stride)
00100 { }
00101
00102
00104 ConstIterator4D& operator++() { msv.mdata += mstride; return *this; }
00105
00107 bool operator!=(const ConstIterator4D& other) const
00108 { if ( msv.mdata +
00109 msv.mpr.mstart +
00110 msv.mrr.mstart +
00111 msv.mcr.mstart
00112 !=
00113 other.msv.mdata +
00114 other.msv.mpr.mstart +
00115 other.msv.mrr.mstart +
00116 other.msv.mcr.mstart )
00117 return true;
00118 else
00119 return false;
00120 }
00121
00122 const ConstTensor3View* operator->() const;
00123 const ConstTensor3View& operator*() const;
00124
00125 private:
00127 ConstTensor3View msv;
00129 Index mstride;
00130 };
00131
00132
00133
00134 class Tensor4;
00135
00136
00149 class ConstTensor4View {
00150 public:
00151
00152 Index nbooks() const;
00153 Index npages() const;
00154 Index nrows() const;
00155 Index ncols() const;
00156
00157
00158 ConstTensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c ) const;
00159
00160 ConstTensor3View operator()( const Range& b, const Range& p, const Range& r, Index c ) const;
00161 ConstTensor3View operator()( const Range& b, const Range& p, Index r, const Range& c ) const;
00162 ConstTensor3View operator()( const Range& b, Index p, const Range& r, const Range& c ) const;
00163 ConstTensor3View operator()( Index b, const Range& p, const Range& r, const Range& c ) const;
00164
00165 ConstMatrixView operator()( const Range& b, const Range& p, Index r, Index c ) const;
00166 ConstMatrixView operator()( const Range& b, Index p, const Range& r, Index c ) const;
00167 ConstMatrixView operator()( const Range& b, Index p, Index r, const Range& c ) const;
00168 ConstMatrixView operator()( Index b, const Range& p, Index r, const Range& c ) const;
00169 ConstMatrixView operator()( Index b, const Range& p, const Range& r, Index c ) const;
00170 ConstMatrixView operator()( Index b, Index p, const Range& r, const Range& c ) const;
00171
00172 ConstVectorView operator()( const Range& b, Index p, Index r, Index c ) const;
00173 ConstVectorView operator()( Index b, const Range& p, Index r, Index c ) const;
00174 ConstVectorView operator()( Index b, Index p, const Range& r, Index c ) const;
00175 ConstVectorView operator()( Index b, Index p, Index r, const Range& c ) const;
00176
00178 Numeric operator()(Index b, Index p, Index r, Index c) const
00179 {
00180 assert( 0 <= b );
00181 assert( 0 <= p );
00182 assert( 0 <= r );
00183 assert( 0 <= c );
00184 assert( b < mbr.mextent );
00185 assert( p < mpr.mextent );
00186 assert( r < mrr.mextent );
00187 assert( c < mcr.mextent );
00188
00189 return *( mdata +
00190 mbr.mstart + b * mbr.mstride +
00191 mpr.mstart + p * mpr.mstride +
00192 mrr.mstart + r * mrr.mstride +
00193 mcr.mstart + c * mcr.mstride );
00194 }
00195
00196
00197 ConstIterator4D begin() const;
00198 ConstIterator4D end() const;
00199
00201 virtual ~ConstTensor4View() {};
00202
00203
00204 friend class Tensor4View;
00205 friend class ConstIterator5D;
00206 friend class ConstTensor5View;
00207 friend class ConstTensor6View;
00208 friend class ConstTensor7View;
00209
00210
00211 ConstTensor4View(const ConstTensor3View& a);
00212
00213 protected:
00214
00215 ConstTensor4View();
00216 ConstTensor4View(Numeric *data,
00217 const Range& b, const Range& p, const Range& r, const Range& c);
00218 ConstTensor4View(Numeric *data,
00219 const Range& pb, const Range& pp, const Range& pr, const Range& pc,
00220 const Range& nb, const Range& np, const Range& nr, const Range& nc);
00221
00222
00223
00225 Range mbr;
00227 Range mpr;
00229 Range mrr;
00231 Range mcr;
00233 Numeric *mdata;
00234 };
00235
00245 class Tensor4View : public ConstTensor4View {
00246 public:
00247
00248
00249 ConstTensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c ) const;
00250
00251 ConstTensor3View operator()( const Range& b, const Range& p, const Range& r, Index c ) const;
00252 ConstTensor3View operator()( const Range& b, const Range& p, Index r, const Range& c ) const;
00253 ConstTensor3View operator()( const Range& b, Index p, const Range& r, const Range& c ) const;
00254 ConstTensor3View operator()( Index b, const Range& p, const Range& r, const Range& c ) const;
00255
00256 ConstMatrixView operator()( const Range& b, const Range& p, Index r, Index c ) const;
00257 ConstMatrixView operator()( const Range& b, Index p, const Range& r, Index c ) const;
00258 ConstMatrixView operator()( const Range& b, Index p, Index r, const Range& c ) const;
00259 ConstMatrixView operator()( Index b, const Range& p, Index r, const Range& c ) const;
00260 ConstMatrixView operator()( Index b, const Range& p, const Range& r, Index c ) const;
00261 ConstMatrixView operator()( Index b, Index p, const Range& r, const Range& c ) const;
00262
00263 ConstVectorView operator()( const Range& b, Index p, Index r, Index c ) const;
00264 ConstVectorView operator()( Index b, const Range& p, Index r, Index c ) const;
00265 ConstVectorView operator()( Index b, Index p, const Range& r, Index c ) const;
00266 ConstVectorView operator()( Index b, Index p, Index r, const Range& c ) const;
00267
00270 Numeric operator()(Index b, Index p, Index r, Index c) const
00271 { return ConstTensor4View::operator()(b,p,r,c); }
00272
00273
00274
00275 Tensor4View operator()( const Range& b, const Range& p, const Range& r, const Range& c );
00276
00277 Tensor3View operator()( const Range& b, const Range& p, const Range& r, Index c );
00278 Tensor3View operator()( const Range& b, const Range& p, Index r, const Range& c );
00279 Tensor3View operator()( const Range& b, Index p, const Range& r, const Range& c );
00280 Tensor3View operator()( Index b, const Range& p, const Range& r, const Range& c );
00281
00282 MatrixView operator()( const Range& b, const Range& p, Index r, Index c );
00283 MatrixView operator()( const Range& b, Index p, const Range& r, Index c );
00284 MatrixView operator()( const Range& b, Index p, Index r, const Range& c );
00285 MatrixView operator()( Index b, const Range& p, Index r, const Range& c );
00286 MatrixView operator()( Index b, const Range& p, const Range& r, Index c );
00287 MatrixView operator()( Index b, Index p, const Range& r, const Range& c );
00288
00289 VectorView operator()( const Range& b, Index p, Index r, Index c );
00290 VectorView operator()( Index b, const Range& p, Index r, Index c );
00291 VectorView operator()( Index b, Index p, const Range& r, Index c );
00292 VectorView operator()( Index b, Index p, Index r, const Range& c );
00293
00295 Numeric& operator()(Index b, Index p, Index r, Index c)
00296 {
00297 assert( 0 <= b );
00298 assert( 0 <= p );
00299 assert( 0 <= r );
00300 assert( 0 <= c );
00301 assert( b < mbr.mextent );
00302 assert( p < mpr.mextent );
00303 assert( r < mrr.mextent );
00304 assert( c < mcr.mextent );
00305
00306 return *( mdata +
00307 mbr.mstart + b * mbr.mstride +
00308 mpr.mstart + p * mpr.mstride +
00309 mrr.mstart + r * mrr.mstride +
00310 mcr.mstart + c * mcr.mstride );
00311 }
00312
00313
00314 const Numeric *get_c_array() const;
00315 Numeric *get_c_array();
00316
00317
00318 ConstIterator4D begin() const;
00319 ConstIterator4D end() const;
00320
00321 Iterator4D begin();
00322 Iterator4D end();
00323
00324
00325 Tensor4View& operator=(const ConstTensor4View& v);
00326 Tensor4View& operator=(const Tensor4View& v);
00327 Tensor4View& operator=(const Tensor4& v);
00328 Tensor4View& operator=(Numeric x);
00329
00330
00331 Tensor4View& operator*=(Numeric x);
00332 Tensor4View& operator/=(Numeric x);
00333 Tensor4View& operator+=(Numeric x);
00334 Tensor4View& operator-=(Numeric x);
00335
00336 Tensor4View& operator*=(const ConstTensor4View& x);
00337 Tensor4View& operator/=(const ConstTensor4View& x);
00338 Tensor4View& operator+=(const ConstTensor4View& x);
00339 Tensor4View& operator-=(const ConstTensor4View& x);
00340
00342 virtual ~Tensor4View() {};
00343
00344
00345
00346
00347
00348 friend class Iterator5D;
00349 friend class Tensor5View;
00350 friend class Tensor6View;
00351 friend class Tensor7View;
00352
00353
00354 Tensor4View(const Tensor3View& a);
00355
00356 protected:
00357
00358 Tensor4View();
00359 Tensor4View(Numeric *data,
00360 const Range& b, const Range& p, const Range& r, const Range& c);
00361 Tensor4View(Numeric *data,
00362 const Range& pb, const Range& pp, const Range& pr, const Range& pc,
00363 const Range& nb, const Range& np, const Range& nr, const Range& nc);
00364 };
00365
00366
00375 class Tensor4 : public Tensor4View {
00376 public:
00377
00378 Tensor4();
00379 Tensor4(Index b, Index p, Index r, Index c);
00380 Tensor4(Index b, Index p, Index r, Index c, Numeric fill);
00381 Tensor4(const ConstTensor4View& v);
00382 Tensor4(const Tensor4& v);
00383
00384
00385 Tensor4& operator=(const Tensor4& x);
00386 Tensor4& operator=(Numeric x);
00387
00388
00389 void resize(Index b, Index p, Index r, Index c);
00390
00391
00392 virtual ~Tensor4();
00393 };
00394
00395
00396
00397
00398
00399 void copy(ConstIterator4D origin,
00400 const ConstIterator4D& end,
00401 Iterator4D target);
00402
00403 void copy(Numeric x,
00404 Iterator4D target,
00405 const Iterator4D& end);
00406
00407 void transform( Tensor4View y,
00408 double (&my_func)(double),
00409 ConstTensor4View x );
00410
00411 Numeric max(const ConstTensor4View& x);
00412
00413 Numeric min(const ConstTensor4View& x);
00414
00415 ostream& operator<<(ostream& os, const ConstTensor4View& v);
00416
00418
00419 #ifndef NDEBUG
00420
00421 Numeric debug_tensor4view_get_elem (Tensor4View& tv,
00422 Index b, Index p, Index r, Index c);
00423
00424 #endif
00426
00427 #endif // matpackIV_h