3665
|
1 // Template array classes |
|
2 /* |
|
3 |
|
4 Copyright (C) 2000 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3665
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
3665
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_ArrayN_h) |
|
25 #define octave_ArrayN_h 1 |
|
26 |
|
27 #include <iostream> |
|
28 |
|
29 #include <cassert> |
|
30 #include <climits> |
|
31 #include <cmath> |
|
32 #include <cstdlib> |
|
33 |
|
34 #include "Array.h" |
4513
|
35 #include "Array2.h" |
3665
|
36 #include "lo-error.h" |
|
37 |
|
38 class idx_vector; |
|
39 |
|
40 // N-dimensional array class. |
|
41 |
|
42 template <class T> |
|
43 class |
|
44 ArrayN : public Array<T> |
|
45 { |
|
46 protected: |
|
47 |
4587
|
48 ArrayN (T *d, const dim_vector& dv) : Array<T> (d, dv) { } |
3665
|
49 |
|
50 public: |
|
51 |
|
52 // These really need to be protected (and they will be in the |
|
53 // future, so don't depend on them being here!), but they can't be |
|
54 // until template friends work correctly in g++. |
|
55 |
|
56 ArrayN (void) : Array<T> () { } |
|
57 |
4587
|
58 ArrayN (const dim_vector& dv) : Array<T> (dv) { } |
3665
|
59 |
4587
|
60 ArrayN (const dim_vector& dv, const T& val) |
5752
|
61 : Array<T> (dv) { Array<T>::fill (val); } |
3665
|
62 |
4902
|
63 template <class U> |
|
64 explicit ArrayN (const Array2<U>& a) : Array<T> (a, a.dims ()) { } |
4504
|
65 |
4902
|
66 template <class U> |
|
67 ArrayN (const ArrayN<U>& a) : Array<T> (a, a.dims ()) { } |
4504
|
68 |
4902
|
69 template <class U> |
|
70 ArrayN (const Array<U>& a) : Array<T> (a) { } |
4532
|
71 |
4902
|
72 template <class U> |
|
73 ArrayN (const Array<U>& a, const dim_vector& dv) |
|
74 : Array<T> (a, dv) { } |
4504
|
75 |
3665
|
76 ~ArrayN (void) { } |
|
77 |
|
78 ArrayN<T>& operator = (const ArrayN<T>& a) |
|
79 { |
4513
|
80 if (this != &a) |
|
81 Array<T>::operator = (a); |
3665
|
82 |
|
83 return *this; |
|
84 } |
|
85 |
4902
|
86 ArrayN<T> reshape (const dim_vector& new_dims) const |
|
87 { return Array<T>::reshape (new_dims); } |
|
88 |
6867
|
89 ArrayN<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const |
4902
|
90 { return Array<T>::permute (vec, inv); } |
|
91 |
6867
|
92 ArrayN<T> ipermute (const Array<octave_idx_type>& vec) const |
4902
|
93 { return Array<T>::ipermute (vec); } |
|
94 |
4587
|
95 void resize (const dim_vector& dv) |
4645
|
96 { this->resize_no_fill (dv); } |
3665
|
97 |
4587
|
98 void resize (const dim_vector& dv, const T& val) |
|
99 { Array<T>::resize (dv, val); } |
3665
|
100 |
4532
|
101 ArrayN<T> squeeze (void) const { return Array<T>::squeeze (); } |
|
102 |
4902
|
103 ArrayN<T> transpose (void) const { return Array<T>::transpose (); } |
|
104 |
4587
|
105 ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dv) |
3665
|
106 { |
4587
|
107 Array<T>::insert (a, dv); |
4513
|
108 return *this; |
3665
|
109 } |
|
110 |
5275
|
111 ArrayN<T>& insert (const ArrayN<T>& a, octave_idx_type r, octave_idx_type c) |
4765
|
112 { |
|
113 Array<T>::insert (a, r, c); |
|
114 return *this; |
|
115 } |
|
116 |
4513
|
117 ArrayN<T> index (idx_vector& i, int resize_ok = 0, |
|
118 const T& rfv = resize_fill_value (T ())) const |
3665
|
119 { |
4513
|
120 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
121 return ArrayN<T> (tmp, tmp.dims ()); |
3665
|
122 } |
|
123 |
4513
|
124 ArrayN<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
125 const T& rfv = resize_fill_value (T ())) const |
|
126 { |
|
127 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
128 return ArrayN<T> (tmp, tmp.dims ()); |
|
129 } |
3665
|
130 |
4273
|
131 ArrayN<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
4513
|
132 const T& rfv = resize_fill_value (T ())) const |
|
133 { |
|
134 Array<T> tmp = Array<T>::index (ra_idx, resize_ok, rfv); |
|
135 return ArrayN<T> (tmp, tmp.dims ()); |
|
136 } |
3665
|
137 }; |
|
138 |
|
139 template <class T> |
|
140 std::ostream& |
|
141 operator << (std::ostream&, const ArrayN<T>&); |
|
142 |
|
143 #endif |
|
144 |
|
145 /* |
|
146 ;;; Local Variables: *** |
|
147 ;;; mode: C++ *** |
|
148 ;;; End: *** |
|
149 */ |