Mercurial > hg > octave-nkf
annotate liboctave/dNDArray.h @ 9732:b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 16 Oct 2009 13:12:31 +0200 |
parents | 192d94cff6c1 |
children | 26abff55f6fe |
rev | line source |
---|---|
4511 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007, 2008, |
4 2009 John W. Eaton | |
4511 | 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. | |
4511 | 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/>. | |
4511 | 21 |
22 */ | |
23 | |
4513 | 24 #if !defined (octave_NDArray_h) |
25 #define octave_NDArray_h 1 | |
4511 | 26 |
27 #include "MArrayN.h" | |
4513 | 28 #include "dMatrix.h" |
4902 | 29 #include "intNDArray.h" |
4511 | 30 |
31 #include "mx-defs.h" | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
32 #include "mx-op-decl.h" |
4511 | 33 |
4513 | 34 class |
6108 | 35 OCTAVE_API |
4513 | 36 NDArray : public MArrayN<double> |
4511 | 37 { |
4513 | 38 public: |
5523 | 39 |
9656
b29504415a2e
provide NDArray->Matrix->Vector typedef mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
9607
diff
changeset
|
40 typedef Matrix matrix_type; |
b29504415a2e
provide NDArray->Matrix->Vector typedef mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
9607
diff
changeset
|
41 |
4511 | 42 NDArray (void) : MArrayN<double> () { } |
43 | |
4587 | 44 NDArray (const dim_vector& dv) : MArrayN<double> (dv) { } |
4511 | 45 |
4587 | 46 NDArray (const dim_vector& dv, double val) |
47 : MArrayN<double> (dv, val) { } | |
4511 | 48 |
4513 | 49 NDArray (const NDArray& a) : MArrayN<double> (a) { } |
50 | |
51 NDArray (const Matrix& a) : MArrayN<double> (a) { } | |
4511 | 52 |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
53 NDArray (const Array<octave_idx_type>& a, bool zero_based = false, |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
54 bool negative_to_nan = false); |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
55 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
56 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
57 NDArray (const MArrayN<U>& a) : MArrayN<double> (a) { } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
58 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
59 template <class U> |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
60 NDArray (const Array<U>& a) : MArrayN<double> (a) { } |
4511 | 61 |
4902 | 62 template <class U> |
63 explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { } | |
4543 | 64 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
65 NDArray (const charNDArray&); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
66 |
4511 | 67 NDArray& operator = (const NDArray& a) |
68 { | |
69 MArrayN<double>::operator = (a); | |
70 return *this; | |
71 } | |
72 | |
4543 | 73 // unary operations |
74 | |
75 boolNDArray operator ! (void) const; | |
76 | |
4634 | 77 bool any_element_is_negative (bool = false) const; |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7919
diff
changeset
|
78 bool any_element_is_nan (void) const; |
4634 | 79 bool any_element_is_inf_or_nan (void) const; |
5943 | 80 bool any_element_not_one_or_zero (void) const; |
6989 | 81 bool all_elements_are_zero (void) const; |
4634 | 82 bool all_elements_are_int_or_inf_or_nan (void) const; |
83 bool all_integers (double& max_val, double& min_val) const; | |
84 bool too_large_for_float (void) const; | |
85 | |
5775 | 86 // FIXME -- this is not quite the right thing. |
4513 | 87 |
4556 | 88 boolNDArray all (int dim = -1) const; |
89 boolNDArray any (int dim = -1) const; | |
4513 | 90 |
4584 | 91 NDArray cumprod (int dim = -1) const; |
92 NDArray cumsum (int dim = -1) const; | |
4569 | 93 NDArray prod (int dim = -1) const; |
94 NDArray sum (int dim = -1) const; | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9656
diff
changeset
|
95 NDArray xsum (int dim = -1) const; |
4569 | 96 NDArray sumsq (int dim = -1) const; |
5275 | 97 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx); |
98 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx); | |
99 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx); | |
4844 | 100 |
101 NDArray max (int dim = 0) const; | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
102 NDArray max (Array<octave_idx_type>& index, int dim = 0) const; |
4844 | 103 NDArray min (int dim = 0) const; |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
104 NDArray min (Array<octave_idx_type>& index, int dim = 0) const; |
4844 | 105 |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
106 NDArray cummax (int dim = 0) const; |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
107 NDArray cummax (Array<octave_idx_type>& index, int dim = 0) const; |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
108 NDArray cummin (int dim = 0) const; |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
109 NDArray cummin (Array<octave_idx_type>& index, int dim = 0) const; |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
110 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
111 NDArray diff (octave_idx_type order = 1, int dim = 0) const; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
112 |
5275 | 113 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c); |
114 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx); | |
4915 | 115 |
4634 | 116 NDArray abs (void) const; |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
117 boolNDArray isnan (void) const; |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
118 boolNDArray isinf (void) const; |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
119 boolNDArray isfinite (void) const; |
4634 | 120 |
4773 | 121 ComplexNDArray fourier (int dim = 1) const; |
122 ComplexNDArray ifourier (int dim = 1) const; | |
123 | |
124 ComplexNDArray fourier2d (void) const; | |
125 ComplexNDArray ifourier2d (void) const; | |
126 | |
127 ComplexNDArray fourierNd (void) const; | |
128 ComplexNDArray ifourierNd (void) const; | |
129 | |
6108 | 130 friend OCTAVE_API NDArray real (const ComplexNDArray& a); |
131 friend OCTAVE_API NDArray imag (const ComplexNDArray& a); | |
4569 | 132 |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
133 friend class ComplexNDArray; |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
134 |
4513 | 135 Matrix matrix_value (void) const; |
136 | |
4902 | 137 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); } |
4532 | 138 |
5275 | 139 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 140 const dim_vector& dimensions, |
141 int start_dimension = 0); | |
142 | |
5275 | 143 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556 | 144 const dim_vector& dimensions); |
145 | |
4511 | 146 // i/o |
147 | |
6108 | 148 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const NDArray& a); |
149 friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a); | |
4511 | 150 |
151 static double resize_fill_value (void) { return 0; } | |
152 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
153 NDArray diag (octave_idx_type k = 0) const; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
154 |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
155 NDArray& changesign (void) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
156 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
157 MArrayN<double>::changesign (); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
158 return *this; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
159 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
160 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
161 typedef double (*dmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
162 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
163 typedef bool (*bmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
164 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
165 NDArray map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
166 ComplexNDArray map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
167 boolNDArray map (bmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
168 |
4513 | 169 private: |
4511 | 170 |
4634 | 171 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { } |
4511 | 172 }; |
173 | |
5508 | 174 // Publish externally used friend functions. |
175 | |
6108 | 176 extern OCTAVE_API NDArray real (const ComplexNDArray& a); |
177 extern OCTAVE_API NDArray imag (const ComplexNDArray& a); | |
5508 | 178 |
6108 | 179 extern OCTAVE_API NDArray min (double d, const NDArray& m); |
180 extern OCTAVE_API NDArray min (const NDArray& m, double d); | |
181 extern OCTAVE_API NDArray min (const NDArray& a, const NDArray& b); | |
4844 | 182 |
6108 | 183 extern OCTAVE_API NDArray max (double d, const NDArray& m); |
184 extern OCTAVE_API NDArray max (const NDArray& m, double d); | |
185 extern OCTAVE_API NDArray max (const NDArray& a, const NDArray& b); | |
4844 | 186 |
6708 | 187 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API) |
188 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API) | |
4543 | 189 |
6708 | 190 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API) |
191 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API) | |
4543 | 192 |
6708 | 193 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API) |
194 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API) | |
4543 | 195 |
4511 | 196 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double) |
197 | |
198 #endif | |
4513 | 199 |
200 /* | |
201 ;;; Local Variables: *** | |
202 ;;; mode: C++ *** | |
203 ;;; End: *** | |
204 */ |