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
|
---|
11 | char * BaseArray::ck_op_msg_[6] =
|
---|
12 | {"???", "Size(int )", "IsPacked(int )"
|
---|
13 | ,"Stride(int )", "ElemCheckBound()", "operator()" };
|
---|
14 | uint_4 BaseArray::max_nprt_ = 50;
|
---|
15 | uint_4 BaseArray::prt_lev_ = 0;
|
---|
16 | short BaseArray::default_memory_mapping = CMemoryMapping;
|
---|
17 | short BaseArray::default_vector_type = ColumnVector;
|
---|
18 | uint_8 BaseArray::openmp_size_threshold = 200000;
|
---|
19 |
|
---|
20 | // ------ Methodes statiques globales --------
|
---|
21 |
|
---|
22 | //! Set maximum number of printed elements and print level
|
---|
23 | /*!
|
---|
24 | \param nprt : maximum number of print
|
---|
25 | \param lev : print level
|
---|
26 | */
|
---|
27 | void BaseArray::SetMaxPrint(uint_4 nprt, uint_4 lev)
|
---|
28 | {
|
---|
29 | max_nprt_ = nprt;
|
---|
30 | prt_lev_ = (lev < 3) ? lev : 3;
|
---|
31 | }
|
---|
32 |
|
---|
33 | //! Set Size threshold for parallel routine call
|
---|
34 | /*!
|
---|
35 | \param thr : thresold value
|
---|
36 | */
|
---|
37 | void BaseArray::SetOpenMPSizeThreshold(uint_8 thr)
|
---|
38 | {
|
---|
39 | openmp_size_threshold = thr;
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
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 | */
|
---|
51 | uint_8 BaseArray::ComputeTotalSize(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset)
|
---|
52 | {
|
---|
53 | uint_8 rs = step;
|
---|
54 | for(int k=0; k<ndim; k++) rs *= siz[k];
|
---|
55 | return(rs+offset);
|
---|
56 | }
|
---|
57 |
|
---|
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 | */
|
---|
91 | short BaseArray::SetDefaultMemoryMapping(short mm)
|
---|
92 | {
|
---|
93 | default_memory_mapping = (mm != CMemoryMapping) ? FortranMemoryMapping : CMemoryMapping;
|
---|
94 | return default_memory_mapping;
|
---|
95 | }
|
---|
96 |
|
---|
97 | //! Set Default Vector Type
|
---|
98 | /*!
|
---|
99 | \param vt : vector type (ColumnVector,RowVector)
|
---|
100 | \return default vector type value
|
---|
101 | */
|
---|
102 | short BaseArray::SetDefaultVectorType(short vt)
|
---|
103 | {
|
---|
104 | default_vector_type = (vt != ColumnVector) ? RowVector : ColumnVector ;
|
---|
105 | return default_vector_type;
|
---|
106 | }
|
---|
107 |
|
---|
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 | */
|
---|
115 | short BaseArray::SelectMemoryMapping(short mm)
|
---|
116 | {
|
---|
117 | if ( (mm == CMemoryMapping) || (mm == FortranMemoryMapping) ) return (mm) ;
|
---|
118 | else return (default_memory_mapping);
|
---|
119 | }
|
---|
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 | */
|
---|
128 | short BaseArray::SelectVectorType(short vt)
|
---|
129 | {
|
---|
130 | if ((vt == ColumnVector) || (vt == RowVector)) return(vt);
|
---|
131 | else return(default_vector_type);
|
---|
132 | }
|
---|
133 |
|
---|
134 | //! Update Memory Mapping
|
---|
135 | /*!
|
---|
136 | Update variables marowi_ macoli_ veceli_
|
---|
137 | \param mm : type of Memory Mapping (CMemoryMapping,FortranMemoryMapping)
|
---|
138 | \sa SetDefaultMemoryMapping
|
---|
139 | */
|
---|
140 | void BaseArray::UpdateMemoryMapping(short mm)
|
---|
141 | {
|
---|
142 | short vt = default_vector_type;
|
---|
143 | if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) mm = default_memory_mapping;
|
---|
144 | if (mm == CMemoryMapping) {
|
---|
145 | marowi_ = 1; macoli_ = 0;
|
---|
146 | }
|
---|
147 | else {
|
---|
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
|
---|
158 | }
|
---|
159 |
|
---|
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 | */
|
---|
167 | void BaseArray::UpdateMemoryMapping(BaseArray const & a, short mm)
|
---|
168 | {
|
---|
169 | short vt = default_vector_type;
|
---|
170 | if (mm == SameMemoryMapping) {
|
---|
171 | mm = ((a.marowi_ == 1) ? CMemoryMapping : FortranMemoryMapping);
|
---|
172 | vt = (a.marowi_ == a.veceli_) ? ColumnVector : RowVector;
|
---|
173 | }
|
---|
174 | else if (mm == AutoMemoryMapping) mm = default_memory_mapping;
|
---|
175 |
|
---|
176 | if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) mm = default_memory_mapping;
|
---|
177 | if (mm == CMemoryMapping) {
|
---|
178 | marowi_ = 1; macoli_ = 0;
|
---|
179 | }
|
---|
180 | else {
|
---|
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
|
---|
190 | }
|
---|
191 |
|
---|
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 | */
|
---|
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 | }
|
---|
219 |
|
---|
220 | //! Set Vector Type
|
---|
221 | /*!
|
---|
222 | Compute values for variable veceli_
|
---|
223 | \param vt : vector type ()
|
---|
224 | \sa SetDefaultVectorType
|
---|
225 | */
|
---|
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 |
|
---|
239 | // -------------------------------------------------------
|
---|
240 | // Methodes de la classe
|
---|
241 | // -------------------------------------------------------
|
---|
242 |
|
---|
243 | //! Default constructor
|
---|
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;
|
---|
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
|
---|
262 | }
|
---|
263 |
|
---|
264 | //! Destructor
|
---|
265 | BaseArray::~BaseArray()
|
---|
266 | {
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | //! Returns true if dimension and sizes are equal
|
---|
271 | /*!
|
---|
272 | \param a : array to be compared
|
---|
273 | \return true if ndim and sizes[ndim] are equal, false if not
|
---|
274 | */
|
---|
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);
|
---|
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);
|
---|
284 | return(true);
|
---|
285 | }
|
---|
286 |
|
---|
287 | //! Change dimension if some size == 1
|
---|
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 |
|
---|
310 | //! Change dimension if some trailed size == 1
|
---|
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 |
|
---|
328 | //! return minimum value for step[ndim]
|
---|
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 |
|
---|
336 | //! return maximum value for step[ndim]
|
---|
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
|
---|
348 | // --------------------------------------------------
|
---|
349 | // Position de l'element 0 du vecteur i selon l'axe ka
|
---|
350 | // --------------------------------------------------
|
---|
351 | //! return position of first element for vector \b i alond \b ka th axe.
|
---|
352 | uint_8 BaseArray::Offset(uint_4 ka, uint_8 i) const
|
---|
353 | {
|
---|
354 |
|
---|
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 |
|
---|
375 | //! return position of element \b ip.
|
---|
376 | uint_8 BaseArray::Offset(uint_8 ip) const
|
---|
377 | {
|
---|
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);
|
---|
401 | }
|
---|
402 |
|
---|
403 |
|
---|
404 | // ----------------------------------------------------
|
---|
405 | // Impression, etc ...
|
---|
406 | // ----------------------------------------------------
|
---|
407 |
|
---|
408 | //! Show infos on stream \b os (\b si to display DvList)
|
---|
409 | void BaseArray::Show(ostream& os, bool si) const
|
---|
410 | {
|
---|
411 | if (ndim_ < 1) {
|
---|
412 | os << "\n--- " << BaseArray::InfoString() << " Unallocated Array ! " << endl;
|
---|
413 | return;
|
---|
414 | }
|
---|
415 | os << "\n--- " << InfoString() ;
|
---|
416 | os << " ND=" << ndim_ << " SizeX*Y*...= " ;
|
---|
417 | for(int k=0; k<ndim_; k++) {
|
---|
418 | os << size_[k];
|
---|
419 | if (k<ndim_-1) os << "x";
|
---|
420 | }
|
---|
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;
|
---|
434 |
|
---|
435 | }
|
---|
436 |
|
---|
437 | //! Return BaseArray Type
|
---|
438 | string BaseArray::InfoString() const
|
---|
439 | {
|
---|
440 | string rs = "BaseArray Type= ";
|
---|
441 | rs += typeid(*this).name() ;
|
---|
442 | return rs;
|
---|
443 | }
|
---|
444 |
|
---|
445 | //! Return attached DVList
|
---|
446 | DVList& BaseArray::Info()
|
---|
447 | {
|
---|
448 | if (mInfo == NULL) mInfo = new DVList;
|
---|
449 | return(*mInfo);
|
---|
450 | }
|
---|
451 |
|
---|
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 | */
|
---|
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;
|
---|
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
|
---|
499 | // Update OK
|
---|
500 | ndim_ = ndim;
|
---|
501 | return true;
|
---|
502 | }
|
---|
503 |
|
---|
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 | */
|
---|
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;
|
---|
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
|
---|
556 | // Update OK
|
---|
557 | ndim_ = ndim;
|
---|
558 | return true;
|
---|
559 | }
|
---|
560 |
|
---|
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 | */
|
---|
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_;
|
---|
601 | veceli_ = a.veceli_;
|
---|
602 | ck_memo_vt_ = a.ck_memo_vt_;
|
---|
603 | // Update OK
|
---|
604 | ndim_ = a.ndim_;
|
---|
605 | return true;
|
---|
606 | }
|
---|
607 |
|
---|
608 |
|
---|
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 | */
|
---|
618 | void BaseArray::UpdateSubArraySizes(BaseArray & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step) const
|
---|
619 | {
|
---|
620 | if ( (ndim > ndim_) || (ndim < 1) )
|
---|
621 | throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) NDim Error") );
|
---|
622 | int k;
|
---|
623 | for(k=0; k<ndim; k++)
|
---|
624 | if ( (siz[k]*step[k]+pos[k]) > size_[k] )
|
---|
625 | throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) Size/Pos Error") );
|
---|
626 | uint_8 offset = offset_;
|
---|
627 | for(k=0; k<ndim_; k++) {
|
---|
628 | offset += pos[k]*step_[k];
|
---|
629 | step[k] *= step_[k];
|
---|
630 | }
|
---|
631 | string exm = "BaseArray::UpdateSubArraySizes() ";
|
---|
632 | if (!ra.UpdateSizes(ndim, siz, step, offset, exm))
|
---|
633 | throw( ParmError(exm) );
|
---|
634 | return;
|
---|
635 | }
|
---|
636 |
|
---|
637 |
|
---|