Changeset 787 in Sophya for trunk/SophyaLib/TArray
- Timestamp:
- Mar 20, 2000, 7:22:49 PM (26 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/fioarr.cc
r785 r787 70 70 // On lit les tailles, etc ... 71 71 is.Get(dobj->ndim_); 72 is.Get(dobj->size_, TARRAY_MAXNDIMS);72 is.Get(dobj->size_, BASEARRAY_MAXNDIMS); 73 73 is.Get(dobj->totsize_); 74 is.Get(dobj->step_, TARRAY_MAXNDIMS);74 is.Get(dobj->step_, BASEARRAY_MAXNDIMS); 75 75 is.Get(dobj->minstep_); 76 76 is.Get(dobj->moystep_); … … 98 98 // On ecrit les tailles, etc ... 99 99 os.Put(dobj->ndim_); 100 os.Put(dobj->size_, TARRAY_MAXNDIMS);100 os.Put(dobj->size_, BASEARRAY_MAXNDIMS); 101 101 os.Put(dobj->totsize_); 102 os.Put(dobj->step_, TARRAY_MAXNDIMS);102 os.Put(dobj->step_, BASEARRAY_MAXNDIMS); 103 103 os.Put(dobj->minstep_); 104 104 os.Put(dobj->moystep_); -
trunk/SophyaLib/TArray/tarray.cc
r785 r787 10 10 11 11 12 // Variables statiques globales13 template <class T>14 char * TArray<T>::ck_op_msg_[6] = {"???", "Size(int )", "IsPacked(int )",15 "Stride(int )", "ElemCheckBound()", "operator()" };16 template <class T>17 uint_4 TArray<T>::max_nprt_ = 50;18 19 // Methodes statiques globales20 template <class T>21 void TArray<T>::SetMaxPrint(uint_4 nprt)22 {23 max_nprt_ = nprt;24 }25 26 27 template <class T>28 uint_8 TArray<T>::ComputeTotalSize(uint_4 ndim, uint_4 * siz, uint_4 step, uint_8 offset)29 {30 uint_8 rs = step;31 for(int k=0; k<ndim; k++) rs *= siz[k];32 return(rs+offset);33 }34 12 35 13 // ------------------------------------------------------- … … 40 18 template <class T> 41 19 TArray<T>::TArray() 42 : mNDBlock() , mInfo(NULL)20 : mNDBlock() , BaseArray() 43 21 // Default constructor 44 22 { 45 ndim_ = 0;46 for(int k=0; k<TARRAY_MAXNDIMS; k++) step_[k] = size_[k] = 0;47 totsize_ = 0;48 minstep_ = 0;49 moystep_ = 0;50 offset_ = 0;51 // Default for matrices : Lines = Y , Columns = X52 macoli_ = 0;53 marowi_ = 1;54 23 } 55 24 56 25 template <class T> 57 26 TArray<T>::TArray(uint_4 ndim, uint_4 * siz, uint_4 step) 58 : mNDBlock(ComputeTotalSize(ndim, siz, step, 1)) , mInfo(NULL)27 : mNDBlock(ComputeTotalSize(ndim, siz, step, 1)) , BaseArray() 59 28 { 60 29 string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, uint_4)"; … … 64 33 template <class T> 65 34 TArray<T>::TArray(uint_4 nx, uint_4 ny=1, uint_4 nz=1) 66 : mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)) , mInfo(NULL)67 { 68 uint_4 size[ TARRAY_MAXNDIMS];35 : mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)) , BaseArray() 36 { 37 uint_4 size[BASEARRAY_MAXNDIMS]; 69 38 size[0] = nx; size[1] = ny; size[2] = nz; 70 39 int ndim = 1; … … 78 47 template <class T> 79 48 TArray<T>::TArray(uint_4 ndim, uint_4 * siz, NDataBlock<T> & db, bool share, uint_4 step, uint_8 offset) 80 : mNDBlock(db, share) , mInfo(NULL)49 : mNDBlock(db, share) , BaseArray() 81 50 { 82 51 string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, NDataBlock<T> & ... )"; … … 87 56 template <class T> 88 57 TArray<T>::TArray(uint_4 ndim, uint_4 * siz, T* values, uint_4 step, uint_8 offset, Bridge* br) 89 : mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br) , mInfo(NULL)58 : mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br) , BaseArray() 90 59 { 91 60 string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, T* ... )"; … … 95 64 template <class T> 96 65 TArray<T>::TArray(const TArray<T>& a) 97 : mNDBlock(a.mNDBlock) , mInfo(NULL)66 : mNDBlock(a.mNDBlock) , BaseArray() 98 67 { 99 68 string exmsg = "TArray<T>::TArray(const TArray<T>&)"; … … 104 73 template <class T> 105 74 TArray<T>::TArray(const TArray<T>& a, bool share) 106 : mNDBlock(a.mNDBlock, share) , mInfo(NULL)75 : mNDBlock(a.mNDBlock, share) , BaseArray() 107 76 { 108 77 string exmsg = "TArray<T>::TArray(const TArray<T>&, bool)"; … … 154 123 } 155 124 156 template <class T> 157 bool TArray<T>::CompareSizes(const TArray<T>& a) 158 { 159 if (ndim_ != a.ndim_) return(false); 160 for(int k=0; k<ndim_; k++) 161 if (size_[k] != a.size_[k]) return(false); 162 if ( (macoli_ != a.macoli_) || (marowi_ != a.marowi_) ) return(false); 163 return(true); 164 } 165 166 template <class T> 167 TArray<T>& TArray<T>::CompactDim() 168 { 169 if (ndim_ < 2) return(*this); 125 126 template <class T> 127 TArray<T>& TArray<T>::CompactAllDimensions() 128 { 129 CompactAllDim(); 130 return(*this); 131 } 132 133 template <class T> 134 TArray<T>& TArray<T>::CompactTrailingDimensions() 135 { 136 CompactTrailingDim(); 137 return(*this); 138 } 139 140 template <class T> 141 double TArray<T>::ValueAtPosition(uint_8 ip) const 142 { 143 #ifdef SO_BOUNDCHECKING 144 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 145 #endif 146 return( (double)(*(mNDBlock.Begin()+Offset(ip))) ); 147 } 148 149 // For complex values, we return the module of the complex number 150 double TArray< complex<r_4> >::ValueAtPosition(uint_8 ip) const 151 { 152 #ifdef SO_BOUNDCHECKING 153 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 154 #endif 155 complex<r_4> c = *(mNDBlock.Begin()+Offset(ip)); 156 double cr = (double)(c.real()); 157 double ci = (double)(c.imag()); 158 return( sqrt(cr*cr+ci*ci) ); 159 } 160 161 double TArray< complex<r_8> >::ValueAtPosition(uint_8 ip) const 162 { 163 #ifdef SO_BOUNDCHECKING 164 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 165 #endif 166 complex<r_8> c = *(mNDBlock.Begin()+Offset(ip)); 167 double cr = (double)(c.real()); 168 double ci = (double)(c.imag()); 169 return( sqrt(cr*cr+ci*ci) ); 170 } 171 172 173 // SubArrays 174 template <class T> 175 TArray<T> TArray<T>::operator () (Range rx, Range ry, Range rz, Range rt, Range ru) 176 { 170 177 uint_4 ndim = 0; 171 uint_4 size[TARRAY_MAXNDIMS]; 172 uint_4 step[TARRAY_MAXNDIMS]; 173 for(int k=0; k<ndim_; k++) { 174 if (size_[k] < 2) continue; 175 size[ndim] = size_[k]; 176 step[ndim] = step_[k]; 177 ndim++; 178 } 179 if (ndim == 0) { 180 size[0] = size_[0]; 181 step[0] = step_[0]; 182 ndim = 1; 183 } 184 string exmsg = "TArray<T>::CompactDim() "; 185 if (!UpdateSizes(ndim, size, step, offset_, exmsg)) throw( ParmError(exmsg) ); 186 return(*this); 187 } 188 189 190 template <class T> 191 uint_4 TArray<T>::MinStepKA() const 192 { 193 for(int ka=0; ka<ndim_; ka++) 194 if (step_[ka] == minstep_) return(ka); 195 return(0); 196 } 197 198 template <class T> 199 uint_4 TArray<T>::MaxSizeKA() const 200 { 201 uint_4 ka = 0; 202 uint_4 mx = size_[0]; 203 for(int k=0; k<ndim_; k++) 204 if (size_[k] > mx) { ka = k; mx = size_[k]; } 205 return(ka); 206 } 207 208 209 // Acces lineaire aux elements .... Calcul d'offset 210 211 template <class T> 212 uint_8 TArray<T>::Offset(uint_8 ip) const 213 { 214 if (ip == 0) return(offset_); 215 uint_4 idx[TARRAY_MAXNDIMS]; 216 int k; 217 uint_8 rest = ip; 218 for(k=0; k<ndim_; k++) { idx[k] = rest%size_[k]; rest /= size_[k]; } 219 uint_8 off = offset_; 220 for(k=0; k<ndim_; k++) off += idx[k]*step_[k]; 221 return (off); 222 } 223 224 // SubArrays 225 template <class T> 226 TArray<T> TArray<T>::operator () (Range rx, Range ry, Range rz, Range rt, Range ru) 227 { 228 uint_4 ndim = 0; 229 uint_4 size[TARRAY_MAXNDIMS]; 230 uint_4 step[TARRAY_MAXNDIMS]; 231 uint_4 pos[TARRAY_MAXNDIMS]; 178 uint_4 size[BASEARRAY_MAXNDIMS]; 179 uint_4 step[BASEARRAY_MAXNDIMS]; 180 uint_4 pos[BASEARRAY_MAXNDIMS]; 232 181 size[0] = rx.Size(); 233 182 size[1] = ry.Size(); … … 251 200 TArray<T> ra; 252 201 SubArray(ra, ndim, size, pos, step); 202 ra.DataBlock().Share(this->DataBlock()); 253 203 ra.SetTemp(true); 254 204 return(ra); … … 523 473 524 474 // ---------------------------------------------------- 525 // Application d'une fonction526 // ----------------------------------------------------527 template <class T>528 TArray<T>& TArray<T>::ApplyFunction(Arr_DoubleFunctionOfX f)529 {530 T * pe;531 uint_8 j,k;532 if (AvgStep() > 0) { // regularly spaced elements533 uint_8 step = AvgStep();534 uint_8 maxx = totsize_*step;535 pe = Data();536 for(k=0; k<maxx; k+=step ) pe[k] = (T)(f((double)pe[k]));537 }538 else { // Non regular data spacing ...539 uint_4 ka = MaxSizeKA();540 uint_8 step = Step(ka);541 uint_8 gpas = Size(ka)*step;542 for(j=0; j<totsize_; j += Size(ka)) {543 pe = mNDBlock.Begin()+Offset(j);544 for(k=0; k<gpas; k+=step) pe[k] = (T)(f((double)pe[k]));545 }546 }547 return(*this);548 }549 550 template <class T>551 TArray<T>& TArray<T>::ApplyFunction(Arr_FloatFunctionOfX f)552 {553 T * pe;554 uint_8 j,k;555 if (AvgStep() > 0) { // regularly spaced elements556 uint_8 step = AvgStep();557 uint_8 maxx = totsize_*step;558 pe = Data();559 for(k=0; k<maxx; k+=step ) pe[k] = (T)(f((float)pe[k]));560 }561 else { // Non regular data spacing ...562 uint_4 ka = MaxSizeKA();563 uint_8 step = Step(ka);564 uint_8 gpas = Size(ka)*step;565 for(j=0; j<totsize_; j += Size(ka)) {566 pe = mNDBlock.Begin()+Offset(j);567 for(k=0; k<gpas; k+=step) pe[k] = (T)(f((float)pe[k]));568 }569 }570 return(*this);571 }572 573 TArray< complex<r_4> >& TArray< complex<r_4> >::ApplyFunction(Arr_DoubleFunctionOfX f)574 {575 throw( NotAvailableOperation("TArray< complex<r_4> >::ApplyFunction() - Unsupported operation ") );576 }577 578 TArray< complex<r_4> >& TArray< complex<r_4> >::ApplyFunction(Arr_FloatFunctionOfX f)579 {580 throw(NotAvailableOperation( "TArray< complex<r_4> >::ApplyFunction() - Unsupported operation ") );581 }582 583 TArray< complex<r_8> >& TArray< complex<r_8> >::ApplyFunction(Arr_DoubleFunctionOfX f)584 {585 throw(NotAvailableOperation("TArray< complex<r_8> >::ApplyFunction() - Unsupported operation ") );586 }587 588 TArray< complex<r_8> >& TArray< complex<r_8> >::ApplyFunction(Arr_FloatFunctionOfX f)589 {590 throw(NotAvailableOperation("TArray< complex<r_8> >::ApplyFunction() - Unsupported operation ") );591 }592 593 // ----------------------------------------------------594 475 // Impression, etc ... 595 476 // ---------------------------------------------------- 596 477 597 478 template <class T> 598 void TArray<T>::Show(ostream& os, bool si) const 599 { 600 os << " TArray< " << typeid(T).name() << " NDim= " << ndim_ 601 << "(" << typeid(*this).name() << " )" << endl; 602 os << "TotSize=" << totsize_ << " Size(X*Y*...)= " ; 603 for(int k=0; k<ndim_; k++) { 604 os << size_[k]; 605 if (k<ndim_-1) os << " x "; 606 } 607 os << endl; 608 os << " Step(X Y ...)= " ; 609 for(int k=0; k<ndim_; k++) os << step_[k] << " " ; 610 os << " Offset= " << offset_ << "\n " << endl; 611 if (si && (mInfo != NULL)) os << (*mInfo) << endl; 612 479 string TArray<T>::DataType() const 480 { 481 string rs = typeid(T).name(); 482 return(rs); 613 483 } 614 484 … … 643 513 } 644 514 645 template <class T>646 DVList& TArray<T>::Info()647 {648 if (mInfo == NULL) mInfo = new DVList;649 return(*mInfo);650 }651 652 653 template <class T>654 bool TArray<T>::UpdateSizes(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset, string & exmsg)655 {656 if (ndim >= TARRAY_MAXNDIMS) {657 exmsg += " NDim Error"; return false;658 }659 if (step < 1) {660 exmsg += " Step(=0) Error"; return false;661 }662 663 minstep_ = moystep_ = step;664 665 // Flagging bad updates ...666 ndim_ = 0;667 668 totsize_ = 1;669 int k;670 for(k=0; k<TARRAY_MAXNDIMS; k++) {671 size_[k] = 1;672 step_[k] = 0;673 }674 for(k=0; k<ndim; k++) {675 size_[k] = siz[k] ;676 step_[k] = totsize_*step;677 totsize_ *= size_[k];678 }679 if (totsize_ < 1) {680 exmsg += " Size Error"; return false;681 }682 offset_ = offset;683 // Default for matrices : Lines = Y , Columns = X684 macoli_ = 0;685 marowi_ = 1;686 // Update OK687 ndim_ = ndim;688 return true;689 }690 691 template <class T>692 bool TArray<T>::UpdateSizes(uint_4 ndim, const uint_4 * siz, const uint_4 * step, uint_8 offset, string & exmsg)693 {694 if (ndim >= TARRAY_MAXNDIMS) {695 exmsg += " NDim Error"; return false;696 }697 698 // Flagging bad updates ...699 ndim_ = 0;700 701 totsize_ = 1;702 int k;703 for(k=0; k<TARRAY_MAXNDIMS; k++) {704 size_[k] = 1;705 step_[k] = 0;706 }707 uint_4 minstep = step[0];708 for(k=0; k<ndim; k++) {709 size_[k] = siz[k] ;710 step_[k] = step[k];711 totsize_ *= size_[k];712 if (step_[k] < minstep) minstep = step_[k];713 }714 if (minstep < 1) {715 exmsg += " Step(=0) Error"; return false;716 }717 if (totsize_ < 1) {718 exmsg += " Size Error"; return false;719 }720 uint_8 plast = 0;721 for(k=0; k<ndim; k++) plast += (siz[k]-1)*step[k];722 if (plast == minstep*totsize_ ) moystep_ = minstep;723 else moystep_ = 0;724 minstep_ = minstep;725 offset_ = offset;726 // Default for matrices : Lines = Y , Columns = X727 macoli_ = 0;728 marowi_ = 1;729 // Update OK730 ndim_ = ndim;731 return true;732 }733 734 template <class T>735 bool TArray<T>::UpdateSizes(const TArray<T>& a, string & exmsg)736 {737 if (a.ndim_ >= TARRAY_MAXNDIMS) {738 exmsg += " NDim Error"; return false;739 }740 741 // Flagging bad updates ...742 ndim_ = 0;743 744 totsize_ = 1;745 int k;746 for(k=0; k<TARRAY_MAXNDIMS; k++) {747 size_[k] = 1;748 step_[k] = 0;749 }750 uint_4 minstep = a.step_[0];751 for(k=0; k<a.ndim_; k++) {752 size_[k] = a.size_[k] ;753 step_[k] = a.step_[k];754 totsize_ *= size_[k];755 if (step_[k] < minstep) minstep = step_[k];756 }757 if (minstep < 1) {758 exmsg += " Step(=0) Error"; return false;759 }760 if (totsize_ < 1) {761 exmsg += " Size Error"; return false;762 }763 764 minstep_ = a.minstep_;765 moystep_ = a.moystep_;766 offset_ = a.offset_;767 macoli_ = a.macoli_;768 marowi_ = a.marowi_;769 // Update OK770 ndim_ = a.ndim_;771 return true;772 }773 515 774 516 template <class T> … … 789 531 790 532 791 template <class T>792 void TArray<T>::SubArray(TArray<T> & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step)793 {794 if ( (ndim > ndim_) || (ndim < 1) ) throw(SzMismatchError("TArray<T>::SubArray( ... ) NDim Error") );795 int k;796 for(k=0; k<ndim; k++)797 if ( (siz[k]*step[k]+pos[k]) > size_[k] )798 throw(SzMismatchError("TArray<T>::SubArray( ... ) Size/Pos Error") );799 (ra.mNDBlock).Share(mNDBlock);800 uint_8 offset = offset_;801 for(k=0; k<ndim_; k++) {802 offset += pos[k]*step_[k];803 step[k] *= step_[k];804 }805 string exm = "TArray<T>::SubArray() ";806 if (!ra.UpdateSizes(ndim, siz, step, offset, exm))807 throw( ParmError(exm) );808 (ra.mNDBlock).Share(mNDBlock);809 return;810 }811 533 812 534 /////////////////////////////////////////////////////////////// -
trunk/SophyaLib/TArray/tarray.h
r785 r787 9 9 #include <math.h> 10 10 #include <iostream.h> 11 #include "basarr.h" 11 12 #include "ndatablock.h" 12 13 #include <complex> 13 #include "anydataobj.h"14 #include "ndatablock.h"15 #include "dvlist.h"16 14 #include "utilarr.h" 17 15 18 19 // Maximum number of dimensions for array20 #define TARRAY_MAXNDIMS 521 16 22 17 namespace SOPHYA { … … 25 20 template <class T> class FIO_TArray; 26 21 27 // ------------ classe template Array ----------- 28 template <class T> 29 class TArray : public AnyDataObj { 22 // --------------------------- classe template Array ----------------------- 23 // ( See BaseArray class for data organisation in memory and related methods ) 24 25 template <class T> 26 class TArray : public BaseArray { 30 27 public: 31 28 // Creation / destruction … … 43 40 virtual TArray<T>& operator = (const TArray<T>& a); 44 41 45 46 42 // Gestion taille/Remplissage 47 43 virtual void Clone(const TArray<T>& a); 48 44 virtual void ReSize(uint_4 ndim, uint_4 * siz, uint_4 step=1); 49 45 virtual void Realloc(uint_4 ndim, uint_4 * siz, uint_4 step=1, bool force=false); 50 // Returns true if ndim and sizes are equal 51 virtual bool CompareSizes(const TArray<T>& a); 46 52 47 // Compacts size=1 array dimensions 53 virtual TArray<T>& CompactDim(); 54 55 // Array dimensions 56 inline uint_4 NbDimensions() const { return( ndim_ ); } 57 58 inline uint_8 Size() const { return(totsize_); } 59 inline uint_4 SizeX() const { return(size_[0]); } 60 inline uint_4 SizeY() const { return(size_[1]); } 61 inline uint_4 SizeZ() const { return(size_[2]); } 62 inline uint_4 Size(int ka) const { return(size_[CheckDI(ka,1)]); } 63 64 uint_4 MaxSizeKA() const ; 65 66 // memory organisation - packing information 67 inline bool IsPacked() const { return(moystep_ == 1); } 68 inline bool IsPackedX() const { return(step_[0] == 1); } 69 inline bool IsPackedY() const { return(step_[1] == 1); } 70 inline bool IsPackedZ() const { return(step_[2] == 1); } 71 inline bool IsPacked(int ka) const { return(step_[CheckDI(ka,2)] == 1); } 72 73 inline uint_4 MinStep() const { return(minstep_); } 74 inline uint_4 AvgStep() const { return(moystep_); } 75 inline uint_4 StepX() const { return(step_[0]); } 76 inline uint_4 StepZ() const { return(step_[1]); } 77 inline uint_4 StepY() const { return(step_[2]); } 78 inline uint_4 Step(int ka) const { return(step_[CheckDI(ka,3)]); } 79 80 uint_4 MinStepKA() const ; 81 82 uint_8 Offset(uint_8 ip=0) const ; 83 84 85 // Temporaire? 86 inline bool IsTemp(void) const {return mNDBlock.IsTemp();} 87 inline void SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);} 48 virtual TArray<T>& CompactAllDimensions(); 49 virtual TArray<T>& CompactTrailingDimensions(); 88 50 89 51 // SubArrays 90 52 virtual TArray<T> operator () (Range rx, Range ry, Range rz=0, Range rt=0, Range ru=0); 91 53 92 // Acces to data 54 55 // ---- Access to data 56 // Definition of virtual element acces method inherited from BaseArray class 57 virtual double ValueAtPosition(uint_8 ip) const; 58 59 // Data Access: operator overloaded inline acces methods 93 60 inline T const& operator()(uint_4 ix, uint_4 iy, uint_4 iz) const ; 94 61 inline T& operator()(uint_4 ix, uint_4 iy, uint_4 iz); … … 108 75 inline const NDataBlock<T>& DataBlock() const {return mNDBlock;} 109 76 77 // Temporaire? 78 inline bool IsTemp(void) const {return mNDBlock.IsTemp();} 79 inline void SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);} 80 110 81 // Operations diverses = , +=, ... 111 82 // Conversion en type T, if Size() == 1 112 inline operator T();83 inline T toScalar(); 113 84 // Met les elements a une suite de valeurs 114 85 virtual TArray<T>& operator = (Sequence seq); … … 123 94 virtual TArray<T>& operator += (const TArray<T>& a); 124 95 virtual TArray<T>& operator -= (const TArray<T>& a); 125 // Multi lication, division element par element les deux tableaux96 // Multiplication, division element par element les deux tableaux 126 97 virtual TArray<T>& MultElt(const TArray<T>& a); 127 98 virtual TArray<T>& DivElt(const TArray<T>& a); 128 99 129 // Application d'une fonction130 virtual TArray<T>& ApplyFunction(Arr_DoubleFunctionOfX f);131 virtual TArray<T>& ApplyFunction(Arr_FloatFunctionOfX f);132 133 100 // Impression, I/O, ... 134 static void SetMaxPrint(uint_4 nprt=50); 135 void Show(ostream& os, bool si=false) const; 136 inline void Show() const { Show(cout); } 137 void Print(ostream& os, int_4 maxprt=-1, bool si=false) const ; 138 139 // Objet DVList info 140 DVList& Info(); 101 virtual string DataType() const; // definition of abstract method inherited from BaseArray 102 virtual void Print(ostream& os, int_4 maxprt=-1, bool si=false) const ; 141 103 142 104 // Pour la gestion de persistance … … 144 106 145 107 protected: 146 // Verifie la compatibilite de l'index de dimension147 inline int CheckDI(int ka, int msg) const ;148 // Verifie la compatibilite des bornes d'index149 inline void CheckBound(int ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu, int msg) const ;150 // Changing Sizes/NDim ... return true if OK151 bool UpdateSizes(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset, string & exmsg);152 bool UpdateSizes(uint_4 ndim, const uint_4 * siz, const uint_4 * step, uint_8 offset, string & exmsg);153 bool UpdateSizes(const TArray<T>& a, string & exmsg);154 static uint_8 ComputeTotalSize(uint_4 ndim, uint_4 * siz, uint_4 step, uint_8 offset) ;155 108 // partage les donnees si "a" temporaire, clone sinon. 156 109 void CloneOrShare(const TArray<T>& a); 157 110 // Share: partage les donnees de "a" 158 111 void Share(const TArray<T>& a); 159 // Extraction de sous-tableau 160 virtual void SubArray(TArray<T> & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step); 161 162 uint_4 ndim_; // nb of dimensions 163 uint_4 size_[TARRAY_MAXNDIMS]; // array size in each dimension 164 uint_8 totsize_; // Total number of elements 165 uint_4 step_[TARRAY_MAXNDIMS]; // two consecutive elements distance in a given dimension 166 uint_4 minstep_; // minimal step (in any axes) 167 uint_4 moystep_; // mean step 0 non regular steps 168 uint_8 offset_; // global offset -> position of elem[0] in DataBlock 112 169 113 NDataBlock<T> mNDBlock; // Le bloc des donnees 170 uint_4 marowi_, macoli_; // For matrices, Row index and column index in dimensions171 172 DVList* mInfo; // Infos (variables) attachees au tableau173 174 static char * ck_op_msg_[6]; // Operation messages for CheckDI() CheckBound()175 static uint_4 max_nprt_; // Nb maxi d'elements imprimes176 114 }; 177 115 … … 218 156 {TArray<T> result(a); result.SetTemp(true); result += b; return result;} 219 157 220 ////////////////////////////////////////////////221 // Calcul de fonction222 template <class T>223 inline TArray<T> sin(const TArray<T>& a)224 {TArray<T> result(a); result.SetTemp(true); result.ApplyFunction(sin); return result;}225 226 template <class T>227 inline TArray<T> cos(const TArray<T>& a)228 {TArray<T> result(a); result.SetTemp(true); result.ApplyFunction(cos); return result;}229 230 // --------------------------------------------------231 // Methodes inline de verification232 // --------------------------------------------------233 template <class T>234 inline int TArray<T>::CheckDI(int ka, int msg) const235 {236 if ( (ka < 0) || (ka >= ndim_) ) {237 string txt = "TArray<T>::CheckDimensionIndex/Error "; txt += ck_op_msg_[msg];238 throw(ParmError(txt));239 }240 return(ka);241 }242 243 template <class T>244 inline void TArray<T>::CheckBound(int ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu, int msg) const245 {246 if ( (ix >= size_[0]) || (iy >= size_[1]) || (iz > size_[2]) ||247 (it >= size_[3]) || (iu >= size_[4]) ) {248 string txt = "TArray<T>::CheckArrayBound/Error "; txt += ck_op_msg_[msg];249 throw(ParmError(txt));250 }251 return;252 }253 254 158 255 159 // -------------------------------------------------- … … 349 253 350 254 template <class T> 351 inline T Array<T>::operator T()255 inline T TArray<T>::toScalar() 352 256 { 353 257 if (Size() != 1) throw(SzMismatchError("TArray<T>::operator T() Size() != 1")) ;
Note:
See TracChangeset
for help on using the changeset viewer.