[787] | 1 | // Base class for numerical arrays
|
---|
| 2 | // R. Ansari, C.Magneville 03/2000
|
---|
| 3 |
|
---|
| 4 | #include "machdefs.h"
|
---|
| 5 | #include <stdio.h>
|
---|
| 6 | #include <stdlib.h>
|
---|
| 7 | #include "pexceptions.h"
|
---|
| 8 | #include "basarr.h"
|
---|
| 9 |
|
---|
| 10 | // Variables statiques globales
|
---|
[894] | 11 | char * BaseArray::ck_op_msg_[6] =
|
---|
| 12 | {"???", "Size(int )", "IsPacked(int )"
|
---|
| 13 | ,"Stride(int )", "ElemCheckBound()", "operator()" };
|
---|
[787] | 14 | uint_4 BaseArray::max_nprt_ = 50;
|
---|
[813] | 15 | uint_4 BaseArray::prt_lev_ = 0;
|
---|
[804] | 16 | short BaseArray::default_memory_mapping = CMemoryMapping;
|
---|
[813] | 17 | short BaseArray::default_vector_type = ColumnVector;
|
---|
| 18 | uint_8 BaseArray::openmp_size_threshold = 200000;
|
---|
[787] | 19 |
|
---|
[813] | 20 | // ------ Methodes statiques globales --------
|
---|
| 21 |
|
---|
[890] | 22 | //! Set maximum number of printed elements and print level
|
---|
| 23 | /*!
|
---|
| 24 | \param nprt : maximum number of print
|
---|
| 25 | \param lev : print level
|
---|
| 26 | */
|
---|
[813] | 27 | void BaseArray::SetMaxPrint(uint_4 nprt, uint_4 lev)
|
---|
[787] | 28 | {
|
---|
| 29 | max_nprt_ = nprt;
|
---|
[813] | 30 | prt_lev_ = (lev < 3) ? lev : 3;
|
---|
[787] | 31 | }
|
---|
| 32 |
|
---|
[890] | 33 | //! Set Size threshold for parallel routine call
|
---|
| 34 | /*!
|
---|
| 35 | \param thr : thresold value
|
---|
| 36 | */
|
---|
[813] | 37 | void BaseArray::SetOpenMPSizeThreshold(uint_8 thr)
|
---|
| 38 | {
|
---|
| 39 | openmp_size_threshold = thr;
|
---|
| 40 | }
|
---|
[787] | 41 |
|
---|
[813] | 42 |
|
---|
[894] | 43 | //! Compute totale size
|
---|
| 44 | /*!
|
---|
| 45 | \param ndim : number of dimensions
|
---|
| 46 | \param siz : array of size along the \b ndim dimensions
|
---|
| 47 | \param step[ndim] : step value
|
---|
| 48 | \param offset : offset value
|
---|
| 49 | \return Total size of the array
|
---|
| 50 | */
|
---|
[804] | 51 | uint_8 BaseArray::ComputeTotalSize(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset)
|
---|
[787] | 52 | {
|
---|
| 53 | uint_8 rs = step;
|
---|
| 54 | for(int k=0; k<ndim; k++) rs *= siz[k];
|
---|
| 55 | return(rs+offset);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[894] | 58 | //! Set Default Memory Mapping
|
---|
| 59 | /*!
|
---|
| 60 | \param mm : Memory Mapping type
|
---|
| 61 | \verbatim
|
---|
| 62 | mm == CMemoryMapping : C like memory mapping
|
---|
| 63 | mm == FortranMemoryMapping : Fortran like memory mapping
|
---|
| 64 | \endverbatim
|
---|
| 65 | \verbatim
|
---|
| 66 | # ===== For Matrices
|
---|
| 67 | *** MATHEMATICS: m(row,column) with indexes running [1,n])
|
---|
| 68 | | 11 12 13 |
|
---|
| 69 | matrix Math = Mmath= | 21 22 23 |
|
---|
| 70 | | 31 32 33 |
|
---|
| 71 | *** IDL, \b FORTRAN: indexes data in \b row-major format:
|
---|
| 72 | indexes arrays in (column,row) order.
|
---|
| 73 | index IDL running [0,n[ ; index FORTRAN running [1,n]
|
---|
| 74 | M in memory: [ 11 12 13 : 21 22 23 : 31 32 33 : ... ]
|
---|
| 75 | line 1 : line 2 : line 3 : ...
|
---|
| 76 | ex: Midl(0,2) = Mfor(1,3) = Mmath(3,1) = 31
|
---|
| 77 | Midl(2,0) = Mfor(3,1) = Mmath(1,3) = 13
|
---|
| 78 | *** C: indexes data in \b column-major format:
|
---|
| 79 | indexes arrays in [row][column] order.
|
---|
| 80 | index C running [0,n[
|
---|
| 81 | M in memory: [ 11 21 31 : 12 22 32 : 13 23 33 : ... ]
|
---|
| 82 | column 1 : column 2 : column 3 : ...
|
---|
| 83 | ex: Mc[2][0] = Mmath(3,1) = 31
|
---|
| 84 | Mc[0][2] = Mmath(1,3) = 13
|
---|
| 85 | *** RESUME diff Idl/Fortan/C/Math:
|
---|
| 86 | Midl(col-1,row-1) = Mfor(col,row) = Mc[row-1][col-1] = Mmath(row,col)
|
---|
| 87 | TRANSPOSE(column-major array) --> row-major array
|
---|
| 88 | \endverbatim
|
---|
| 89 | \return default memory mapping value
|
---|
| 90 | */
|
---|
[804] | 91 | short BaseArray::SetDefaultMemoryMapping(short mm)
|
---|
| 92 | {
|
---|
[813] | 93 | default_memory_mapping = (mm != CMemoryMapping) ? FortranMemoryMapping : CMemoryMapping;
|
---|
[804] | 94 | return default_memory_mapping;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[894] | 97 | //! Set Default Vector Type
|
---|
| 98 | /*!
|
---|
| 99 | \param vt : vector type (ColumnVector,RowVector)
|
---|
| 100 | \return default vector type value
|
---|
| 101 | */
|
---|
[813] | 102 | short BaseArray::SetDefaultVectorType(short vt)
|
---|
| 103 | {
|
---|
| 104 | default_vector_type = (vt != ColumnVector) ? RowVector : ColumnVector ;
|
---|
| 105 | return default_vector_type;
|
---|
| 106 | }
|
---|
[804] | 107 |
|
---|
[894] | 108 | //! Select Memory Mapping
|
---|
| 109 | /*!
|
---|
| 110 | Do essentially nothing.
|
---|
| 111 | \param mm : type of Memory Mapping (CMemoryMapping,FortranMemoryMapping)
|
---|
| 112 | \return return \b mm if it makes sense or default memory mapping value
|
---|
| 113 | \sa SetDefaultMemoryMapping
|
---|
| 114 | */
|
---|
[804] | 115 | short BaseArray::SelectMemoryMapping(short mm)
|
---|
| 116 | {
|
---|
| 117 | if ( (mm == CMemoryMapping) || (mm == FortranMemoryMapping) ) return (mm) ;
|
---|
| 118 | else return (default_memory_mapping);
|
---|
| 119 | }
|
---|
[894] | 120 |
|
---|
| 121 | //! Select Vector type
|
---|
| 122 | /*!
|
---|
| 123 | Do essentially nothing.
|
---|
| 124 | \param vt : vector type (ColumnVector,RowVector)
|
---|
| 125 | \return return \b vt if it makes sense or default vector type
|
---|
| 126 | \sa SetDefaultVectorType
|
---|
| 127 | */
|
---|
[813] | 128 | short BaseArray::SelectVectorType(short vt)
|
---|
| 129 | {
|
---|
| 130 | if ((vt == ColumnVector) || (vt == RowVector)) return(vt);
|
---|
| 131 | else return(default_vector_type);
|
---|
| 132 | }
|
---|
[804] | 133 |
|
---|
[894] | 134 | //! Update Memory Mapping
|
---|
| 135 | /*!
|
---|
| 136 | Update variables marowi_ macoli_ veceli_
|
---|
| 137 | \param mm : type of Memory Mapping (CMemoryMapping,FortranMemoryMapping)
|
---|
| 138 | \sa SetDefaultMemoryMapping
|
---|
| 139 | */
|
---|
[813] | 140 | void BaseArray::UpdateMemoryMapping(short mm)
|
---|
[804] | 141 | {
|
---|
[813] | 142 | short vt = default_vector_type;
|
---|
[804] | 143 | if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) mm = default_memory_mapping;
|
---|
| 144 | if (mm == CMemoryMapping) {
|
---|
[813] | 145 | marowi_ = 1; macoli_ = 0;
|
---|
[804] | 146 | }
|
---|
| 147 | else {
|
---|
[813] | 148 | marowi_ = 0; macoli_ = 1;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
|
---|
| 152 | // Choix automatique Vecteur ligne ou colonne
|
---|
| 153 | if ( size_[macoli_] == 1) veceli_ = marowi_;
|
---|
| 154 | else veceli_ = macoli_;
|
---|
| 155 | }
|
---|
| 156 | else veceli_ = (vt == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 157 | ck_memo_vt_ = true; // Check MemMapping and VectorType for CompareSize
|
---|
[804] | 158 | }
|
---|
| 159 |
|
---|
[894] | 160 | //! Update Memory Mapping
|
---|
| 161 | /*!
|
---|
| 162 | \param a : Array to be compared with
|
---|
| 163 | \param mm : type of Memory Mapping or memory mapping transfert
|
---|
| 164 | (SameMemoryMapping,AutoMemoryMapping,CMemoryMapping,FortranMemoryMapping)
|
---|
| 165 | \sa SetDefaultMemoryMapping
|
---|
| 166 | */
|
---|
[804] | 167 | void BaseArray::UpdateMemoryMapping(BaseArray const & a, short mm)
|
---|
| 168 | {
|
---|
[813] | 169 | short vt = default_vector_type;
|
---|
| 170 | if (mm == SameMemoryMapping) {
|
---|
[804] | 171 | mm = ((a.marowi_ == 1) ? CMemoryMapping : FortranMemoryMapping);
|
---|
[813] | 172 | vt = (a.marowi_ == a.veceli_) ? ColumnVector : RowVector;
|
---|
| 173 | }
|
---|
| 174 | else if (mm == AutoMemoryMapping) mm = default_memory_mapping;
|
---|
| 175 |
|
---|
[804] | 176 | if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) mm = default_memory_mapping;
|
---|
| 177 | if (mm == CMemoryMapping) {
|
---|
[813] | 178 | marowi_ = 1; macoli_ = 0;
|
---|
[804] | 179 | }
|
---|
| 180 | else {
|
---|
[813] | 181 | marowi_ = 0; macoli_ = 1;
|
---|
| 182 | }
|
---|
| 183 | if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
|
---|
| 184 | // Choix automatique Vecteur ligne ou colonne
|
---|
| 185 | if ( size_[macoli_] == 1) veceli_ = marowi_;
|
---|
| 186 | else veceli_ = marowi_;
|
---|
| 187 | }
|
---|
| 188 | else veceli_ = (vt == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 189 | ck_memo_vt_ = true; // Check MemMapping and VectorType for CompareSize
|
---|
[804] | 190 | }
|
---|
| 191 |
|
---|
[894] | 192 | //! Set Memory Mapping type
|
---|
| 193 | /*!
|
---|
| 194 | Compute values for variables marowi_ macoli_ veceli_
|
---|
| 195 | \param mm : Memory Mapping type (SameMemoryMapping,AutoMemoryMapping
|
---|
| 196 | ,CMemoryMapping,FortranMemoryMapping)
|
---|
| 197 | \sa SetDefaultMemoryMapping
|
---|
| 198 | */
|
---|
[813] | 199 | void BaseArray::SetMemoryMapping(short mm)
|
---|
| 200 | {
|
---|
| 201 | if (mm == SameMemoryMapping) return;
|
---|
| 202 | if (mm == AutoMemoryMapping) mm = default_memory_mapping;
|
---|
| 203 | if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) return;
|
---|
| 204 | short vt = (marowi_ == veceli_) ? ColumnVector : RowVector;
|
---|
| 205 | if (mm == CMemoryMapping) {
|
---|
| 206 | marowi_ = 1; macoli_ = 0;
|
---|
| 207 | }
|
---|
| 208 | else {
|
---|
| 209 | marowi_ = 0; macoli_ = 1;
|
---|
| 210 | }
|
---|
| 211 | if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
|
---|
| 212 | // Choix automatique Vecteur ligne ou colonne
|
---|
| 213 | if ( size_[macoli_] == 1) veceli_ = marowi_;
|
---|
| 214 | else veceli_ = macoli_;
|
---|
| 215 | }
|
---|
| 216 | else veceli_ = (vt == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 217 | ck_memo_vt_ = true; // Check MemMapping and VectorType for CompareSize
|
---|
| 218 | }
|
---|
[804] | 219 |
|
---|
[894] | 220 | //! Set Vector Type
|
---|
| 221 | /*!
|
---|
| 222 | Compute values for variable veceli_
|
---|
| 223 | \param vt : vector type ()
|
---|
| 224 | \sa SetDefaultVectorType
|
---|
| 225 | */
|
---|
[813] | 226 | void BaseArray::SetVectorType(short vt)
|
---|
| 227 | {
|
---|
| 228 | if (vt == SameVectorType) return;
|
---|
| 229 | if (vt == AutoVectorType) vt = default_vector_type;
|
---|
| 230 | if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
|
---|
| 231 | // Choix automatique Vecteur ligne ou colonne
|
---|
| 232 | if ( size_[macoli_] == 1) veceli_ = marowi_;
|
---|
| 233 | else veceli_ = macoli_;
|
---|
| 234 | }
|
---|
| 235 | else veceli_ = (vt == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 236 | ck_memo_vt_ = true; // Check MemMapping and VectorType for CompareSize
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[787] | 239 | // -------------------------------------------------------
|
---|
| 240 | // Methodes de la classe
|
---|
| 241 | // -------------------------------------------------------
|
---|
| 242 |
|
---|
[890] | 243 | //! Default constructor
|
---|
[787] | 244 | BaseArray::BaseArray()
|
---|
| 245 | : mInfo(NULL)
|
---|
| 246 | {
|
---|
| 247 | ndim_ = 0;
|
---|
| 248 | for(int k=0; k<BASEARRAY_MAXNDIMS; k++) step_[k] = size_[k] = 0;
|
---|
| 249 | totsize_ = 0;
|
---|
| 250 | minstep_ = 0;
|
---|
| 251 | moystep_ = 0;
|
---|
| 252 | offset_ = 0;
|
---|
[813] | 253 | // Default for matrices : Memory organisation and Vector type
|
---|
| 254 | if (default_memory_mapping == CMemoryMapping) {
|
---|
| 255 | marowi_ = 1; macoli_ = 0;
|
---|
| 256 | }
|
---|
| 257 | else {
|
---|
| 258 | marowi_ = 0; macoli_ = 1;
|
---|
| 259 | }
|
---|
| 260 | veceli_ = (default_vector_type == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 261 | ck_memo_vt_ = false; // Default : Don't Check MemMapping and VectorType for CompareSize
|
---|
[787] | 262 | }
|
---|
| 263 |
|
---|
[890] | 264 | //! Destructor
|
---|
[787] | 265 | BaseArray::~BaseArray()
|
---|
| 266 | {
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 |
|
---|
[894] | 270 | //! Returns true if dimension and sizes are equal
|
---|
[890] | 271 | /*!
|
---|
| 272 | \param a : array to be compared
|
---|
[894] | 273 | \return true if ndim and sizes[ndim] are equal, false if not
|
---|
[890] | 274 | */
|
---|
[787] | 275 | bool BaseArray::CompareSizes(const BaseArray& a)
|
---|
| 276 | {
|
---|
| 277 | if (ndim_ != a.ndim_) return(false);
|
---|
| 278 | for(int k=0; k<ndim_; k++)
|
---|
| 279 | if (size_[k] != a.size_[k]) return(false);
|
---|
[813] | 280 | // $CHECK$ Reza doit-on verifier ca
|
---|
| 281 | if (ck_memo_vt_ && a.ck_memo_vt_)
|
---|
| 282 | if ( (macoli_ != a.macoli_) || (marowi_ != a.marowi_) ||
|
---|
| 283 | (veceli_ != a.veceli_) ) return(false);
|
---|
[787] | 284 | return(true);
|
---|
| 285 | }
|
---|
| 286 |
|
---|
[894] | 287 | //! Change dimension if some size == 1
|
---|
[787] | 288 | void BaseArray::CompactAllDim()
|
---|
| 289 | {
|
---|
| 290 | if (ndim_ < 2) return;
|
---|
| 291 | uint_4 ndim = 0;
|
---|
| 292 | uint_4 size[BASEARRAY_MAXNDIMS];
|
---|
| 293 | uint_4 step[BASEARRAY_MAXNDIMS];
|
---|
| 294 | for(int k=0; k<ndim_; k++) {
|
---|
| 295 | if (size_[k] < 2) continue;
|
---|
| 296 | size[ndim] = size_[k];
|
---|
| 297 | step[ndim] = step_[k];
|
---|
| 298 | ndim++;
|
---|
| 299 | }
|
---|
| 300 | if (ndim == 0) {
|
---|
| 301 | size[0] = size_[0];
|
---|
| 302 | step[0] = step_[0];
|
---|
| 303 | ndim = 1;
|
---|
| 304 | }
|
---|
| 305 | string exmsg = "BaseArray::CompactAllDim() ";
|
---|
| 306 | if (!UpdateSizes(ndim, size, step, offset_, exmsg)) throw( ParmError(exmsg) );
|
---|
| 307 | return;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[894] | 310 | //! Change dimension if some trailed size == 1
|
---|
[787] | 311 | void BaseArray::CompactTrailingDim()
|
---|
| 312 | {
|
---|
| 313 | if (ndim_ < 2) return;
|
---|
| 314 | uint_4 ndim = 0;
|
---|
| 315 | uint_4 size[BASEARRAY_MAXNDIMS];
|
---|
| 316 | uint_4 step[BASEARRAY_MAXNDIMS];
|
---|
| 317 | for(int k=0; k<ndim_; k++) {
|
---|
| 318 | size[ndim] = size_[k];
|
---|
| 319 | step[ndim] = step_[k];
|
---|
| 320 | if (size_[k] > 1) ndim=k;
|
---|
| 321 | }
|
---|
| 322 | if (ndim == 0) ndim = 1;
|
---|
| 323 | string exmsg = "BaseArray::CompactTrailingDim() ";
|
---|
| 324 | if (!UpdateSizes(ndim, size, step, offset_, exmsg)) throw( ParmError(exmsg) );
|
---|
| 325 | return;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[894] | 328 | //! return minimum value for step[ndim]
|
---|
[787] | 329 | uint_4 BaseArray::MinStepKA() const
|
---|
| 330 | {
|
---|
| 331 | for(int ka=0; ka<ndim_; ka++)
|
---|
| 332 | if (step_[ka] == minstep_) return(ka);
|
---|
| 333 | return(0);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[894] | 336 | //! return maximum value for step[ndim]
|
---|
[787] | 337 | uint_4 BaseArray::MaxSizeKA() const
|
---|
| 338 | {
|
---|
| 339 | uint_4 ka = 0;
|
---|
| 340 | uint_4 mx = size_[0];
|
---|
| 341 | for(int k=0; k<ndim_; k++)
|
---|
| 342 | if (size_[k] > mx) { ka = k; mx = size_[k]; }
|
---|
| 343 | return(ka);
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 |
|
---|
| 347 | // Acces lineaire aux elements .... Calcul d'offset
|
---|
[813] | 348 | // --------------------------------------------------
|
---|
| 349 | // Position de l'element 0 du vecteur i selon l'axe ka
|
---|
| 350 | // --------------------------------------------------
|
---|
[894] | 351 | //! return position of first element for vector \b i alond \b ka th axe.
|
---|
[813] | 352 | uint_8 BaseArray::Offset(uint_4 ka, uint_8 i) const
|
---|
| 353 | {
|
---|
[787] | 354 |
|
---|
[813] | 355 | if ( (ndim_ < 1) || (i == 0) ) return(offset_);
|
---|
| 356 | //#ifdef SO_BOUNDCHECKING
|
---|
| 357 | if (ka >= ndim_)
|
---|
| 358 | throw RangeCheckError("BaseArray::Offset(uint_4 ka, uint_8 i) Axe KA Error");
|
---|
| 359 | if ( i*size_[ka] >= totsize_ )
|
---|
| 360 | throw RangeCheckError("BaseArray::Offset(uint_4 ka, uint_8 i) Index Error");
|
---|
| 361 | //#endif
|
---|
| 362 | uint_4 idx[BASEARRAY_MAXNDIMS];
|
---|
| 363 | int k;
|
---|
| 364 | uint_8 rest = i;
|
---|
| 365 | idx[ka] = 0;
|
---|
| 366 | for(k=0; k<ndim_; k++) {
|
---|
| 367 | if (k == ka) continue;
|
---|
| 368 | idx[k] = rest%size_[k]; rest /= size_[k];
|
---|
| 369 | }
|
---|
| 370 | uint_8 off = offset_;
|
---|
| 371 | for(k=0; k<ndim_; k++) off += idx[k]*step_[k];
|
---|
| 372 | return (off);
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[894] | 375 | //! return position of element \b ip.
|
---|
[787] | 376 | uint_8 BaseArray::Offset(uint_8 ip) const
|
---|
| 377 | {
|
---|
[813] | 378 | if ( (ndim_ < 1) || (ip == 0) ) return(offset_);
|
---|
| 379 | //#ifdef SO_BOUNDCHECKING
|
---|
| 380 | if (ip >= totsize_)
|
---|
| 381 | throw RangeCheckError("BaseArray::Offset(uint_8 ip) Out of range index ip");
|
---|
| 382 | //#endif
|
---|
| 383 |
|
---|
| 384 | uint_4 idx[BASEARRAY_MAXNDIMS];
|
---|
| 385 | int k;
|
---|
| 386 | uint_8 rest = ip;
|
---|
| 387 | for(k=0; k<ndim_; k++) {
|
---|
| 388 | idx[k] = rest%size_[k]; rest /= size_[k];
|
---|
| 389 | }
|
---|
| 390 | //#ifdef SO_BOUNDCHECKING
|
---|
| 391 | if (rest != 0)
|
---|
| 392 | throw PError("BaseArray::Offset(uint_8 ip) GUG !!! rest != 0");
|
---|
| 393 | //#endif
|
---|
| 394 | // if (rest != 0) cerr << " BUG ---- BaseArray::Offset( " << ip << " )" << rest << endl;
|
---|
| 395 | // cerr << " DBG-Offset( " << ip << ")" ;
|
---|
| 396 | // for(k=0; k<ndim_; k++) cerr << idx[k] << "," ;
|
---|
| 397 | // cerr << " ZZZZ " << endl;
|
---|
| 398 | uint_8 off = offset_;
|
---|
| 399 | for(k=0; k<ndim_; k++) off += idx[k]*step_[k];
|
---|
| 400 | return (off);
|
---|
[787] | 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
| 404 | // ----------------------------------------------------
|
---|
| 405 | // Impression, etc ...
|
---|
| 406 | // ----------------------------------------------------
|
---|
| 407 |
|
---|
[894] | 408 | //! Show infos on stream \b os (\b si to display DvList)
|
---|
[787] | 409 | void BaseArray::Show(ostream& os, bool si) const
|
---|
| 410 | {
|
---|
[850] | 411 | if (ndim_ < 1) {
|
---|
| 412 | os << "\n--- " << BaseArray::InfoString() << " Unallocated Array ! " << endl;
|
---|
| 413 | return;
|
---|
| 414 | }
|
---|
[813] | 415 | os << "\n--- " << InfoString() ;
|
---|
| 416 | os << " ND=" << ndim_ << " SizeX*Y*...= " ;
|
---|
[787] | 417 | for(int k=0; k<ndim_; k++) {
|
---|
| 418 | os << size_[k];
|
---|
[813] | 419 | if (k<ndim_-1) os << "x";
|
---|
[787] | 420 | }
|
---|
[813] | 421 | os << " ---" << endl;
|
---|
| 422 | if (prt_lev_ > 0) {
|
---|
| 423 | os << " TotSize= " << totsize_ << " Step(X Y ...)=" ;
|
---|
| 424 | for(int k=0; k<ndim_; k++) os << step_[k] << " " ;
|
---|
| 425 | os << " Offset= " << offset_ << endl;
|
---|
| 426 | }
|
---|
| 427 | if (prt_lev_ > 1) {
|
---|
| 428 | os << " MemoryMapping=" << GetMemoryMapping() << " VecType= " << GetVectorType()
|
---|
| 429 | << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA()
|
---|
| 430 | << " VectKA=" << VectKA() << endl;
|
---|
| 431 | }
|
---|
| 432 | if (!si && (prt_lev_ < 2)) return;
|
---|
| 433 | if (mInfo != NULL) os << (*mInfo) << endl;
|
---|
[787] | 434 |
|
---|
| 435 | }
|
---|
| 436 |
|
---|
[894] | 437 | //! Return BaseArray Type
|
---|
[813] | 438 | string BaseArray::InfoString() const
|
---|
| 439 | {
|
---|
| 440 | string rs = "BaseArray Type= ";
|
---|
| 441 | rs += typeid(*this).name() ;
|
---|
| 442 | return rs;
|
---|
| 443 | }
|
---|
[787] | 444 |
|
---|
[894] | 445 | //! Return attached DVList
|
---|
[787] | 446 | DVList& BaseArray::Info()
|
---|
| 447 | {
|
---|
| 448 | if (mInfo == NULL) mInfo = new DVList;
|
---|
| 449 | return(*mInfo);
|
---|
| 450 | }
|
---|
| 451 |
|
---|
[894] | 452 | //! Update sizes and information for array
|
---|
| 453 | /*!
|
---|
| 454 | \param ndim : dimension
|
---|
| 455 | \param siz[ndim] : sizes
|
---|
| 456 | \param step : step (must be the same on all dimensions)
|
---|
| 457 | \param offset : offset of the first element
|
---|
| 458 | \return true if all OK, false if problems appear
|
---|
| 459 | \return string \b exmsg for explanation in case of problems
|
---|
| 460 | */
|
---|
[787] | 461 | bool BaseArray::UpdateSizes(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset, string & exmsg)
|
---|
| 462 | {
|
---|
| 463 | if (ndim >= BASEARRAY_MAXNDIMS) {
|
---|
| 464 | exmsg += " NDim Error"; return false;
|
---|
| 465 | }
|
---|
| 466 | if (step < 1) {
|
---|
| 467 | exmsg += " Step(=0) Error"; return false;
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | minstep_ = moystep_ = step;
|
---|
| 471 |
|
---|
| 472 | // Flagging bad updates ...
|
---|
| 473 | ndim_ = 0;
|
---|
| 474 |
|
---|
| 475 | totsize_ = 1;
|
---|
| 476 | int k;
|
---|
| 477 | for(k=0; k<BASEARRAY_MAXNDIMS; k++) {
|
---|
| 478 | size_[k] = 1;
|
---|
| 479 | step_[k] = 0;
|
---|
| 480 | }
|
---|
| 481 | for(k=0; k<ndim; k++) {
|
---|
| 482 | size_[k] = siz[k] ;
|
---|
| 483 | step_[k] = totsize_*step;
|
---|
| 484 | totsize_ *= size_[k];
|
---|
| 485 | }
|
---|
| 486 | if (totsize_ < 1) {
|
---|
| 487 | exmsg += " Size Error"; return false;
|
---|
| 488 | }
|
---|
| 489 | offset_ = offset;
|
---|
[813] | 490 | // Default for matrices : Memory organisation and Vector type
|
---|
| 491 | if (default_memory_mapping == CMemoryMapping) {
|
---|
| 492 | marowi_ = 1; macoli_ = 0;
|
---|
| 493 | }
|
---|
| 494 | else {
|
---|
| 495 | marowi_ = 0; macoli_ = 1;
|
---|
| 496 | }
|
---|
| 497 | veceli_ = (default_vector_type == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 498 | ck_memo_vt_ = false; // Default : Don't Check MemMapping and VectorType for CompareSize
|
---|
[787] | 499 | // Update OK
|
---|
| 500 | ndim_ = ndim;
|
---|
| 501 | return true;
|
---|
| 502 | }
|
---|
| 503 |
|
---|
[894] | 504 | //! Update sizes and information for array
|
---|
| 505 | /*!
|
---|
| 506 | \param ndim : dimension
|
---|
| 507 | \param siz[ndim] : sizes
|
---|
| 508 | \param step[ndim] : steps
|
---|
| 509 | \param offset : offset of the first element
|
---|
| 510 | \return true if all OK, false if problems appear
|
---|
| 511 | \return string \b exmsg for explanation in case of problems
|
---|
| 512 | */
|
---|
[787] | 513 | bool BaseArray::UpdateSizes(uint_4 ndim, const uint_4 * siz, const uint_4 * step, uint_8 offset, string & exmsg)
|
---|
| 514 | {
|
---|
| 515 | if (ndim >= BASEARRAY_MAXNDIMS) {
|
---|
| 516 | exmsg += " NDim Error"; return false;
|
---|
| 517 | }
|
---|
| 518 |
|
---|
| 519 | // Flagging bad updates ...
|
---|
| 520 | ndim_ = 0;
|
---|
| 521 |
|
---|
| 522 | totsize_ = 1;
|
---|
| 523 | int k;
|
---|
| 524 | for(k=0; k<BASEARRAY_MAXNDIMS; k++) {
|
---|
| 525 | size_[k] = 1;
|
---|
| 526 | step_[k] = 0;
|
---|
| 527 | }
|
---|
| 528 | uint_4 minstep = step[0];
|
---|
| 529 | for(k=0; k<ndim; k++) {
|
---|
| 530 | size_[k] = siz[k] ;
|
---|
| 531 | step_[k] = step[k];
|
---|
| 532 | totsize_ *= size_[k];
|
---|
| 533 | if (step_[k] < minstep) minstep = step_[k];
|
---|
| 534 | }
|
---|
| 535 | if (minstep < 1) {
|
---|
| 536 | exmsg += " Step(=0) Error"; return false;
|
---|
| 537 | }
|
---|
| 538 | if (totsize_ < 1) {
|
---|
| 539 | exmsg += " Size Error"; return false;
|
---|
| 540 | }
|
---|
| 541 | uint_8 plast = 0;
|
---|
| 542 | for(k=0; k<ndim; k++) plast += (siz[k]-1)*step[k];
|
---|
| 543 | if (plast == minstep*totsize_ ) moystep_ = minstep;
|
---|
| 544 | else moystep_ = 0;
|
---|
| 545 | minstep_ = minstep;
|
---|
| 546 | offset_ = offset;
|
---|
[813] | 547 | // Default for matrices : Memory organisation and Vector type
|
---|
| 548 | if (default_memory_mapping == CMemoryMapping) {
|
---|
| 549 | marowi_ = 1; macoli_ = 0;
|
---|
| 550 | }
|
---|
| 551 | else {
|
---|
| 552 | marowi_ = 0; macoli_ = 1;
|
---|
| 553 | }
|
---|
| 554 | veceli_ = (default_vector_type == ColumnVector ) ? marowi_ : macoli_;
|
---|
| 555 | ck_memo_vt_ = false; // Default : Don't Check MemMapping and VectorType for CompareSize
|
---|
[787] | 556 | // Update OK
|
---|
| 557 | ndim_ = ndim;
|
---|
| 558 | return true;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[894] | 561 | //! Update sizes and information relative to array \b a
|
---|
| 562 | /*!
|
---|
| 563 | \param a : array to be compare with
|
---|
| 564 | \return true if all OK, false if problems appear
|
---|
| 565 | \return string \b exmsg for explanation in case of problems
|
---|
| 566 | */
|
---|
[787] | 567 | bool BaseArray::UpdateSizes(const BaseArray& a, string & exmsg)
|
---|
| 568 | {
|
---|
| 569 | if (a.ndim_ >= BASEARRAY_MAXNDIMS) {
|
---|
| 570 | exmsg += " NDim Error"; return false;
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | // Flagging bad updates ...
|
---|
| 574 | ndim_ = 0;
|
---|
| 575 |
|
---|
| 576 | totsize_ = 1;
|
---|
| 577 | int k;
|
---|
| 578 | for(k=0; k<BASEARRAY_MAXNDIMS; k++) {
|
---|
| 579 | size_[k] = 1;
|
---|
| 580 | step_[k] = 0;
|
---|
| 581 | }
|
---|
| 582 | uint_4 minstep = a.step_[0];
|
---|
| 583 | for(k=0; k<a.ndim_; k++) {
|
---|
| 584 | size_[k] = a.size_[k] ;
|
---|
| 585 | step_[k] = a.step_[k];
|
---|
| 586 | totsize_ *= size_[k];
|
---|
| 587 | if (step_[k] < minstep) minstep = step_[k];
|
---|
| 588 | }
|
---|
| 589 | if (minstep < 1) {
|
---|
| 590 | exmsg += " Step(=0) Error"; return false;
|
---|
| 591 | }
|
---|
| 592 | if (totsize_ < 1) {
|
---|
| 593 | exmsg += " Size Error"; return false;
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | minstep_ = a.minstep_;
|
---|
| 597 | moystep_ = a.moystep_;
|
---|
| 598 | offset_ = a.offset_;
|
---|
| 599 | macoli_ = a.macoli_;
|
---|
| 600 | marowi_ = a.marowi_;
|
---|
[804] | 601 | veceli_ = a.veceli_;
|
---|
[813] | 602 | ck_memo_vt_ = a.ck_memo_vt_;
|
---|
[787] | 603 | // Update OK
|
---|
| 604 | ndim_ = a.ndim_;
|
---|
| 605 | return true;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 |
|
---|
[894] | 609 | //! Update sizes and information relative to array \b a
|
---|
| 610 | /*!
|
---|
| 611 | \param a : array to be compare with
|
---|
| 612 | \param ndim : could be change (but should be less than the ndim of the current class)
|
---|
| 613 | \param siz[ndim],pos[ndim],step[ndim] : could be changed but must be
|
---|
| 614 | compatible within the memory size with those of the current class.
|
---|
| 615 | \return true if all OK, false if problems appear
|
---|
| 616 | \return string \b exmsg for explanation in case of problems
|
---|
| 617 | */
|
---|
[804] | 618 | void BaseArray::UpdateSubArraySizes(BaseArray & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step) const
|
---|
[787] | 619 | {
|
---|
[804] | 620 | if ( (ndim > ndim_) || (ndim < 1) )
|
---|
| 621 | throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) NDim Error") );
|
---|
[787] | 622 | int k;
|
---|
| 623 | for(k=0; k<ndim; k++)
|
---|
| 624 | if ( (siz[k]*step[k]+pos[k]) > size_[k] )
|
---|
[804] | 625 | throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) Size/Pos Error") );
|
---|
[787] | 626 | uint_8 offset = offset_;
|
---|
| 627 | for(k=0; k<ndim_; k++) {
|
---|
| 628 | offset += pos[k]*step_[k];
|
---|
| 629 | step[k] *= step_[k];
|
---|
| 630 | }
|
---|
[804] | 631 | string exm = "BaseArray::UpdateSubArraySizes() ";
|
---|
[787] | 632 | if (!ra.UpdateSizes(ndim, siz, step, offset, exm))
|
---|
| 633 | throw( ParmError(exm) );
|
---|
| 634 | return;
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 |
|
---|