Mercurial > hg > octave-lyh
annotate liboctave/intNDArray.cc @ 10010:c5e9931c7ba7
Correctly produce postcript output for geometryimages when QHULL library is not present
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 20 Dec 2009 17:02:57 -0800 |
parents | b4fdfee405b5 |
children | 4c0cdbe0acca |
rev | line source |
---|---|
4902 | 1 // N-D Array manipulations. |
2 /* | |
3 | |
8920 | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague, a.s. |
4902 | 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. | |
4902 | 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/>. | |
4902 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include "Array-util.h" | |
30 #include "mx-base.h" | |
31 #include "lo-ieee.h" | |
8741
008f3985c8c0
use new summation code for native integer summation
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
32 #include "mx-inlines.cc" |
4902 | 33 |
34 // unary operations | |
35 | |
36 template <class T> | |
37 boolNDArray | |
38 intNDArray<T>::operator ! (void) const | |
39 { | |
4932 | 40 boolNDArray b (this->dims ()); |
4902 | 41 |
5275 | 42 for (octave_idx_type i = 0; i < this->length (); i++) |
4932 | 43 b.elem (i) = ! this->elem (i); |
4902 | 44 |
45 return b; | |
46 } | |
47 | |
5943 | 48 template <class T> |
49 bool | |
50 intNDArray<T>::any_element_not_one_or_zero (void) const | |
51 { | |
52 octave_idx_type nel = this->nelem (); | |
53 | |
54 for (octave_idx_type i = 0; i < nel; i++) | |
55 { | |
56 T val = this->elem (i); | |
57 | |
58 if (val != 0.0 && val != 1.0) | |
59 return true; | |
60 } | |
61 | |
62 return false; | |
63 } | |
64 | |
6979 | 65 template <class T> |
66 intNDArray<T> | |
67 intNDArray<T>::diag (octave_idx_type k) const | |
68 { | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
69 return MArrayN<T>::diag (k); |
6979 | 70 } |
71 | |
5775 | 72 // FIXME -- this is not quite the right thing. |
4902 | 73 |
74 template <class T> | |
75 boolNDArray | |
76 intNDArray<T>::all (int dim) const | |
77 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
78 return do_mx_red_op<boolNDArray, T > (*this, dim, mx_inline_all); |
4902 | 79 } |
80 | |
81 template <class T> | |
82 boolNDArray | |
83 intNDArray<T>::any (int dim) const | |
84 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
85 return do_mx_red_op<boolNDArray, T > (*this, dim, mx_inline_any); |
4902 | 86 } |
87 | |
88 template <class T> | |
89 void | |
5275 | 90 intNDArray<T>::increment_index (Array<octave_idx_type>& ra_idx, |
4902 | 91 const dim_vector& dimensions, |
92 int start_dimension) | |
93 { | |
94 ::increment_index (ra_idx, dimensions, start_dimension); | |
95 } | |
96 | |
97 template <class T> | |
5275 | 98 octave_idx_type |
99 intNDArray<T>::compute_index (Array<octave_idx_type>& ra_idx, | |
4902 | 100 const dim_vector& dimensions) |
101 { | |
102 return ::compute_index (ra_idx, dimensions); | |
103 } | |
104 | |
4915 | 105 template <class T> |
5073 | 106 intNDArray<T> |
5275 | 107 intNDArray<T>::concat (const intNDArray<T>& rb, const Array<octave_idx_type>& ra_idx) |
5073 | 108 { |
6482 | 109 if (rb.numel () > 0) |
5073 | 110 insert (rb, ra_idx); |
111 return *this; | |
112 } | |
113 | |
114 template <class T> | |
4915 | 115 intNDArray<T>& |
5275 | 116 intNDArray<T>::insert (const intNDArray<T>& a, octave_idx_type r, octave_idx_type c) |
4915 | 117 { |
118 Array<T>::insert (a, r, c); | |
119 return *this; | |
120 } | |
121 | |
122 template <class T> | |
123 intNDArray<T>& | |
5275 | 124 intNDArray<T>::insert (const intNDArray<T>& a, const Array<octave_idx_type>& ra_idx) |
4915 | 125 { |
126 Array<T>::insert (a, ra_idx); | |
127 return *this; | |
128 } | |
129 | |
4902 | 130 // This contains no information on the array structure !!! |
131 | |
132 template <class T> | |
133 std::ostream& | |
134 operator << (std::ostream& os, const intNDArray<T>& a) | |
135 { | |
5275 | 136 octave_idx_type nel = a.nelem (); |
4902 | 137 |
5275 | 138 for (octave_idx_type i = 0; i < nel; i++) |
4902 | 139 os << " " << a.elem (i) << "\n"; |
140 | |
141 return os; | |
142 } | |
143 | |
144 template <class T> | |
145 std::istream& | |
146 operator >> (std::istream& is, intNDArray<T>& a) | |
147 { | |
5275 | 148 octave_idx_type nel = a.nelem (); |
4902 | 149 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
150 if (nel > 0) |
4902 | 151 { |
152 T tmp; | |
153 | |
5275 | 154 for (octave_idx_type i = 0; i < nel; i++) |
4902 | 155 { |
156 is >> tmp; | |
157 | |
158 if (is) | |
159 a.elem (i) = tmp; | |
160 else | |
161 goto done; | |
162 } | |
163 } | |
164 | |
165 done: | |
166 | |
167 return is; | |
168 } | |
169 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
170 // FIXME -- should abs and signum just be mapper functions? |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
171 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
172 template <class T> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
173 intNDArray<T> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
174 intNDArray<T>::abs (void) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
175 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
176 octave_idx_type nel = this->nelem (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
177 intNDArray<T> ret (*this); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
178 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
179 for (octave_idx_type i = 0; i < nel; i++) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
180 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
181 T val = this->elem (i); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
182 ret.xelem (i) = val.abs (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
183 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
184 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
185 return ret; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
186 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
187 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
188 template <class T> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
189 intNDArray<T> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
190 intNDArray<T>::signum (void) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
191 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
192 octave_idx_type nel = this->nelem (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
193 intNDArray<T> ret (*this); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
194 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
195 for (octave_idx_type i = 0; i < nel; i++) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
196 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
197 T val = this->elem (i); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
198 ret.xelem (i) = val.signum (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
199 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
200 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
201 return ret; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
202 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7457
diff
changeset
|
203 |
7113 | 204 template <class T> |
205 intNDArray<T> | |
206 intNDArray<T>::sum (int dim) const | |
207 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
208 return do_mx_red_op<intNDArray<T> , T > (*this, dim, mx_inline_sum); |
7113 | 209 } |
210 | |
7189 | 211 template <class T> |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
212 NDArray |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
213 intNDArray<T>::dsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
214 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
215 return do_mx_red_op<NDArray , T> (*this, dim, mx_inline_dsum); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
216 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
217 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
218 template <class T> |
7189 | 219 intNDArray<T> |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
220 intNDArray<T>::cumsum (int dim) const |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
221 { |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
222 return do_mx_cum_op<intNDArray<T> , T > (*this, dim, mx_inline_cumsum); |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
223 } |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
224 |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
225 template <class T> |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
226 intNDArray<T> |
7189 | 227 intNDArray<T>::max (int dim) const |
228 { | |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
229 return do_mx_minmax_op<intNDArray<T> > (*this, dim, mx_inline_max); |
7189 | 230 } |
231 | |
232 template <class T> | |
233 intNDArray<T> | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
234 intNDArray<T>::max (Array<octave_idx_type>& idx_arg, int dim) const |
7189 | 235 { |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
236 return do_mx_minmax_op<intNDArray<T> > (*this, idx_arg, dim, mx_inline_max); |
7189 | 237 } |
238 | |
239 template <class T> | |
240 intNDArray<T> | |
241 intNDArray<T>::min (int dim) const | |
242 { | |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
243 return do_mx_minmax_op<intNDArray<T> > (*this, dim, mx_inline_min); |
7189 | 244 } |
245 | |
246 template <class T> | |
247 intNDArray<T> | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
248 intNDArray<T>::min (Array<octave_idx_type>& idx_arg, int dim) const |
7189 | 249 { |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
250 return do_mx_minmax_op<intNDArray<T> > (*this, idx_arg, dim, mx_inline_min); |
7189 | 251 } |
252 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
253 template <class T> |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
254 intNDArray<T> |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
255 intNDArray<T>::cummax (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
256 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
257 return do_mx_cumminmax_op<intNDArray<T> > (*this, dim, mx_inline_cummax); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
258 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
259 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
260 template <class T> |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
261 intNDArray<T> |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
262 intNDArray<T>::cummax (Array<octave_idx_type>& idx_arg, int dim) const |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
263 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
264 return do_mx_cumminmax_op<intNDArray<T> > (*this, idx_arg, dim, mx_inline_cummax); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
265 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
266 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
267 template <class T> |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
268 intNDArray<T> |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
269 intNDArray<T>::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
270 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
271 return do_mx_cumminmax_op<intNDArray<T> > (*this, dim, mx_inline_cummin); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
272 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
273 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
274 template <class T> |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
275 intNDArray<T> |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
276 intNDArray<T>::cummin (Array<octave_idx_type>& idx_arg, int dim) const |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
277 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
278 return do_mx_cumminmax_op<intNDArray<T> > (*this, idx_arg, dim, mx_inline_cummin); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
279 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
280 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
281 template <class T> |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
282 intNDArray<T> |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
283 intNDArray<T>::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
284 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
285 return do_mx_diff_op<intNDArray<T> > (*this, dim, order, mx_inline_diff); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
286 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
287 |
4902 | 288 /* |
289 ;;; Local Variables: *** | |
290 ;;; mode: C++ *** | |
291 ;;; End: *** | |
292 */ |