ArrayInline.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_INLINE_CXX
22 
23 
24 namespace Seldon
25 {
26 
27  /**************
28  * DESTRUCTOR *
29  **************/
30 
31 
33  template <class T, int N, class Allocator>
35  {
36  Clear();
37  }
38 
39 
40  /*****************
41  * BASIC METHODS *
42  *****************/
43 
45 
49  template <class T, int N, class Allocator>
50  inline int Array<T, N, Allocator>::GetLength(int dimension) const
51  {
52  return length_[dimension];
53  }
54 
55 
57 
62  template <class T, int N, class Allocator>
63  inline long Array<T, N, Allocator>::GetSize() const
64  {
65  return offset_[N - 1];
66  }
67 
68 
70 
76  template <class T, int N, class Allocator>
78  {
79  return offset_[N - 1];
80  }
81 
82 
84 
89  template <class T, int N, class Allocator>
90  inline typename Array<T, N, Allocator>::pointer Array<T, N, Allocator>
91  ::GetData() const
92  {
93  return data_;
94  }
95 
96 
97  /**********************************
98  * ELEMENT ACCESS AND AFFECTATION *
99  **********************************/
100 
101 
103 
110  template <class T, int N, class Allocator>
111  inline typename Array<T, N, Allocator>::reference
113  {
114 #ifdef SELDON_CHECK_BOUNDS
115  if (N != 3)
116  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
117  "Array dimension should be 3.");
118 
119  CheckBounds(i, j, k, length_[0], length_[1], length_[2], "Array");
120 #endif
121 
122  return data_[i * offset_[0] + j * offset_[1] + k];
123  }
124 
125 
127 
134  template <class T, int N, class Allocator>
135  inline typename Array<T, N, Allocator>::const_reference
136  Array<T, N, Allocator>::operator() (int i, int j, int k) const
137  {
138 #ifdef SELDON_CHECK_BOUNDS
139  if (N != 3)
140  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
141  "Array dimension should be 3.");
142 
143  CheckBounds(i, j, k, length_[0], length_[1], length_[2], "Array");
144 #endif
145 
146  return data_[i * offset_[0] + j * offset_[1] + k];
147  }
148 
149 
151 
159  template <class T, int N, class Allocator>
160  inline typename Array<T, N, Allocator>::reference
161  Array<T, N, Allocator>::operator() (int i, int j, int k, int l)
162  {
163 #ifdef SELDON_CHECK_BOUNDS
164  if (N != 4)
165  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
166  "Array dimension should be 4.");
167 
168  CheckBounds(i, j, k, l, length_[0], length_[1],
169  length_[2], length_[3], "Array");
170 #endif
171 
172  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] + l];
173  }
174 
175 
177 
185  template <class T, int N, class Allocator>
186  inline typename Array<T, N, Allocator>::const_reference
187  Array<T, N, Allocator>::operator() (int i, int j, int k, int l) const
188  {
189 #ifdef SELDON_CHECK_BOUNDS
190  if (N != 4)
191  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
192  "Array dimension should be 4.");
193 
194  CheckBounds(i, j, k, l, length_[0], length_[1],
195  length_[2], length_[3], "Array");
196 #endif
197 
198  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] + l];
199  }
200 
201 
203 
212  template <class T, int N, class Allocator>
213  inline typename Array<T, N, Allocator>::reference
214  Array<T, N, Allocator>::operator() (int i, int j, int k, int l, int m)
215  {
216 #ifdef SELDON_CHECK_BOUNDS
217  if (N != 5)
218  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
219  "Array dimension should be 5.");
220 
221  CheckBounds(i, j, k, l, m, length_[0], length_[1], length_[2],
222  length_[3], length_[4], "Array");
223 #endif
224 
225  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
226  l * offset_[3] + m];
227  }
228 
229 
231 
240  template <class T, int N, class Allocator>
241  inline typename Array<T, N, Allocator>::const_reference
242  Array<T, N, Allocator>::operator() (int i, int j, int k, int l, int m) const
243  {
244 #ifdef SELDON_CHECK_BOUNDS
245  if (N != 5)
246  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
247  "Array dimension should be 5.");
248 
249  CheckBounds(i, j, k, l, m, length_[0], length_[1], length_[2],
250  length_[3], length_[4], "Array");
251 #endif
252 
253  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
254  l * offset_[3] + m];
255  }
256 
257 
259 
269  template <class T, int N, class Allocator>
270  inline typename Array<T, N, Allocator>::reference
272  ::operator() (int i, int j, int k, int l, int m, int n)
273  {
274 #ifdef SELDON_CHECK_BOUNDS
275  if (N != 6)
276  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
277  "Array dimension should be 6.");
278 
279  CheckBounds(i, j, k, l, m, n, length_[0], length_[1], length_[2],
280  length_[3], length_[4], length_[5], "Array");
281 #endif
282 
283  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
284  l * offset_[3] + m * offset_[4] + n];
285  }
286 
287 
289 
299  template <class T, int N, class Allocator>
300  inline typename Array<T, N, Allocator>::const_reference
302  ::operator() (int i, int j, int k, int l, int m, int n) const
303  {
304 #ifdef SELDON_CHECK_BOUNDS
305  if (N != 6)
306  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
307  "Array dimension should be 6.");
308 
309  CheckBounds(i, j, k, l, m, n, length_[0], length_[1], length_[2],
310  length_[3], length_[4], length_[5], "Array");
311 #endif
312 
313  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
314  l * offset_[3] + m * offset_[4] + n];
315  }
316 
317 
319 
330  template <class T, int N, class Allocator>
331  inline typename Array<T, N, Allocator>::reference
333  ::operator() (int i, int j, int k, int l, int m, int n, int o)
334  {
335 #ifdef SELDON_CHECK_BOUNDS
336  if (N != 7)
337  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
338  "Array dimension should be 7.");
339 
340  CheckBounds(i, j, k, l, m, n, o, length_[0], length_[1], length_[2],
341  length_[3], length_[4], length_[5], length_[6], "Array");
342 #endif
343 
344  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
345  l * offset_[3] + m * offset_[4] + n * offset_[5] + o];
346  }
347 
348 
350 
361  template <class T, int N, class Allocator>
362  inline typename Array<T, N, Allocator>::const_reference
364  ::operator() (int i, int j, int k, int l, int m, int n, int o) const
365  {
366 #ifdef SELDON_CHECK_BOUNDS
367  if (N != 7)
368  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
369  "Array dimension should be 7.");
370 
371  CheckBounds(i, j, k, l, m, n, o, length_[0], length_[1], length_[2],
372  length_[3], length_[4], length_[5], length_[6], "Array");
373 #endif
374 
375  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
376  l * offset_[3] + m * offset_[4] + n * offset_[5] + o];
377  }
378 
379 
381 
393  template <class T, int N, class Allocator>
394  inline typename Array<T, N, Allocator>::reference
396  ::operator() (int i, int j, int k, int l, int m, int n, int o, int p)
397  {
398 #ifdef SELDON_CHECK_BOUNDS
399  if (N != 8)
400  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
401  "Array dimension should be 8.");
402 
403  CheckBounds(i, j, k, l, m, n, o, p, length_[0], length_[1], length_[2],
404  length_[3], length_[4], length_[5], length_[6],
405  length_[7], "Array");
406 #endif
407 
408  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
409  l * offset_[3] + m * offset_[4] + n * offset_[5] +
410  o * offset_[6] + p];
411  }
412 
413 
415 
427  template <class T, int N, class Allocator>
428  inline typename Array<T, N, Allocator>::const_reference
430  ::operator() (int i, int j, int k, int l, int m, int n, int o, int p) const
431  {
432 #ifdef SELDON_CHECK_BOUNDS
433  if (N != 8)
434  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
435  "Array dimension should be 8.");
436 
437  CheckBounds(i, j, k, l, m, n, o, p, length_[0], length_[1], length_[2],
438  length_[3], length_[4], length_[5], length_[6],
439  length_[7], "Array");
440 #endif
441 
442  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
443  l * offset_[3] + m * offset_[4] + n * offset_[5] +
444  o * offset_[6] + p];
445  }
446 
447 
449 
462  template <class T, int N, class Allocator>
463  inline typename Array<T, N, Allocator>::reference
464  Array<T, N, Allocator>::operator() (int i, int j, int k, int l, int m,
465  int n, int o, int p, int q)
466  {
467 #ifdef SELDON_CHECK_BOUNDS
468  if (N != 9)
469  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
470  "Array dimension should be 9.");
471 
472  CheckBounds(i, j, k, l, m, n, o, p, q, length_[0], length_[1], length_[2],
473  length_[3], length_[4], length_[5], length_[6],
474  length_[7], length_[8], "Array");
475 #endif
476 
477  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
478  l * offset_[3] + m * offset_[4] + n * offset_[5] +
479  o * offset_[6] + p * offset_[7] + q];
480  }
481 
482 
484 
497  template <class T, int N, class Allocator>
498  inline typename Array<T, N, Allocator>::const_reference
499  Array<T, N, Allocator>::operator() (int i, int j, int k, int l, int m,
500  int n, int o, int p, int q) const
501  {
502 #ifdef SELDON_CHECK_BOUNDS
503  if (N != 9)
504  throw WrongDim("Array<T, N, Allocator>::operator(int, ...)",
505  "Array dimension should be 9.");
506 
507  CheckBounds(i, j, k, l, m, n, o, p, q, length_[0], length_[1], length_[2],
508  length_[3], length_[4], length_[5], length_[6],
509  length_[7], length_[8], "Array");
510 #endif
511 
512  return data_[i * offset_[0] + j * offset_[1] + k * offset_[2] +
513  l * offset_[3] + m * offset_[4] + n * offset_[5] +
514  o * offset_[6] + p * offset_[7] + q];
515  }
516 
517 
519 
524  template <class T, int N, class Allocator>
527  {
528  Copy(A);
529 
530  return *this;
531  }
532 
533 } // namespace Seldon.
534 
535 #define SELDON_FILE_ARRAY_INLINE_CXX
536 #endif
Seldon::Array::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: ArrayInline.cxx:77
Seldon::Array::GetLength
int GetLength(int dimension) const
Returns the length in dimension #1.
Definition: ArrayInline.cxx:50
Seldon::Array
Multi-dimensional Array.
Definition: Array.hxx:33
Seldon::Array::~Array
~Array()
Destructor.
Definition: ArrayInline.cxx:34
Seldon::WrongDim
Definition: Errors.hxx:102
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Array::GetData
pointer GetData() const
Returns a pointer to the data array.
Definition: ArrayInline.cxx:91
Seldon::Array::GetSize
long GetSize() const
Returns the number of elements in the 3D array.
Definition: ArrayInline.cxx:63
Seldon::Array::operator()
reference operator()(int i, int j, int k)
Access operator.
Definition: ArrayInline.cxx:112