00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00027 #ifndef matpackIII_h
00028 #define matpackIII_h
00029
00030 #include "matpackI.h"
00031
00034 class Iterator3D {
00035 public:
00036
00038 Iterator3D() : msv(), mstride(0) { }
00039
00041 Iterator3D(const Iterator3D& o) : msv(o.msv), mstride(o.mstride)
00042 { }
00043
00045 Iterator3D(const MatrixView& x, Index stride) : msv(x), mstride(stride)
00046 { }
00047
00048
00050 Iterator3D& operator++()
00051 { msv.mdata += mstride; return *this; }
00052
00054 bool operator!=(const Iterator3D& other) const
00055 { if ( msv.mdata +
00056 msv.mrr.mstart +
00057 msv.mcr.mstart
00058 !=
00059 other.msv.mdata +
00060 other.msv.mrr.mstart +
00061 other.msv.mcr.mstart )
00062 return true;
00063 else
00064 return false;
00065 }
00066
00069 MatrixView* operator->() { return &msv; }
00070
00072 MatrixView& operator*() { return msv; }
00073
00074 private:
00076 MatrixView msv;
00078 Index mstride;
00079 };
00080
00082 class ConstIterator3D {
00083 public:
00084
00086 ConstIterator3D() : msv(), mstride(0) { }
00087
00089 ConstIterator3D(const ConstIterator3D& o) : msv(o.msv), mstride(o.mstride)
00090 { }
00091
00093 ConstIterator3D(const ConstMatrixView& x, Index stride)
00094 : msv(x), mstride(stride)
00095 { }
00096
00097
00099 ConstIterator3D& operator++() { msv.mdata += mstride; return *this; }
00100
00102 bool operator!=(const ConstIterator3D& other) const
00103 { if ( msv.mdata +
00104 msv.mrr.mstart +
00105 msv.mcr.mstart
00106 !=
00107 other.msv.mdata +
00108 other.msv.mrr.mstart +
00109 other.msv.mcr.mstart )
00110 return true;
00111 else
00112 return false;
00113 }
00114
00117 const ConstMatrixView* operator->() const { return &msv; }
00118
00120 const ConstMatrixView& operator*() const { return msv; }
00121
00122
00123 private:
00125 ConstMatrixView msv;
00127 Index mstride;
00128 };
00129
00130
00131
00132 class Tensor3;
00133
00134
00147 class ConstTensor3View {
00148 public:
00149
00151 Index npages() const { return mpr.mextent; }
00152
00154 Index nrows() const { return mrr.mextent; }
00155
00157 Index ncols() const { return mcr.mextent; }
00158
00159
00160 ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
00161
00162 ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
00163 ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
00164 ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
00165
00166 ConstVectorView operator()( Index p, Index r, const Range& c ) const;
00167 ConstVectorView operator()( Index p, const Range& r, Index c ) const;
00168 ConstVectorView operator()( const Range& p, Index r, Index c ) const;
00169
00171 Numeric operator()(Index p, Index r, Index c) const
00172 {
00173 assert( 0<=p );
00174 assert( 0<=r );
00175 assert( 0<=c );
00176 assert( p<mpr.mextent );
00177 assert( r<mrr.mextent );
00178 assert( c<mcr.mextent );
00179
00180 return *( mdata +
00181 mpr.mstart + p*mpr.mstride +
00182 mrr.mstart + r*mrr.mstride +
00183 mcr.mstart + c*mcr.mstride );
00184 }
00185
00186
00187 ConstIterator3D begin() const;
00188 ConstIterator3D end() const;
00189
00191 virtual ~ConstTensor3View() {};
00192
00193
00194 friend class Tensor3View;
00195 friend class ConstIterator4D;
00196 friend class ConstTensor4View;
00197 friend class ConstTensor5View;
00198 friend class ConstTensor6View;
00199 friend class ConstTensor7View;
00200
00201
00202 ConstTensor3View(const ConstMatrixView& a);
00203
00204 protected:
00205
00206 ConstTensor3View();
00207 ConstTensor3View(Numeric *data,
00208 const Range& p, const Range& r, const Range& c);
00209 ConstTensor3View(Numeric *data,
00210 const Range& pp, const Range& pr, const Range& pc,
00211 const Range& np, const Range& nr, const Range& nc);
00212
00213
00214
00216 Range mpr;
00218 Range mrr;
00220 Range mcr;
00222 Numeric *mdata;
00223 };
00224
00234 class Tensor3View : public ConstTensor3View {
00235 public:
00236
00237
00238 ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
00239
00240 ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
00241 ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
00242 ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
00243
00244 ConstVectorView operator()( Index p, Index r, const Range& c ) const;
00245 ConstVectorView operator()( Index p, const Range& r, Index c ) const;
00246 ConstVectorView operator()( const Range& p, Index r, Index c ) const;
00247
00250 Numeric operator()(Index p, Index r, Index c) const
00251 { return ConstTensor3View::operator()(p,r,c); }
00252
00253
00254
00255 Tensor3View operator()( const Range& p, const Range& r, const Range& c );
00256
00257 MatrixView operator()( const Range& p, const Range& r, Index c );
00258 MatrixView operator()( const Range& p, Index r, const Range& c );
00259 MatrixView operator()( Index p, const Range& r, const Range& c );
00260
00261 VectorView operator()( Index p, Index r, const Range& c );
00262 VectorView operator()( Index p, const Range& r, Index c );
00263 VectorView operator()( const Range& p, Index r, Index c );
00264
00266 Numeric& operator()( Index p, Index r, Index c)
00267 {
00268
00269 assert( 0<=p );
00270 assert( 0<=r );
00271 assert( 0<=c );
00272 assert( p<mpr.mextent );
00273 assert( r<mrr.mextent );
00274 assert( c<mcr.mextent );
00275
00276 return *( mdata +
00277 mpr.mstart + p*mpr.mstride +
00278 mrr.mstart + r*mrr.mstride +
00279 mcr.mstart + c*mcr.mstride );
00280 }
00281
00282
00283 const Numeric *get_c_array() const;
00284 Numeric *get_c_array();
00285
00286
00287 ConstIterator3D begin() const;
00288 ConstIterator3D end() const;
00289
00290 Iterator3D begin();
00291 Iterator3D end();
00292
00293
00294 Tensor3View& operator=(const ConstTensor3View& v);
00295 Tensor3View& operator=(const Tensor3View& v);
00296 Tensor3View& operator=(const Tensor3& v);
00297 Tensor3View& operator=(Numeric x);
00298
00299
00300 Tensor3View& operator*=(Numeric x);
00301 Tensor3View& operator/=(Numeric x);
00302 Tensor3View& operator+=(Numeric x);
00303 Tensor3View& operator-=(Numeric x);
00304
00305 Tensor3View& operator*=(const ConstTensor3View& x);
00306 Tensor3View& operator/=(const ConstTensor3View& x);
00307 Tensor3View& operator+=(const ConstTensor3View& x);
00308 Tensor3View& operator-=(const ConstTensor3View& x);
00309
00311 virtual ~Tensor3View() {};
00312
00313
00314 friend class Iterator4D;
00315 friend class Tensor4View;
00316 friend class Tensor5View;
00317 friend class Tensor6View;
00318 friend class Tensor7View;
00319
00320
00321 Tensor3View(const MatrixView& a);
00322
00323 protected:
00324
00325 Tensor3View();
00326 Tensor3View(Numeric *data, const Range& p, const Range& r, const Range& c);
00327 Tensor3View(Numeric *data,
00328 const Range& pp, const Range& pr, const Range& pc,
00329 const Range& np, const Range& nr, const Range& nc);
00330 };
00331
00340 class Tensor3 : public Tensor3View {
00341 public:
00342
00343 Tensor3();
00344 Tensor3(Index p, Index r, Index c);
00345 Tensor3(Index p, Index r, Index c, Numeric fill);
00346 Tensor3(const ConstTensor3View& v);
00347 Tensor3(const Tensor3& v);
00348
00349
00350 Tensor3& operator=(const Tensor3& x);
00351 Tensor3& operator=(Numeric x);
00352
00353
00354 void resize(Index p, Index r, Index c);
00355
00356
00357 virtual ~Tensor3();
00358 };
00359
00360
00361
00362
00363
00364 void copy(ConstIterator3D origin,
00365 const ConstIterator3D& end,
00366 Iterator3D target);
00367
00368 void copy(Numeric x,
00369 Iterator3D target,
00370 const Iterator3D& end);
00371
00372 void transform( Tensor3View y,
00373 double (&my_func)(double),
00374 ConstTensor3View x );
00375
00376 Numeric max(const ConstTensor3View& x);
00377
00378 Numeric min(const ConstTensor3View& x);
00379
00380 ostream& operator<<(ostream& os, const ConstTensor3View& v);
00381
00383
00384 #ifndef NDEBUG
00385
00386 Numeric debug_tensor3view_get_elem (Tensor3View& tv,
00387 Index p, Index r, Index c);
00388
00389 #endif
00391
00392 #endif // matpackIII_h