Array.cxx
1 // Copyright (C) 2010 Lin Wu
2 // Copyright (C) 2001-2009 Vivien Mallet
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_FILE_ARRAY_CXX
22 
23 
24 namespace Seldon
25 {
26 
27  /****************
28  * CONSTRUCTORS *
29  ****************/
30 
31 
33 
36  template <class T, int N, class Allocator>
38  {
39  if (N < ARRAY_MINRANK || N > ARRAY_MAXRANK)
40  {
41  string msg = string("Array dimension should be in [") +
42  to_str(ARRAY_MINRANK) + string(", ") + to_str(ARRAY_MAXRANK) + "].";
43  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)", msg);
44  }
45 
46  data_ = NULL;
47  for (int k = 0; k < N; k++)
48  {
49  length_[k] = 0;
50  offset_[k] = 0;
51  }
52  }
53 
54 
56 
61  template <class T, int N, class Allocator>
62  Array<T, N, Allocator>::Array(int i, int j, int k)
63  {
64  if (N != 3)
65  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
66  "Array dimension should be 3.");
67 
68  long nb_elt = long(i) * long(j) * long(k);
69 
70 #ifdef SELDON_CHECK_MEMORY
71  try
72  {
73 #endif
74 
75  data_ = Allocator::allocate(nb_elt, this);
76 
77 #ifdef SELDON_CHECK_MEMORY
78  }
79  catch (...)
80  {
81  data_ = NULL;
82  }
83  if (data_ == NULL && i != 0 && j != 0 && k != 0)
84  throw NoMemory("Array::Array(int, ...)",
85  string("Unable to allocate memory for an array of size ")
86  + to_str(static_cast<long int>(i)
87  * static_cast<long int>(j)
88  * static_cast<long int>(k)
89  * static_cast<long int>(sizeof(T)))
90  + " bytes (" + to_str(i) + " x " + to_str(j)
91  + " x " + to_str(k) + " elements).");
92 #endif
93 
94  length_[0] = i;
95  length_[1] = j;
96  length_[2] = k;
97  offset_[0] = long(j) * long(k);
98  offset_[1] = k;
99  offset_[2] = nb_elt;
100 
101  }
102 
103 
105 
111  template <class T, int N, class Allocator>
112  Array<T, N, Allocator>::Array(int i, int j, int k, int l)
113  {
114  if (N != 4)
115  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
116  "Array dimension should be 4.");
117 
118  long nb_elt = long(i) * long(j) * long(k) * long(l);
119 
120 #ifdef SELDON_CHECK_MEMORY
121  try
122  {
123 #endif
124 
125  data_ = Allocator::allocate(nb_elt, this);
126 
127 #ifdef SELDON_CHECK_MEMORY
128  }
129  catch (...)
130  {
131  data_ = NULL;
132  }
133  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0)
134  throw NoMemory("Array::Array(int, ...)",
135  string("Unable to allocate memory for an array of size ")
136  + to_str(static_cast<long int>(i)
137  * static_cast<long int>(j)
138  * static_cast<long int>(k)
139  * static_cast<long int>(l)
140  * static_cast<long int>(sizeof(T)))
141  + " bytes (" + to_str(i) + " x " + to_str(j)
142  + " x " + to_str(k) + " x " + to_str(l) + " elements).");
143 #endif
144 
145  length_[0] = i;
146  length_[1] = j;
147  length_[2] = k;
148  length_[3] = l;
149  offset_[0] = long(j) * long(k) * long(l);
150  offset_[1] = long(k) * long(l);
151  offset_[2] = long(l);
152  offset_[3] = nb_elt;
153 
154  }
155 
156 
158 
165  template <class T, int N, class Allocator>
166  Array<T, N, Allocator>::Array(int i, int j, int k, int l, int m)
167  {
168  if (N != 5)
169  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
170  "Array dimension should be 5.");
171 
172  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m);
173 
174 #ifdef SELDON_CHECK_MEMORY
175  try
176  {
177 #endif
178 
179  data_ = Allocator::allocate(nb_elt, this);
180 
181 #ifdef SELDON_CHECK_MEMORY
182  }
183  catch (...)
184  {
185  data_ = NULL;
186  }
187  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0)
188  throw NoMemory("Array::Array(int, ...)",
189  string("Unable to allocate memory for an array of size ")
190  + to_str(static_cast<long int>(i)
191  * static_cast<long int>(j)
192  * static_cast<long int>(k)
193  * static_cast<long int>(l)
194  * static_cast<long int>(m)
195  * static_cast<long int>(sizeof(T)))
196  + " bytes (" + to_str(i) + " x " + to_str(j)
197  + " x " + to_str(k) + " x " + to_str(l) + " x "
198  + to_str(m) + " elements).");
199 #endif
200 
201  length_[0] = i;
202  length_[1] = j;
203  length_[2] = k;
204  length_[3] = l;
205  length_[4] = m;
206  offset_[0] = long(j) * long(k) * long(l) * long(m);
207  offset_[1] = long(k) * long(l) * long(m);
208  offset_[2] = long(l) * long(m);
209  offset_[3] = m;
210  offset_[4] = nb_elt;
211 
212  }
213 
214 
216 
224  template <class T, int N, class Allocator>
226  ::Array(int i, int j, int k, int l, int m, int n)
227  {
228  if (N != 6)
229  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
230  "Array dimension should be 6.");
231 
232  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m) * long(n);
233 
234 #ifdef SELDON_CHECK_MEMORY
235  try
236  {
237 #endif
238 
239  data_ = Allocator::allocate(nb_elt, this);
240 
241 #ifdef SELDON_CHECK_MEMORY
242  }
243  catch (...)
244  {
245  data_ = NULL;
246  }
247 
248  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
249  n != 0)
250  throw NoMemory("Array::Array(int, ...)",
251  string("Unable to allocate memory for an array of size ")
252  + to_str(static_cast<long int>(i)
253  * static_cast<long int>(j)
254  * static_cast<long int>(k)
255  * static_cast<long int>(l)
256  * static_cast<long int>(m)
257  * static_cast<long int>(n)
258  * static_cast<long int>(sizeof(T)))
259  + " bytes (" + to_str(i) + " x " + to_str(j)
260  + " x " + to_str(k) + " x " + to_str(l) + " x " +
261  to_str(m) + " x " + to_str(n) + " elements).");
262 #endif
263 
264  length_[0] = i;
265  length_[1] = j;
266  length_[2] = k;
267  length_[3] = l;
268  length_[4] = m;
269  length_[5] = n;
270 
271  offset_[4] = n;
272  offset_[3] = long(m) * long(n);
273  offset_[2] = long(l) * offset_[3];
274  offset_[1] = long(k) * offset_[2];
275  offset_[0] = long(j) * offset_[1];
276  offset_[5] = nb_elt;
277 
278  }
279 
280 
282 
292  template <class T, int N, class Allocator>
294  ::Array(int i, int j, int k, int l, int m, int n, int o)
295  {
296  if (N != 7)
297  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
298  "Array dimension should be 7.");
299 
300  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m)
301  * long(n) * long(o);
302 
303 #ifdef SELDON_CHECK_MEMORY
304  try
305  {
306 #endif
307 
308  data_ = Allocator::allocate(nb_elt, this);
309 
310 #ifdef SELDON_CHECK_MEMORY
311  }
312  catch (...)
313  {
314  data_ = NULL;
315  }
316  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
317  n != 0 && o != 0)
318  throw NoMemory("Array::Array(int, ...)",
319  string("Unable to allocate memory for an array of size ")
320  + to_str(static_cast<long int>(i)
321  * static_cast<long int>(j)
322  * static_cast<long int>(k)
323  * static_cast<long int>(l)
324  * static_cast<long int>(m)
325  * static_cast<long int>(n)
326  * static_cast<long int>(o)
327  * static_cast<long int>(sizeof(T)))
328  + " bytes (" + to_str(i) + " x " + to_str(j)
329  + " x " + to_str(k) + " x " + to_str(l) + " x " +
330  to_str(m) + " x " + to_str(n) + " x " + to_str(o) +
331  " elements).");
332 #endif
333 
334  length_[0] = i;
335  length_[1] = j;
336  length_[2] = k;
337  length_[3] = l;
338  length_[4] = m;
339  length_[5] = n;
340  length_[6] = o;
341 
342  offset_[5] = o;
343  offset_[4] = long(n) * long(o);
344  offset_[3] = long(m) * offset_[4];
345  offset_[2] = long(l) * offset_[3];
346  offset_[1] = long(k) * offset_[2];
347  offset_[0] = long(j) * offset_[1];
348  offset_[6] = nb_elt;
349  }
350 
351 
353 
364  template <class T, int N, class Allocator>
366  ::Array(int i, int j, int k, int l, int m, int n, int o, int p)
367  {
368  if (N != 8)
369  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
370  "Array dimension should be 8.");
371 
372  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m)
373  * long(n) * long(o) * long(p);
374 
375 #ifdef SELDON_CHECK_MEMORY
376  try
377  {
378 #endif
379 
380  data_ = Allocator::allocate(nb_elt, this);
381 
382 #ifdef SELDON_CHECK_MEMORY
383  }
384  catch (...)
385  {
386  data_ = NULL;
387  }
388  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
389  n != 0 && o != 0 && p != 0)
390  throw NoMemory("Array::Array(int, ...)",
391  string("Unable to allocate memory for an array of size ")
392  + to_str(static_cast<long int>(i)
393  * static_cast<long int>(j)
394  * static_cast<long int>(k)
395  * static_cast<long int>(l)
396  * static_cast<long int>(m)
397  * static_cast<long int>(n)
398  * static_cast<long int>(o)
399  * static_cast<long int>(p)
400  * static_cast<long int>(sizeof(T)))
401  + " bytes (" + to_str(i) + " x " + to_str(j)
402  + " x " + to_str(k) + " x " + to_str(l) + " x " +
403  to_str(m) + " x " + to_str(n) + " x " + to_str(o)
404  + " x " + to_str(p) + " elements).");
405 #endif
406 
407  length_[0] = i;
408  length_[1] = j;
409  length_[2] = k;
410  length_[3] = l;
411  length_[4] = m;
412  length_[5] = n;
413  length_[6] = o;
414  length_[7] = p;
415 
416  offset_[6] = p;
417  offset_[5] = long(o) * long(p);
418  offset_[4] = long(n) * offset_[5];
419  offset_[3] = long(m) * offset_[4];
420  offset_[2] = long(l) * offset_[3];
421  offset_[1] = long(k) * offset_[2];
422  offset_[0] = long(j) * offset_[1];
423  offset_[7] = nb_elt;
424 
425  }
426 
427 
429 
441  template <class T, int N, class Allocator>
443  ::Array(int i, int j, int k, int l, int m, int n, int o, int p, int q)
444  {
445  if (N != 9)
446  throw WrongDim("Array<T, N, Allocator>::Array(int, ...)",
447  "Array dimension should be 9.");
448 
449  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m)
450  * long(n) * long(o) * long(p) * long(q);
451 
452 #ifdef SELDON_CHECK_MEMORY
453  try
454  {
455 #endif
456 
457  data_ = Allocator::allocate(nb_elt, this);
458 
459 #ifdef SELDON_CHECK_MEMORY
460  }
461  catch (...)
462  {
463  data_ = NULL;
464  }
465  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
466  n != 0 && o != 0 && p != 0 && q != 0)
467  throw NoMemory("Array::Array(int, ...)",
468  string("Unable to allocate memory for an array of size ")
469  + to_str(static_cast<long int>(i)
470  * static_cast<long int>(j)
471  * static_cast<long int>(k)
472  * static_cast<long int>(l)
473  * static_cast<long int>(m)
474  * static_cast<long int>(n)
475  * static_cast<long int>(o)
476  * static_cast<long int>(p)
477  * static_cast<long int>(q)
478  * static_cast<long int>(sizeof(T)))
479  + " bytes (" + to_str(i) + " x " + to_str(j)
480  + " x " + to_str(k) + " x " + to_str(l) + " x " +
481  to_str(m) + " x " + to_str(n) + " x " + to_str(o) + " x "
482  + to_str(p) + " x " + to_str(q) + " elements).");
483 #endif
484 
485  length_[0] = i;
486  length_[1] = j;
487  length_[2] = k;
488  length_[3] = l;
489  length_[4] = m;
490  length_[5] = n;
491  length_[6] = o;
492  length_[7] = p;
493  length_[8] = q;
494 
495  offset_[7] = q;
496  offset_[6] = long(p) * long(q);
497  offset_[5] = long(o) * offset_[6];
498  offset_[4] = long(n) * offset_[5];
499  offset_[3] = long(m) * offset_[4];
500  offset_[2] = long(l) * offset_[3];
501  offset_[1] = long(k) * offset_[2];
502  offset_[0] = long(j) * offset_[1];
503  offset_[8] = nb_elt;
504 
505  }
506 
507 
509  template <class T, int N, class Allocator>
511  {
512  data_ = NULL;
513 
514  Copy(A);
515  }
516 
517 
518  /*********************
519  * MEMORY MANAGEMENT *
520  *********************/
521 
522 
524 
531  template <class T, int N, class Allocator>
532  void Array<T, N, Allocator>::Reallocate(int i, int j, int k)
533  {
534  if (N != 3)
535  throw WrongDim("Array::Reallocate(int, ...)",
536  "Array dimension should be 3.");
537 
538  long nb_elt = long(i) * long(j) * long(k);
539 
540  if (length_ == NULL || i != length_[0] || j != length_[1]
541  || k != length_[2])
542  {
543 
544 #ifdef SELDON_CHECK_MEMORY
545  try
546  {
547 #endif
548 
549  data_ =
550  reinterpret_cast<pointer>(Allocator::reallocate(data_,
551  nb_elt,
552  this));
553 
554 #ifdef SELDON_CHECK_MEMORY
555  }
556  catch (...)
557  {
558  data_ = NULL;
559  }
560  if (data_ == NULL && i != 0 && j != 0 && k != 0)
561  throw NoMemory("Array::Reallocate(int, ...)",
562  string("Unable to reallocate memory")
563  + " for an array of size "
564  + to_str(static_cast<long int>(i)
565  * static_cast<long int>(j)
566  * static_cast<long int>(k)
567  * static_cast<long int>(sizeof(T)))
568  + " bytes (" + to_str(i) + " x " + to_str(j)
569  + " x " + to_str(k) + " elements).");
570 #endif
571 
572  length_[0] = i;
573  length_[1] = j;
574  length_[2] = k;
575  offset_[0] = long(j) * long(k);
576  offset_[1] = k;
577  offset_[2] = nb_elt;
578  }
579  }
580 
581 
583 
591  template <class T, int N, class Allocator>
592  void Array<T, N, Allocator>::Reallocate(int i, int j, int k, int l)
593  {
594  if (N != 4)
595  throw WrongDim("Array::Reallocate(int, ...)",
596  "Array dimension should be 4.");
597 
598  long nb_elt = long(i) * long(j) * long(k) * long(l);
599 
600  if (length_ == NULL || i != length_[0] || j != length_[1]
601  || k != length_[2] || l != length_[3])
602  {
603 
604 #ifdef SELDON_CHECK_MEMORY
605  try
606  {
607 #endif
608 
609  data_ =
610  reinterpret_cast<pointer>(Allocator::reallocate(data_,
611  nb_elt,
612  this));
613 
614 #ifdef SELDON_CHECK_MEMORY
615  }
616  catch (...)
617  {
618  data_ = NULL;
619  }
620  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0)
621  throw NoMemory("Array::Reallocate(int, ...)",
622  string("Unable to reallocate memory")
623  + " for an array of size "
624  + to_str(static_cast<long int>(i)
625  * static_cast<long int>(j)
626  * static_cast<long int>(k)
627  * static_cast<long int>(l)
628  * static_cast<long int>(sizeof(T)))
629  + " bytes (" + to_str(i) + " x " + to_str(j)
630  + " x " + to_str(k) + " x " + to_str(l)
631  + " elements).");
632 #endif
633 
634  length_[0] = i;
635  length_[1] = j;
636  length_[2] = k;
637  length_[3] = l;
638  offset_[0] = long(j) * long(k) * long(l);
639  offset_[1] = long(k) * long(l);
640  offset_[2] = long(l);
641  offset_[3] = nb_elt;
642  }
643  }
644 
645 
647 
656  template <class T, int N, class Allocator>
658  ::Reallocate(int i, int j, int k, int l, int m)
659  {
660  if (N != 5)
661  throw WrongDim("Array::Reallocate(int, ...)",
662  "Array dimension should be 5.");
663 
664  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m);
665 
666  if (length_ == NULL || i != length_[0] || j != length_[1]
667  || k != length_[2] || l != length_[3] || m != length_[4])
668  {
669 
670 #ifdef SELDON_CHECK_MEMORY
671  try
672  {
673 #endif
674 
675  data_ =
676  reinterpret_cast<pointer>(Allocator::reallocate(data_,
677  nb_elt,
678  this));
679 
680 #ifdef SELDON_CHECK_MEMORY
681  }
682  catch (...)
683  {
684  data_ = NULL;
685  }
686  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0)
687  throw NoMemory("Array::Reallocate(int, ...)",
688  string("Unable to reallocate memory")
689  + " for an array of size "
690  + to_str(static_cast<long int>(i)
691  * static_cast<long int>(j)
692  * static_cast<long int>(k)
693  * static_cast<long int>(l)
694  * static_cast<long int>(m)
695  * static_cast<long int>(sizeof(T)))
696  + " bytes (" + to_str(i) + " x " + to_str(j)
697  + " x " + to_str(k) + " x " + to_str(l)
698  + " x " + to_str(m) + " elements).");
699 #endif
700 
701  length_[0] = i;
702  length_[1] = j;
703  length_[2] = k;
704  length_[3] = l;
705  length_[4] = m;
706  offset_[0] = long(j) * long(k) * long(l) * long(m);
707  offset_[1] = long(k) * long(l) * long(m);
708  offset_[2] = long(l) * long(m);
709  offset_[3] = m;
710  offset_[4] = nb_elt;
711  }
712  }
713 
714 
716 
726  template <class T, int N, class Allocator>
728  ::Reallocate(int i, int j, int k, int l, int m, int n)
729  {
730  if (N != 6)
731  throw WrongDim("Array::Reallocate(int, ...)",
732  "Array dimension should be 6.");
733 
734  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m) * long(n);
735 
736  if (length_ == NULL || i != length_[0] || j != length_[1]
737  || k != length_[2] || l != length_[3] || m != length_[4]
738  || n != length_[5])
739  {
740 
741 #ifdef SELDON_CHECK_MEMORY
742  try
743  {
744 #endif
745 
746  data_ =
747  reinterpret_cast<pointer>(Allocator::reallocate(data_,
748  nb_elt,
749  this));
750 
751 #ifdef SELDON_CHECK_MEMORY
752  }
753  catch (...)
754  {
755  data_ = NULL;
756  }
757  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
758  n != 0)
759  throw NoMemory("Array::Reallocate(int, ...)",
760  string("Unable to reallocate memory")
761  + " for an array of size "
762  + to_str(static_cast<long int>(i)
763  * static_cast<long int>(j)
764  * static_cast<long int>(k)
765  * static_cast<long int>(l)
766  * static_cast<long int>(m)
767  * static_cast<long int>(n)
768  * static_cast<long int>(sizeof(T)))
769  + " bytes (" + to_str(i) + " x " + to_str(j)
770  + " x " + to_str(k) + " x " + to_str(l)
771  + " x " + to_str(m) + " x " + to_str(n)
772  + " elements).");
773 #endif
774 
775  length_[0] = i;
776  length_[1] = j;
777  length_[2] = k;
778  length_[3] = l;
779  length_[4] = m;
780  length_[5] = n;
781 
782  offset_[4] = n;
783  offset_[3] = long(m) * long(n);
784  offset_[2] = long(l) * offset_[3];
785  offset_[1] = long(k) * offset_[2];
786  offset_[0] = long(j) * offset_[1];
787  offset_[5] = nb_elt;
788  }
789  }
790 
791 
793 
804  template <class T, int N, class Allocator>
806  ::Reallocate(int i, int j, int k, int l, int m, int n, int o)
807  {
808  if (N != 7)
809  throw WrongDim("Array::Reallocate(int, ...)",
810  "Array dimension should be 7.");
811 
812  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m)
813  * long(n) * long(o);
814 
815  if (length_ == NULL || i != length_[0] || j != length_[1]
816  || k != length_[2] || l != length_[3] || m != length_[4]
817  || n != length_[5] || o != length_[6])
818  {
819 
820 #ifdef SELDON_CHECK_MEMORY
821  try
822  {
823 #endif
824 
825  data_ =
826  reinterpret_cast<pointer>(Allocator::reallocate(data_, nb_elt, this));
827 
828 #ifdef SELDON_CHECK_MEMORY
829  }
830  catch (...)
831  {
832  data_ = NULL;
833  }
834  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
835  n != 0 && o != 0)
836  throw NoMemory("Array::Reallocate(int, ...)",
837  string("Unable to reallocate memory")
838  + " for an array of size "
839  + to_str(static_cast<long int>(i)
840  * static_cast<long int>(j)
841  * static_cast<long int>(k)
842  * static_cast<long int>(l)
843  * static_cast<long int>(m)
844  * static_cast<long int>(n)
845  * static_cast<long int>(o)
846  * static_cast<long int>(sizeof(T)))
847  + " bytes (" + to_str(i) + " x " + to_str(j)
848  + " x " + to_str(k) + " x " + to_str(l)
849  + " x " + to_str(m) + " x " + to_str(n)
850  + " x " + to_str(o) + " elements).");
851 #endif
852 
853  length_[0] = i;
854  length_[1] = j;
855  length_[2] = k;
856  length_[3] = l;
857  length_[4] = m;
858  length_[5] = n;
859  length_[6] = o;
860 
861  offset_[5] = o;
862  offset_[4] = long(n) * long(o);
863  offset_[3] = long(m) * offset_[4];
864  offset_[2] = long(l) * offset_[3];
865  offset_[1] = long(k) * offset_[2];
866  offset_[0] = long(j) * offset_[1];
867  offset_[6] = nb_elt;
868  }
869  }
870 
871 
873 
885  template <class T, int N, class Allocator>
887  ::Reallocate(int i, int j, int k, int l, int m, int n, int o, int p)
888  {
889  if (N != 8)
890  throw WrongDim("Array::Reallocate(int, ...)",
891  "Array dimension should be 8.");
892 
893  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m)
894  * long(n) * long(o) * long(p);
895 
896  if (length_ == NULL || i != length_[0] || j != length_[1]
897  || k != length_[2] || l != length_[3] || m != length_[4]
898  || n != length_[5] || o != length_[6] || p != length_[7])
899  {
900 
901 #ifdef SELDON_CHECK_MEMORY
902  try
903  {
904 #endif
905  data_ =
906  reinterpret_cast<pointer>(Allocator::reallocate(data_, nb_elt, this));
907 
908 
909 #ifdef SELDON_CHECK_MEMORY
910  }
911  catch (...)
912  {
913  data_ = NULL;
914  }
915  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
916  n != 0 && o != 0 && p != 0)
917  throw NoMemory("Array::Reallocate(int, ...)",
918  string("Unable to reallocate memory")
919  + " for an array of size "
920  + to_str(static_cast<long int>(i)
921  * static_cast<long int>(j)
922  * static_cast<long int>(k)
923  * static_cast<long int>(l)
924  * static_cast<long int>(m)
925  * static_cast<long int>(n)
926  * static_cast<long int>(o)
927  * static_cast<long int>(p)
928  * static_cast<long int>(sizeof(T)))
929  + " bytes (" + to_str(i) + " x " + to_str(j)
930  + " x " + to_str(k) + " x " + to_str(l)
931  + " x " + to_str(m) + " x " + to_str(n)
932  + " x " + to_str(o) + " x " + to_str(p)
933  + " elements).");
934 #endif
935 
936  length_[0] = i;
937  length_[1] = j;
938  length_[2] = k;
939  length_[3] = l;
940  length_[4] = m;
941  length_[5] = n;
942  length_[6] = o;
943  length_[7] = p;
944 
945  offset_[6] = p;
946  offset_[5] = long(o) * long(p);
947  offset_[4] = long(n) * offset_[5];
948  offset_[3] = long(m) * offset_[4];
949  offset_[2] = long(l) * offset_[3];
950  offset_[1] = long(k) * offset_[2];
951  offset_[0] = long(j) * offset_[1];
952  offset_[7] = nb_elt;
953  }
954  }
955 
956 
958 
971  template <class T, int N, class Allocator>
973  ::Reallocate(int i, int j, int k, int l, int m, int n, int o, int p, int q)
974  {
975  if (N != 9)
976  throw WrongDim("Array::Reallocate(int, ...)",
977  "Array dimension should be 9.");
978 
979  long nb_elt = long(i) * long(j) * long(k) * long(l) * long(m)
980  * long(n) * long(o) * long(p) * long(q);
981 
982  if (length_ == NULL || i != length_[0] || j != length_[1]
983  || k != length_[2] || l != length_[3] || m != length_[4]
984  || n != length_[5] || o != length_[6] || p != length_[7]
985  || q != length_[8])
986  {
987 
988 #ifdef SELDON_CHECK_MEMORY
989  try
990  {
991 #endif
992 
993  data_ =
994  reinterpret_cast<pointer>(Allocator::reallocate(data_, nb_elt, this));
995 
996 #ifdef SELDON_CHECK_MEMORY
997  }
998  catch (...)
999  {
1000  data_ = NULL;
1001  }
1002  if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0 && m != 0 &&
1003  n != 0 && o != 0 && p != 0 && q != 0)
1004  throw NoMemory("Array::Reallocate(int, ...)",
1005  string("Unable to reallocate memory")
1006  + " for an array of size "
1007  + to_str(static_cast<long int>(i)
1008  * static_cast<long int>(j)
1009  * static_cast<long int>(k)
1010  * static_cast<long int>(l)
1011  * static_cast<long int>(m)
1012  * static_cast<long int>(n)
1013  * static_cast<long int>(o)
1014  * static_cast<long int>(p)
1015  * static_cast<long int>(q)
1016  * static_cast<long int>(sizeof(T)))
1017  + " bytes (" + to_str(i) + " x " + to_str(j)
1018  + " x " + to_str(k) + " x " + to_str(l)
1019  + " x " + to_str(m) + " x " + to_str(n)
1020  + " x " + to_str(o) + " x " + to_str(p)
1021  + " x " + to_str(q) + " elements).");
1022 #endif
1023 
1024  length_[0] = i;
1025  length_[1] = j;
1026  length_[2] = k;
1027  length_[3] = l;
1028  length_[4] = m;
1029  length_[5] = n;
1030  length_[6] = o;
1031  length_[7] = p;
1032  length_[8] = q;
1033 
1034  offset_[7] = q;
1035  offset_[6] = long(p) * long(q);
1036  offset_[5] = long(o) * offset_[6];
1037  offset_[4] = long(n) * offset_[5];
1038  offset_[3] = long(m) * offset_[4];
1039  offset_[2] = long(l) * offset_[3];
1040  offset_[1] = long(k) * offset_[2];
1041  offset_[0] = long(j) * offset_[1];
1042  offset_[8] = nb_elt;
1043  }
1044  }
1045 
1046 
1048 
1052  template <class T, int N, class Allocator>
1054  {
1055 
1056 #ifdef SELDON_CHECK_MEMORY
1057  try
1058  {
1059 #endif
1060 
1061  if (data_ != NULL)
1062  {
1063  Allocator::deallocate(data_, offset_[N-1]);
1064  data_ = NULL;
1065  }
1066 
1067 #ifdef SELDON_CHECK_MEMORY
1068  }
1069  catch (...)
1070  {
1071  data_ = NULL;
1072  }
1073 #endif
1074 
1075  }
1076 
1077 
1079 
1084  template <class T, int N, class Allocator>
1086  {
1087  if (N == 3)
1088  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2));
1089  if (N == 4)
1090  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2),
1091  A.GetLength(3));
1092  if (N == 5)
1093  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2),
1094  A.GetLength(3), A.GetLength(4));
1095  if (N == 6)
1096  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2),
1097  A.GetLength(3), A.GetLength(4), A.GetLength(5));
1098  if (N == 7)
1099  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2),
1100  A.GetLength(3), A.GetLength(4), A.GetLength(5),
1101  A.GetLength(6));
1102  if (N == 8)
1103  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2),
1104  A.GetLength(3), A.GetLength(4), A.GetLength(5),
1105  A.GetLength(6), A.GetLength(7));
1106  if (N == 9)
1107  Reallocate(A.GetLength(0), A.GetLength(1), A.GetLength(2),
1108  A.GetLength(3), A.GetLength(4), A.GetLength(5),
1109  A.GetLength(6), A.GetLength(7), A.GetLength(8));
1110 
1111  Allocator::memorycpy(data_, A.GetData(), GetDataSize());
1112  }
1113 
1114 
1115  /************************
1116  * CONVENIENT FUNCTIONS *
1117  ************************/
1118 
1119 
1121 
1125  template <class T, int N, class Allocator>
1127  {
1128  size_t taille = sizeof(*this);
1129  taille += size_t(sizeof(T))*GetDataSize();
1130  return taille;
1131  }
1132 
1133 
1135 
1139  template <class T, int N, class Allocator>
1141  {
1142  Allocator::memoryset(data_, char(0),
1143  GetDataSize()*sizeof(value_type));
1144  }
1145 
1146 
1148 
1152  template <class T, int N, class Allocator>
1154  {
1155  for (long i = 0; i < GetDataSize(); i++)
1156  SetComplexReal(i, data_[i]);
1157  }
1158 
1159 
1161 
1165  template <class T, int N, class Allocator>
1166  template <class T0>
1168  {
1169  T x_;
1170  SetComplexReal(x, x_);
1171  for (long i = 0; i < GetDataSize(); i++)
1172  data_[i] = x_;
1173  }
1174 
1175 
1177 
1180  template <class T, int N, class Allocator>
1182  {
1183 #ifndef SELDON_WITHOUT_REINIT_RANDOM
1184  srand(time(NULL));
1185 #endif
1186  for (long i = 0; i < GetDataSize(); i++)
1187  SetComplexReal(rand(), this->data_[i]);
1188  }
1189 
1190 
1192 
1195  template <class T, int N, class Allocator>
1197  {
1198  if (N == 3)
1199  {
1200  int i, j, k;
1201  for (i = 0; i < GetLength(0); i++)
1202  {
1203  for (j = 0; j < GetLength(1); j++)
1204  {
1205  for (k = 0; k < GetLength(2); k++)
1206  cout << (*this)(i, j, k) << '\t';
1207  cout << endl;
1208  }
1209  cout << endl;
1210  }
1211  }
1212 
1213  if (N == 4)
1214  {
1215  int i, j, k, l;
1216  for (i = 0; i < GetLength(0); i++)
1217  {
1218  for (j = 0; j < GetLength(1); j++)
1219  {
1220  for (k = 0; k < GetLength(2); k++)
1221  {
1222  for (l = 0; l < GetLength(3); l++)
1223  cout << (*this)(i, j, k, l) << '\t';
1224  cout << endl;
1225  }
1226  cout << endl;
1227  }
1228  cout << endl;
1229  }
1230  }
1231 
1232  if (N == 5)
1233  {
1234  int i, j, k, l, m;
1235  for (i = 0; i < GetLength(0); i++)
1236  {
1237  for (j = 0; j < GetLength(1); j++)
1238  {
1239  for (k = 0; k < GetLength(2); k++)
1240  {
1241  for (l = 0; l < GetLength(3); l++)
1242  {
1243  for (m = 0; m < GetLength(4); m++)
1244  cout << (*this)(i, j, k, l, m) << '\t';
1245  cout << endl;
1246  }
1247  cout << endl;
1248  }
1249  cout << endl;
1250  }
1251  cout << endl;
1252  }
1253  }
1254 
1255  if (N == 6)
1256  {
1257  int i, j, k, l, m, n;
1258  for (i = 0; i < GetLength(0); i++)
1259  {
1260  for (j = 0; j < GetLength(1); j++)
1261  {
1262  for (k = 0; k < GetLength(2); k++)
1263  {
1264  for (l = 0; l < GetLength(3); l++)
1265  {
1266  for (m = 0; m < GetLength(4); m++)
1267  {
1268  for (n = 0; n < GetLength(5); n++)
1269  cout << (*this)(i, j, k, l, m, n) << '\t';
1270  cout << endl;
1271  }
1272  cout << endl;
1273  }
1274  cout << endl;
1275  }
1276  cout << endl;
1277  }
1278  cout << endl;
1279  }
1280  }
1281 
1282  if (N == 7)
1283  {
1284  int i, j, k, l, m, n, o;
1285  for (i = 0; i < GetLength(0); i++)
1286  {
1287  for (j = 0; j < GetLength(1); j++)
1288  {
1289  for (k = 0; k < GetLength(2); k++)
1290  {
1291  for (l = 0; l < GetLength(3); l++)
1292  {
1293  for (m = 0; m < GetLength(4); m++)
1294  {
1295  for (n = 0; n < GetLength(5); n++)
1296  {
1297  for (o = 0; o < GetLength(6); o++)
1298  cout << (*this)(i, j, k, l, m, n, o)
1299  << '\t';
1300  cout << endl;
1301  }
1302  cout << endl;
1303  }
1304  cout << endl;
1305  }
1306  cout << endl;
1307  }
1308  cout << endl;
1309  }
1310  cout << endl;
1311  }
1312  }
1313 
1314  if (N == 8)
1315  {
1316  int i, j, k, l, m, n, o, p;
1317  for (i = 0; i < GetLength(0); i++)
1318  {
1319  for (j = 0; j < GetLength(1); j++)
1320  {
1321  for (k = 0; k < GetLength(2); k++)
1322  {
1323  for (l = 0; l < GetLength(3); l++)
1324  {
1325  for (m = 0; m < GetLength(4); m++)
1326  {
1327  for (n = 0; n < GetLength(5); n++)
1328  {
1329  for (o = 0; o < GetLength(6); o++)
1330  {
1331  for (p = 0; p < GetLength(7); p++)
1332  cout << (*this)(i, j, k, l, m, n, o, p)
1333  << '\t';
1334  cout << endl;
1335  }
1336  cout << endl;
1337  }
1338  cout << endl;
1339  }
1340  cout << endl;
1341  }
1342  cout << endl;
1343  }
1344  cout << endl;
1345  }
1346  cout << endl;
1347  }
1348  }
1349 
1350  if (N == 9)
1351  {
1352  int i, j, k, l, m, n, o, p, q;
1353  for (i = 0; i < GetLength(0); i++)
1354  {
1355  for (j = 0; j < GetLength(1); j++)
1356  {
1357  for (k = 0; k < GetLength(2); k++)
1358  {
1359  for (l = 0; l < GetLength(3); l++)
1360  {
1361  for (m = 0; m < GetLength(4); m++)
1362  {
1363  for (n = 0; n < GetLength(5); n++)
1364  {
1365  for (o = 0; o < GetLength(6); o++)
1366  {
1367  for (p = 0; p < GetLength(7); p++)
1368  {
1369  for (q = 0; q < GetLength(8); q++)
1370  cout << (*this)(i, j, k, l, m, n,
1371  o, p, q)
1372  << '\t';
1373  cout << endl;
1374  }
1375  cout << endl;
1376  }
1377  cout << endl;
1378  }
1379  cout << endl;
1380  }
1381  cout << endl;
1382  }
1383  cout << endl;
1384  }
1385  cout << endl;
1386  }
1387  cout << endl;
1388  }
1389  }
1390  }
1391 
1392 
1393  /**************************
1394  * INPUT/OUTPUT FUNCTIONS *
1395  **************************/
1396 
1397 
1399 
1405  template <class T, int N, class Allocator> void Array<T, N, Allocator>
1406  ::Write(string FileName, bool with_size) const
1407  {
1408  ofstream FileStream;
1409  FileStream.open(FileName.c_str(), ofstream::binary);
1410 
1411 #ifdef SELDON_CHECK_IO
1412  // Checks if the file was opened.
1413  if (!FileStream.is_open())
1414  throw IOError("Array::Write(string FileName)",
1415  string("Unable to open file \"") + FileName + "\".");
1416 #endif
1417 
1418  Write(FileStream, with_size);
1419 
1420  FileStream.close();
1421  }
1422 
1423 
1425 
1431  template <class T, int N, class Allocator> void Array<T, N, Allocator>
1432  ::Write(ofstream& FileStream, bool with_size) const
1433  {
1434 
1435 #ifdef SELDON_CHECK_IO
1436  // Checks if the stream is ready.
1437  if (!FileStream.good())
1438  throw IOError("Array::Write(ofstream& FileStream)",
1439  "Stream is not ready.");
1440 #endif
1441 
1442  if (with_size)
1443  {
1444  for (int i = 0; i < N; i++)
1445  FileStream.write(reinterpret_cast<char*>
1446  (const_cast<int*>(&length_[i])),
1447  sizeof(int));
1448  }
1449 
1450  FileStream.write(reinterpret_cast<char*>(data_),
1451  offset_[N - 1] * sizeof(value_type));
1452 
1453 #ifdef SELDON_CHECK_IO
1454  // Checks if data was written.
1455  if (!FileStream.good())
1456  throw IOError("Array::Write(ofstream& FileStream)",
1457  string("Output operation failed.")
1458  + string(" The output file may have been removed")
1459  + " or there is no space left on device.");
1460 #endif
1461 
1462  }
1463 
1464 
1466 
1472  template <class T, int N, class Allocator>
1473  void Array<T, N, Allocator>::Read(string FileName, bool with_size)
1474  {
1475  ifstream FileStream;
1476  FileStream.open(FileName.c_str(), ifstream::binary);
1477 
1478 #ifdef SELDON_CHECK_IO
1479  // Checks if the file was opened.
1480  if (!FileStream.is_open())
1481  throw IOError("Array::Read(string FileName)",
1482  string("Unable to open file \"") + FileName + "\".");
1483 #endif
1484 
1485  Read(FileStream, with_size);
1486 
1487  FileStream.close();
1488  }
1489 
1490 
1492 
1498  template <class T, int N, class Allocator>
1500  ::Read(ifstream& FileStream, bool with_size)
1501  {
1502 
1503 #ifdef SELDON_CHECK_IO
1504  // Checks if the stream is ready.
1505  if (!FileStream.good())
1506  throw IOError("Matrix_Pointers::Read(ifstream& FileStream)",
1507  "Stream is not ready.");
1508 #endif
1509 
1510  if (with_size)
1511  {
1512  if (N == 3)
1513  {
1514  int new_l1, new_l2, new_l3;
1515  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1516  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1517  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1518  Reallocate(new_l1, new_l2, new_l3);
1519  }
1520  if (N == 4)
1521  {
1522  int new_l1, new_l2, new_l3, new_l4;
1523  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1524  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1525  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1526  FileStream.read(reinterpret_cast<char*>(&new_l4), sizeof(int));
1527  Reallocate(new_l1, new_l2, new_l3, new_l4);
1528  }
1529  if (N == 5)
1530  {
1531  int new_l1, new_l2, new_l3, new_l4, new_l5;
1532  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1533  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1534  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1535  FileStream.read(reinterpret_cast<char*>(&new_l4), sizeof(int));
1536  FileStream.read(reinterpret_cast<char*>(&new_l5), sizeof(int));
1537  Reallocate(new_l1, new_l2, new_l3, new_l4, new_l5);
1538  }
1539  if (N == 6)
1540  {
1541  int new_l1, new_l2, new_l3, new_l4, new_l5, new_l6;
1542  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1543  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1544  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1545  FileStream.read(reinterpret_cast<char*>(&new_l4), sizeof(int));
1546  FileStream.read(reinterpret_cast<char*>(&new_l5), sizeof(int));
1547  FileStream.read(reinterpret_cast<char*>(&new_l6), sizeof(int));
1548  Reallocate(new_l1, new_l2, new_l3, new_l4, new_l5, new_l6);
1549  }
1550  if (N == 7)
1551  {
1552  int new_l1, new_l2, new_l3, new_l4, new_l5, new_l6, new_l7;
1553  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1554  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1555  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1556  FileStream.read(reinterpret_cast<char*>(&new_l4), sizeof(int));
1557  FileStream.read(reinterpret_cast<char*>(&new_l5), sizeof(int));
1558  FileStream.read(reinterpret_cast<char*>(&new_l6), sizeof(int));
1559  FileStream.read(reinterpret_cast<char*>(&new_l7), sizeof(int));
1560  Reallocate(new_l1, new_l2, new_l3, new_l4, new_l5, new_l6,
1561  new_l7);
1562  }
1563  if (N == 8)
1564  {
1565  int new_l1, new_l2, new_l3, new_l4, new_l5, new_l6, new_l7,
1566  new_l8;
1567  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1568  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1569  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1570  FileStream.read(reinterpret_cast<char*>(&new_l4), sizeof(int));
1571  FileStream.read(reinterpret_cast<char*>(&new_l5), sizeof(int));
1572  FileStream.read(reinterpret_cast<char*>(&new_l6), sizeof(int));
1573  FileStream.read(reinterpret_cast<char*>(&new_l7), sizeof(int));
1574  FileStream.read(reinterpret_cast<char*>(&new_l8), sizeof(int));
1575  Reallocate(new_l1, new_l2, new_l3, new_l4, new_l5, new_l6,
1576  new_l7, new_l8);
1577  }
1578  if (N == 9)
1579  {
1580  int new_l1, new_l2, new_l3, new_l4, new_l5, new_l6, new_l7,
1581  new_l8, new_l9;
1582  FileStream.read(reinterpret_cast<char*>(&new_l1), sizeof(int));
1583  FileStream.read(reinterpret_cast<char*>(&new_l2), sizeof(int));
1584  FileStream.read(reinterpret_cast<char*>(&new_l3), sizeof(int));
1585  FileStream.read(reinterpret_cast<char*>(&new_l4), sizeof(int));
1586  FileStream.read(reinterpret_cast<char*>(&new_l5), sizeof(int));
1587  FileStream.read(reinterpret_cast<char*>(&new_l6), sizeof(int));
1588  FileStream.read(reinterpret_cast<char*>(&new_l7), sizeof(int));
1589  FileStream.read(reinterpret_cast<char*>(&new_l8), sizeof(int));
1590  FileStream.read(reinterpret_cast<char*>(&new_l9), sizeof(int));
1591  Reallocate(new_l1, new_l2, new_l3, new_l4, new_l5, new_l6,
1592  new_l7, new_l8, new_l9);
1593  }
1594  }
1595 
1596  FileStream.read(reinterpret_cast<char*>(data_),
1597  offset_[N - 1] * sizeof(value_type));
1598 
1599 #ifdef SELDON_CHECK_IO
1600  // Checks if data was read.
1601  if (!FileStream.good())
1602  throw IOError("Array::Read(ifstream& FileStream)",
1603  string("Output operation failed.")
1604  + string(" The intput file may have been removed")
1605  + " or may not contain enough data.");
1606 #endif
1607 
1608  }
1609 
1611 
1616  template <class T, int N, class Allocator>
1617  ostream& operator << (ostream& out,
1618  const Array<T, N, Allocator>& A)
1619  {
1620  if (N == 3)
1621  {
1622  int i, j, k;
1623 
1624  for (i = 0; i < A.GetLength(0); i++)
1625  {
1626  for (j = 0; j < A.GetLength(1); j++)
1627  {
1628  for (k = 0; k < A.GetLength(2); k++)
1629  out << A(i, j, k) << '\t';
1630  out << endl;
1631  }
1632  out << endl;
1633  }
1634  }
1635 
1636  if (N == 4)
1637  {
1638  int i, j, k, l;
1639 
1640  for (i = 0; i < A.GetLength(0); i++)
1641  {
1642  for (j = 0; j < A.GetLength(1); j++)
1643  {
1644  for (k = 0; k < A.GetLength(2); k++)
1645  {
1646  for (l = 0; l < A.GetLength(3); l++)
1647  out << A(i, j, k, l) << '\t';
1648  out << endl;
1649  }
1650  out << endl;
1651  }
1652  out << endl;
1653  }
1654  }
1655 
1656  if (N == 5)
1657  {
1658  int i, j, k, l, m;
1659 
1660  for (i = 0; i < A.GetLength(0); i++)
1661  {
1662  for (j = 0; j < A.GetLength(1); j++)
1663  {
1664  for (k = 0; k < A.GetLength(2); k++)
1665  {
1666  for (l = 0; l < A.GetLength(3); l++)
1667  {
1668  for (m = 0; m < A.GetLength(4); m++)
1669  out << A(i, j, k, l, m) << '\t';
1670  out << endl;
1671  }
1672  out << endl;
1673  }
1674  out << endl;
1675  }
1676  out << endl;
1677  }
1678  }
1679 
1680  if (N == 6)
1681  {
1682  int i, j, k, l, m, n;
1683 
1684  for (i = 0; i < A.GetLength(0); i++)
1685  {
1686  for (j = 0; j < A.GetLength(1); j++)
1687  {
1688  for (k = 0; k < A.GetLength(2); k++)
1689  {
1690  for (l = 0; l < A.GetLength(3); l++)
1691  {
1692  for (m = 0; m < A.GetLength(4); m++)
1693  {
1694  for (n = 0; n < A.GetLength(5); n++)
1695  out << A(i, j, k, l, m, n) << '\t';
1696  out << endl;
1697  }
1698  out << endl;
1699  }
1700  out << endl;
1701  }
1702  out << endl;
1703  }
1704  out << endl;
1705  }
1706  }
1707 
1708  if (N == 7)
1709  {
1710  int i, j, k, l, m, n, o;
1711  for (i = 0; i < A.GetLength(0); i++)
1712  {
1713  for (j = 0; j < A.GetLength(1); j++)
1714  {
1715  for (k = 0; k < A.GetLength(2); k++)
1716  {
1717  for (l = 0; l < A.GetLength(3); l++)
1718  {
1719  for (m = 0; m < A.GetLength(4); m++)
1720  {
1721  for (n = 0; n < A.GetLength(5); n++)
1722  {
1723  for (o = 0; o < A.GetLength(6); o++)
1724  cout << A(i, j, k, l, m, n, o)
1725  << '\t';
1726  cout << endl;
1727  }
1728  cout << endl;
1729  }
1730  cout << endl;
1731  }
1732  cout << endl;
1733  }
1734  cout << endl;
1735  }
1736  cout << endl;
1737  }
1738  }
1739 
1740  if (N == 8)
1741  {
1742  int i, j, k, l, m, n, o, p;
1743  for (i = 0; i < A.GetLength(0); i++)
1744  {
1745  for (j = 0; j < A.GetLength(1); j++)
1746  {
1747  for (k = 0; k < A.GetLength(2); k++)
1748  {
1749  for (l = 0; l < A.GetLength(3); l++)
1750  {
1751  for (m = 0; m < A.GetLength(4); m++)
1752  {
1753  for (n = 0; n < A.GetLength(5); n++)
1754  {
1755  for (o = 0; o < A.GetLength(6); o++)
1756  {
1757  for (p = 0; p < A.GetLength(7); p++)
1758  cout << A(i, j, k, l, m, n, o, p)
1759  << '\t';
1760  cout << endl;
1761  }
1762  cout << endl;
1763  }
1764  cout << endl;
1765  }
1766  cout << endl;
1767  }
1768  cout << endl;
1769  }
1770  cout << endl;
1771  }
1772  cout << endl;
1773  }
1774  }
1775 
1776  if (N == 9)
1777  {
1778  int i, j, k, l, m, n, o, p, q;
1779  for (i = 0; i < A.GetLength(0); i++)
1780  {
1781  for (j = 0; j < A.GetLength(1); j++)
1782  {
1783  for (k = 0; k < A.GetLength(2); k++)
1784  {
1785  for (l = 0; l < A.GetLength(3); l++)
1786  {
1787  for (m = 0; m < A.GetLength(4); m++)
1788  {
1789  for (n = 0; n < A.GetLength(5); n++)
1790  {
1791  for (o = 0; o < A.GetLength(6); o++)
1792  {
1793  for (p = 0; p < A.GetLength(7); p++)
1794  {
1795  for (q = 0; q < A.GetLength(8); q++)
1796  cout << A(i, j, k, l, m, n, o, p, q)
1797  << '\t';
1798  cout << endl;
1799  }
1800  cout << endl;
1801  }
1802  cout << endl;
1803  }
1804  cout << endl;
1805  }
1806  cout << endl;
1807  }
1808  cout << endl;
1809  }
1810  cout << endl;
1811  }
1812  cout << endl;
1813  }
1814  }
1815 
1816  return out;
1817  }
1818 
1819 
1820 } // namespace Seldon.
1821 
1822 #define SELDON_FILE_ARRAY_CXX
1823 #endif
Seldon::Array::Clear
void Clear()
Clears the array.
Definition: Array.cxx:1053
Seldon::to_str
std::string to_str(const T &input)
Converts most types to string.
Definition: CommonInline.cxx:137
Seldon::Array::GetLength
int GetLength(int dimension) const
Returns the length in dimension #1.
Definition: ArrayInline.cxx:50
Seldon::Array::Read
void Read(string FileName, bool with_size=true)
Reads the array from a file.
Definition: Array.cxx:1473
Seldon::Array
Multi-dimensional Array.
Definition: Array.hxx:33
Seldon::Array::GetMemorySize
size_t GetMemorySize() const
Returns the memory used by the object in bytes.
Definition: Array.cxx:1126
Seldon::Array::Zero
void Zero()
Sets all elements to zero.
Definition: Array.cxx:1140
Seldon::Array::Write
void Write(string FileName, bool with_size=true) const
Writes the array in a file.
Definition: Array.cxx:1406
Seldon::Array::Reallocate
void Reallocate(int i, int j, int k)
Reallocates memory to resize the 3D array.
Definition: Array.cxx:532
Seldon::Array::Array
Array()
Default constructor.
Definition: Array.cxx:37
Seldon::Array::FillRand
void FillRand()
Fills the array randomly.
Definition: Array.cxx:1181
Seldon::Array::Fill
void Fill()
Fills the array.
Definition: Array.cxx:1153
Seldon::Array::Copy
void Copy(const Array< T, N, Allocator > &A)
Duplicates an array.
Definition: Array.cxx:1085
Seldon::Array::Print
void Print() const
Displays the array on the standard output.
Definition: Array.cxx:1196
Seldon::WrongDim
Definition: Errors.hxx:102
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::operator<<
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
Definition: Array.cxx:1617
Seldon::IOError
Definition: Errors.hxx:150
Seldon::Array::GetData
pointer GetData() const
Returns a pointer to the data array.
Definition: ArrayInline.cxx:91
Seldon::NoMemory
Definition: Errors.hxx:90
Seldon::SetComplexReal
void SetComplexReal(int n, std::complex< T > &number)
Sets a complex number to (n, 0).
Definition: CommonInline.cxx:234