3665
|
1 // Template array classes |
|
2 /* |
|
3 |
7017
|
4 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
|
5 John W. Eaton |
3665
|
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. |
3665
|
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/>. |
3665
|
22 |
|
23 */ |
|
24 |
|
25 #if !defined (octave_ArrayN_h) |
|
26 #define octave_ArrayN_h 1 |
|
27 |
|
28 #include <iostream> |
|
29 |
|
30 #include <cassert> |
|
31 #include <climits> |
|
32 #include <cmath> |
|
33 #include <cstdlib> |
|
34 |
|
35 #include "Array.h" |
4513
|
36 #include "Array2.h" |
3665
|
37 #include "lo-error.h" |
|
38 |
|
39 class idx_vector; |
|
40 |
|
41 // N-dimensional array class. |
|
42 |
|
43 template <class T> |
|
44 class |
|
45 ArrayN : public Array<T> |
|
46 { |
|
47 protected: |
|
48 |
4587
|
49 ArrayN (T *d, const dim_vector& dv) : Array<T> (d, dv) { } |
3665
|
50 |
|
51 public: |
|
52 |
|
53 // These really need to be protected (and they will be in the |
|
54 // future, so don't depend on them being here!), but they can't be |
|
55 // until template friends work correctly in g++. |
|
56 |
|
57 ArrayN (void) : Array<T> () { } |
|
58 |
4587
|
59 ArrayN (const dim_vector& dv) : Array<T> (dv) { } |
3665
|
60 |
4587
|
61 ArrayN (const dim_vector& dv, const T& val) |
5752
|
62 : Array<T> (dv) { Array<T>::fill (val); } |
3665
|
63 |
4902
|
64 template <class U> |
|
65 explicit ArrayN (const Array2<U>& a) : Array<T> (a, a.dims ()) { } |
4504
|
66 |
4902
|
67 template <class U> |
|
68 ArrayN (const ArrayN<U>& a) : Array<T> (a, a.dims ()) { } |
4504
|
69 |
4902
|
70 template <class U> |
|
71 ArrayN (const Array<U>& a) : Array<T> (a) { } |
4532
|
72 |
4902
|
73 template <class U> |
|
74 ArrayN (const Array<U>& a, const dim_vector& dv) |
|
75 : Array<T> (a, dv) { } |
4504
|
76 |
3665
|
77 ~ArrayN (void) { } |
|
78 |
|
79 ArrayN<T>& operator = (const ArrayN<T>& a) |
|
80 { |
4513
|
81 if (this != &a) |
|
82 Array<T>::operator = (a); |
3665
|
83 |
|
84 return *this; |
|
85 } |
|
86 |
4902
|
87 ArrayN<T> reshape (const dim_vector& new_dims) const |
|
88 { return Array<T>::reshape (new_dims); } |
|
89 |
6867
|
90 ArrayN<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const |
4902
|
91 { return Array<T>::permute (vec, inv); } |
|
92 |
6867
|
93 ArrayN<T> ipermute (const Array<octave_idx_type>& vec) const |
4902
|
94 { return Array<T>::ipermute (vec); } |
|
95 |
4587
|
96 void resize (const dim_vector& dv) |
4645
|
97 { this->resize_no_fill (dv); } |
3665
|
98 |
4587
|
99 void resize (const dim_vector& dv, const T& val) |
|
100 { Array<T>::resize (dv, val); } |
3665
|
101 |
4532
|
102 ArrayN<T> squeeze (void) const { return Array<T>::squeeze (); } |
|
103 |
4902
|
104 ArrayN<T> transpose (void) const { return Array<T>::transpose (); } |
|
105 |
4587
|
106 ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dv) |
3665
|
107 { |
4587
|
108 Array<T>::insert (a, dv); |
4513
|
109 return *this; |
3665
|
110 } |
|
111 |
5275
|
112 ArrayN<T>& insert (const ArrayN<T>& a, octave_idx_type r, octave_idx_type c) |
4765
|
113 { |
|
114 Array<T>::insert (a, r, c); |
|
115 return *this; |
|
116 } |
|
117 |
4513
|
118 ArrayN<T> index (idx_vector& i, int resize_ok = 0, |
|
119 const T& rfv = resize_fill_value (T ())) const |
3665
|
120 { |
4513
|
121 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
|
122 return ArrayN<T> (tmp, tmp.dims ()); |
3665
|
123 } |
|
124 |
4513
|
125 ArrayN<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
126 const T& rfv = resize_fill_value (T ())) const |
|
127 { |
|
128 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); |
|
129 return ArrayN<T> (tmp, tmp.dims ()); |
|
130 } |
3665
|
131 |
4273
|
132 ArrayN<T> index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
4513
|
133 const T& rfv = resize_fill_value (T ())) const |
|
134 { |
|
135 Array<T> tmp = Array<T>::index (ra_idx, resize_ok, rfv); |
|
136 return ArrayN<T> (tmp, tmp.dims ()); |
|
137 } |
3665
|
138 }; |
|
139 |
|
140 template <class T> |
|
141 std::ostream& |
|
142 operator << (std::ostream&, const ArrayN<T>&); |
|
143 |
|
144 #endif |
|
145 |
|
146 /* |
|
147 ;;; Local Variables: *** |
|
148 ;;; mode: C++ *** |
|
149 ;;; End: *** |
|
150 */ |