Mercurial > hg > octave-lyh
annotate liboctave/ArrayN.h @ 8950:d865363208d6
include <iosfwd> instead of <iostream> in header files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 10 Mar 2009 13:55:52 -0400 |
parents | eb63fbe60fab |
children | aea3a3a950e1 |
rev | line source |
---|---|
3665 | 1 // Template array classes |
2 /* | |
3 | |
8920 | 4 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
7017 | 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 <cassert> | |
29 #include <climits> | |
30 #include <cstdlib> | |
31 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
32 #include <iosfwd> |
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
33 |
3665 | 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 | |
4532 | 96 ArrayN<T> squeeze (void) const { return Array<T>::squeeze (); } |
97 | |
4902 | 98 ArrayN<T> transpose (void) const { return Array<T>::transpose (); } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
99 ArrayN<T> hermitian (T (*fcn) (const T&) = 0) const { return Array<T>::hermitian (fcn); } |
4902 | 100 |
4587 | 101 ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dv) |
3665 | 102 { |
4587 | 103 Array<T>::insert (a, dv); |
4513 | 104 return *this; |
3665 | 105 } |
106 | |
5275 | 107 ArrayN<T>& insert (const ArrayN<T>& a, octave_idx_type r, octave_idx_type c) |
4765 | 108 { |
109 Array<T>::insert (a, r, c); | |
110 return *this; | |
111 } | |
112 | |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
113 ArrayN<T> index (const idx_vector& i, bool resize_ok = false, |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
114 const T& rfv = Array<T>::resize_fill_value ()) const |
3665 | 115 { |
4513 | 116 Array<T> tmp = Array<T>::index (i, resize_ok, rfv); |
117 return ArrayN<T> (tmp, tmp.dims ()); | |
3665 | 118 } |
119 | |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
120 ArrayN<T> index (const idx_vector& i, const idx_vector& j, bool resize_ok = false, |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
121 const T& rfv = Array<T>::resize_fill_value ()) const |
4513 | 122 { |
123 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv); | |
124 return ArrayN<T> (tmp, tmp.dims ()); | |
125 } | |
3665 | 126 |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
127 ArrayN<T> index (const Array<idx_vector>& ra_idx, bool resize_ok = false, |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
128 const T& rfv = Array<T>::resize_fill_value ()) const |
4513 | 129 { |
130 Array<T> tmp = Array<T>::index (ra_idx, resize_ok, rfv); | |
131 return ArrayN<T> (tmp, tmp.dims ()); | |
132 } | |
7433 | 133 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
134 ArrayN<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 135 { |
136 Array<T> tmp = Array<T>::sort (dim, mode); | |
137 return ArrayN<T> (tmp, tmp.dims ()); | |
138 } | |
139 | |
140 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
|
141 sortmode mode = ASCENDING) const |
7433 | 142 { |
143 Array<T> tmp = Array<T>::sort (sidx, dim, mode); | |
144 return ArrayN<T> (tmp, tmp.dims ()); | |
145 } | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
146 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
147 ArrayN<T> diag (octave_idx_type k) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
148 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
149 return Array<T>::diag (k); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
150 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
151 |
7503
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 */ |