Mercurial > octave-nkf
annotate liboctave/ArrayN.h @ 7503:8c32f95c2639
convert mapper functions to new format
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 20 Feb 2008 04:22:50 -0500 |
parents | 2467639bd8c0 |
children | 36594d5bbe13 |
rev | line source |
---|---|
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 <cstdlib> | |
33 | |
34 #include "Array.h" | |
4513 | 35 #include "Array2.h" |
3665 | 36 #include "lo-error.h" |
7231 | 37 #include "lo-math.h" |
3665 | 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 } | |
7433 | 138 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
139 ArrayN<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 140 { |
141 Array<T> tmp = Array<T>::sort (dim, mode); | |
142 return ArrayN<T> (tmp, tmp.dims ()); | |
143 } | |
144 | |
145 ArrayN<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
|
146 sortmode mode = ASCENDING) const |
7433 | 147 { |
148 Array<T> tmp = Array<T>::sort (sidx, dim, mode); | |
149 return ArrayN<T> (tmp, tmp.dims ()); | |
150 } | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
151 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
152 template <class U, class F> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
153 ArrayN<U> map (F fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
154 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
155 return Array<T>::template map<U> (fcn); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
156 } |
3665 | 157 }; |
158 | |
159 template <class T> | |
160 std::ostream& | |
161 operator << (std::ostream&, const ArrayN<T>&); | |
162 | |
163 #endif | |
164 | |
165 /* | |
166 ;;; Local Variables: *** | |
167 ;;; mode: C++ *** | |
168 ;;; End: *** | |
169 */ |