Mercurial > hg > octave-nkf
annotate liboctave/Array3.h @ 8290:7cbe01c21986
improve dense array indexing
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 20 Oct 2008 16:54:28 +0200 |
parents | 2467639bd8c0 |
children | eb63fbe60fab |
rev | line source |
---|---|
1993 | 1 // Template array classes |
1988 | 2 /* |
3 | |
7017 | 4 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2007 |
5 John W. Eaton | |
1988 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1988 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1988 | 22 |
23 */ | |
24 | |
25 #if !defined (octave_Array3_h) | |
26 #define octave_Array3_h 1 | |
27 | |
28 #include <cassert> | |
29 #include <cstdlib> | |
30 | |
4513 | 31 #include "Array.h" |
1988 | 32 #include "lo-error.h" |
33 | |
34 class idx_vector; | |
35 | |
36 // Three dimensional array class. | |
37 | |
38 template <class T> | |
3585 | 39 class |
4513 | 40 Array3 : public Array<T> |
1988 | 41 { |
42 protected: | |
43 | |
5275 | 44 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c, octave_idx_type p) |
4513 | 45 { return Array<T>::get_size (r, c, p); } |
1988 | 46 |
5275 | 47 Array3 (T *d, octave_idx_type r, octave_idx_type c, octave_idx_type p) : Array<T> (d, dim_vector (r, c, p)) { } |
1988 | 48 |
49 public: | |
50 | |
4513 | 51 Array3 (void) : Array<T> (dim_vector (0, 0, 0)) { } |
1988 | 52 |
5275 | 53 Array3 (octave_idx_type r, octave_idx_type c, octave_idx_type p) : Array<T> (dim_vector (r, c, p)) { } |
1988 | 54 |
5275 | 55 Array3 (octave_idx_type r, octave_idx_type c, octave_idx_type p, const T& val) |
4513 | 56 : Array<T> (dim_vector (r, c, p), val) { } |
1988 | 57 |
4513 | 58 Array3 (const Array3<T>& a) |
59 : Array<T> (a, a.dims ()) { } | |
60 | |
5275 | 61 Array3 (const Array<T>& a, octave_idx_type r, octave_idx_type c, octave_idx_type p) |
4513 | 62 : Array<T> (a, dim_vector (r, c, p)) { } |
1988 | 63 |
64 ~Array3 (void) { } | |
65 | |
66 Array3<T>& operator = (const Array3<T>& a) | |
67 { | |
4513 | 68 if (this != &a) |
4645 | 69 Array<T>::operator = (a); |
1988 | 70 |
71 return *this; | |
72 } | |
73 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7463
diff
changeset
|
74 void resize (octave_idx_type r, octave_idx_type c, octave_idx_type p) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7463
diff
changeset
|
75 { Array<T>::resize (dim_vector (r, c, p)); } |
2306 | 76 |
5275 | 77 void resize (octave_idx_type r, octave_idx_type c, octave_idx_type p, const T& val) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7463
diff
changeset
|
78 { Array<T>::resize_fill (dim_vector (r, c, p), val); } |
7433 | 79 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
80 Array3<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 81 { |
82 Array<T> tmp = Array<T>::sort (dim, mode); | |
83 return Array3<T> (tmp, tmp.rows (), tmp.columns (), tmp.pages ()); | |
84 } | |
85 | |
86 Array3<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
87 sortmode mode = ASCENDING) const |
7433 | 88 { |
89 Array<T> tmp = Array<T>::sort (sidx, dim, mode); | |
90 return Array3<T> (tmp, tmp.rows (), tmp.columns (), tmp.pages ()); | |
91 } | |
1988 | 92 }; |
93 | |
94 #endif | |
95 | |
96 /* | |
97 ;;; Local Variables: *** | |
98 ;;; mode: C++ *** | |
99 ;;; End: *** | |
100 */ |