Changeset 813 in Sophya for trunk/SophyaLib/TArray/tmatrix.cc
- Timestamp:
- Apr 5, 2000, 5:44:19 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tmatrix.cc
r804 r813 1 // $Id: tmatrix.cc,v 1. 3 2000-04-03 17:35:58ansari Exp $1 // $Id: tmatrix.cc,v 1.4 2000-04-05 15:44:15 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" … … 17 17 : TArray<T>() 18 18 { 19 ck_memo_vt_ = true; 19 20 } 20 21 … … 48 49 : TArray<T>(a) 49 50 { 50 if (a.NbDimensions() != 2) 51 throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions() != 2 "); 51 if (a.NbDimensions() > 2) 52 throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions()>2 "); 53 if (a.NbDimensions() == 1) { 54 size_[1] = 1; 55 step_[1] = size_[0]*step_[0]; 56 ndim_ = 2; 57 } 58 UpdateMemoryMapping(a, SameMemoryMapping); 52 59 } 53 60 … … 56 63 : TArray<T>(a, share) 57 64 { 58 if (a.NbDimensions() != 2) 59 throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions() != 2 "); 65 if (a.NbDimensions() > 2) 66 throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions()>2"); 67 if (a.NbDimensions() == 1) { 68 size_[1] = 1; 69 step_[1] = size_[0]*step_[0]; 70 ndim_ = 2; 71 } 60 72 UpdateMemoryMapping(a, mm); 61 73 } … … 71 83 TArray<T>& TMatrix<T>::Set(const TArray<T>& a) 72 84 { 73 if (a.NbDimensions() != 2) 74 throw SzMismatchError("TMatrix<T>::Set(const TArray<T>& a) a.NbDimensions() != 2 "); 75 return(TArray<T>::Set(a)); 85 if (a.NbDimensions() > 2) 86 throw SzMismatchError("TMatrix<T>::Set(const TArray<T>& a) a.NbDimensions() > 2"); 87 TArray<T>::Set(a); 88 if (a.NbDimensions() == 1) { 89 size_[1] = 1; 90 step_[1] = size_[0]*step_[0]; 91 ndim_ = 2; 92 } 93 UpdateMemoryMapping(a, SameMemoryMapping); 94 return(*this); 76 95 } 77 96 … … 83 102 uint_4 size[BASEARRAY_MAXNDIMS]; 84 103 for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++) size[kk] = 0; 85 size[0] = r; size[1] = c;86 104 if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 87 UpdateMemoryMapping(mm, size[0], size[1]); 105 else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) 106 mm = GetDefaultMemoryMapping(); 107 if (mm == CMemoryMapping) { 108 size[0] = c; size[1] = r; 109 } 110 else { 111 size[0] = r; size[1] = c; 112 } 88 113 TArray<T>::ReSize(2, size, 1); 89 UpdateMemoryMapping(mm , size[0], size[1]);114 UpdateMemoryMapping(mm); 90 115 } 91 116 … … 97 122 uint_4 size[BASEARRAY_MAXNDIMS]; 98 123 for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++) size[kk] = 0; 99 UpdateMemoryMapping(mm, size[0], size[1]); 124 if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 125 else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) 126 mm = GetDefaultMemoryMapping(); 127 if (mm == CMemoryMapping) { 128 size[0] = c; size[1] = r; 129 } 130 else { 131 size[0] = r; size[1] = c; 132 } 100 133 TArray<T>::Realloc(2, size, 1, force); 101 UpdateMemoryMapping(mm , size[0], size[1]);134 UpdateMemoryMapping(mm); 102 135 } 103 136 104 137 // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ? 105 138 template <class T> 106 TMatrix<T> TMatrix<T>::operator () (Range rline, Range rcol) const 107 { 108 uint_4 nx, ny; 109 nx = ny = 0; 110 if (GetMemoryMapping() == CMemoryMapping ) { 111 TMatrix sm(SubArray(rcol, rline, 0, 0, 0),true,CMemoryMapping); 112 sm.UpdateMemoryMapping(CMemoryMapping, nx, ny); 113 sm.SetTemp(true); 114 return(sm); 115 } 116 else { 117 TMatrix sm(SubArray(rline, rcol, 0, 0, 0),true,CMemoryMapping); 118 sm.UpdateMemoryMapping(FortranMemoryMapping, nx, ny); 119 sm.SetTemp(true); 120 return(sm); 121 } 139 TMatrix<T> TMatrix<T>::SubMatrix(Range rline, Range rcol) const 140 { 141 short mm = GetMemoryMapping(); 142 Range rx, ry; 143 if (mm == CMemoryMapping) { rx = rcol; ry = rline; } 144 else { ry = rcol; rx = rline; } 145 TMatrix sm(SubArray(rx, ry, Range(0), Range(0), Range(0)),true, mm); 146 sm.UpdateMemoryMapping(mm); 147 sm.SetTemp(true); 148 return(sm); 122 149 } 123 150 … … 127 154 TMatrix<T>& TMatrix<T>::Transpose() 128 155 { 156 short vt = (marowi_ == veceli_) ? ColumnVector : RowVector; 129 157 uint_4 rci = macoli_; 130 158 macoli_ = marowi_; 131 159 marowi_ = rci; 160 veceli_ = (vt == ColumnVector ) ? marowi_ : macoli_; 132 161 return(*this); 133 162 } … … 147 176 148 177 // Rearrangement memoire 178 // Si identique, renvoie une matrice qui partage les donnees 149 179 template <class T> 150 180 TMatrix<T> TMatrix<T>::Rearrange(short mm) 151 181 { 152 if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 182 if ( mm == SameMemoryMapping) mm = GetMemoryMapping(); 183 else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) 184 mm = GetDefaultMemoryMapping(); 185 186 if (mm == GetMemoryMapping()) 187 return (TMatrix<T>(*this, true)); 188 153 189 TMatrix<T> tm(NRows(), NCols(), mm); 154 190 for(uint_4 i=0; i<NRows(); i++) … … 180 216 //**** Impression 181 217 template <class T> 218 string TMatrix<T>::InfoString() const 219 { 220 string rs = "TMatrix<"; 221 rs += typeid(T).name(); 222 char buff[64]; 223 sprintf(buff, ">(NRows=%ld, NCols=%ld)", (long)NRows(), (long)NCols()); 224 rs += buff; 225 return(rs); 226 } 227 228 template <class T> 182 229 void TMatrix<T>::Print(ostream& os, int_4 maxprt, bool si) const 183 230 { 184 os << "... TMatrix<T>(NRows=" << NRows() << " x NCols=" << NCols()185 << ")::Print() (MemOrg=" << GetMemoryMapping() << ")" << endl;186 os << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA() << " VectKA=" << VectKA() << endl;187 231 if (maxprt < 0) maxprt = max_nprt_; 188 232 int_4 npr = 0; … … 200 244 os << endl; 201 245 } 202 os << "\n" <<endl;246 os << endl; 203 247 } 204 248 … … 235 279 } 236 280 237 238 281 /////////////////////////////////////////////////////////////// 239 282 #ifdef __CXX_PRAGMA_TEMPLATES__
Note:
See TracChangeset
for help on using the changeset viewer.