Mercurial > hg > octave-nkf
annotate liboctave/dNDArray.h @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 724c0f46d9d4 |
children | d91fa4b20bbb |
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 |
4511 | 40 NDArray (void) : MArrayN<double> () { } |
41 | |
4587 | 42 NDArray (const dim_vector& dv) : MArrayN<double> (dv) { } |
4511 | 43 |
4587 | 44 NDArray (const dim_vector& dv, double val) |
45 : MArrayN<double> (dv, val) { } | |
4511 | 46 |
4513 | 47 NDArray (const NDArray& a) : MArrayN<double> (a) { } |
48 | |
49 NDArray (const Matrix& a) : MArrayN<double> (a) { } | |
4511 | 50 |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
51 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
|
52 bool negative_to_nan = false); |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
53 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
54 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
55 NDArray (const MArrayN<U>& a) : MArrayN<double> (a) { } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
56 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
57 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
58 NDArray (const ArrayN<U>& a) : MArrayN<double> (a) { } |
4511 | 59 |
4902 | 60 template <class U> |
61 explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { } | |
4543 | 62 |
4511 | 63 NDArray& operator = (const NDArray& a) |
64 { | |
65 MArrayN<double>::operator = (a); | |
66 return *this; | |
67 } | |
68 | |
4543 | 69 // unary operations |
70 | |
71 boolNDArray operator ! (void) const; | |
72 | |
4634 | 73 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
|
74 bool any_element_is_nan (void) const; |
4634 | 75 bool any_element_is_inf_or_nan (void) const; |
5943 | 76 bool any_element_not_one_or_zero (void) const; |
6989 | 77 bool all_elements_are_zero (void) const; |
4634 | 78 bool all_elements_are_int_or_inf_or_nan (void) const; |
79 bool all_integers (double& max_val, double& min_val) const; | |
80 bool too_large_for_float (void) const; | |
81 | |
5775 | 82 // FIXME -- this is not quite the right thing. |
4513 | 83 |
4556 | 84 boolNDArray all (int dim = -1) const; |
85 boolNDArray any (int dim = -1) const; | |
4513 | 86 |
4584 | 87 NDArray cumprod (int dim = -1) const; |
88 NDArray cumsum (int dim = -1) const; | |
4569 | 89 NDArray prod (int dim = -1) const; |
90 NDArray sum (int dim = -1) const; | |
91 NDArray sumsq (int dim = -1) const; | |
5275 | 92 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx); |
93 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx); | |
94 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx); | |
4844 | 95 |
96 NDArray max (int dim = 0) const; | |
5275 | 97 NDArray max (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844 | 98 NDArray min (int dim = 0) const; |
5275 | 99 NDArray min (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844 | 100 |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
101 NDArray cummax (int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
102 NDArray cummax (ArrayN<octave_idx_type>& index, int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
103 NDArray cummin (int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
104 NDArray cummin (ArrayN<octave_idx_type>& index, int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
105 |
5275 | 106 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c); |
107 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx); | |
4915 | 108 |
4634 | 109 NDArray abs (void) const; |
110 | |
4773 | 111 ComplexNDArray fourier (int dim = 1) const; |
112 ComplexNDArray ifourier (int dim = 1) const; | |
113 | |
114 ComplexNDArray fourier2d (void) const; | |
115 ComplexNDArray ifourier2d (void) const; | |
116 | |
117 ComplexNDArray fourierNd (void) const; | |
118 ComplexNDArray ifourierNd (void) const; | |
119 | |
6108 | 120 friend OCTAVE_API NDArray real (const ComplexNDArray& a); |
121 friend OCTAVE_API NDArray imag (const ComplexNDArray& a); | |
4569 | 122 |
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
|
123 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
|
124 |
4513 | 125 Matrix matrix_value (void) const; |
126 | |
4902 | 127 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); } |
4532 | 128 |
5275 | 129 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 130 const dim_vector& dimensions, |
131 int start_dimension = 0); | |
132 | |
5275 | 133 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556 | 134 const dim_vector& dimensions); |
135 | |
4511 | 136 // i/o |
137 | |
6108 | 138 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const NDArray& a); |
139 friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a); | |
4511 | 140 |
141 static double resize_fill_value (void) { return 0; } | |
142 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
143 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
|
144 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
145 typedef double (*dmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
146 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
147 typedef bool (*bmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
148 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 NDArray map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 ComplexNDArray map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
151 boolNDArray map (bmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
152 |
4513 | 153 private: |
4511 | 154 |
4634 | 155 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { } |
4511 | 156 }; |
157 | |
5508 | 158 // Publish externally used friend functions. |
159 | |
6108 | 160 extern OCTAVE_API NDArray real (const ComplexNDArray& a); |
161 extern OCTAVE_API NDArray imag (const ComplexNDArray& a); | |
5508 | 162 |
6108 | 163 extern OCTAVE_API NDArray min (double d, const NDArray& m); |
164 extern OCTAVE_API NDArray min (const NDArray& m, double d); | |
165 extern OCTAVE_API NDArray min (const NDArray& a, const NDArray& b); | |
4844 | 166 |
6108 | 167 extern OCTAVE_API NDArray max (double d, const NDArray& m); |
168 extern OCTAVE_API NDArray max (const NDArray& m, double d); | |
169 extern OCTAVE_API NDArray max (const NDArray& a, const NDArray& b); | |
4844 | 170 |
6708 | 171 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API) |
172 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API) | |
4543 | 173 |
6708 | 174 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API) |
175 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API) | |
4543 | 176 |
6708 | 177 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API) |
178 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API) | |
4543 | 179 |
4511 | 180 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double) |
181 | |
182 #endif | |
4513 | 183 |
184 /* | |
185 ;;; Local Variables: *** | |
186 ;;; mode: C++ *** | |
187 ;;; End: *** | |
188 */ |