4511
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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" |
|
32 #include "mx-op-defs.h" |
|
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 |
|
51 NDArray (const MArrayN<double>& a) : MArrayN<double> (a) { } |
|
52 |
4902
|
53 template <class U> |
|
54 explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { } |
4543
|
55 |
4511
|
56 NDArray& operator = (const NDArray& a) |
|
57 { |
|
58 MArrayN<double>::operator = (a); |
|
59 return *this; |
|
60 } |
|
61 |
4543
|
62 // unary operations |
|
63 |
|
64 boolNDArray operator ! (void) const; |
|
65 |
4634
|
66 bool any_element_is_negative (bool = false) const; |
|
67 bool any_element_is_inf_or_nan (void) const; |
5943
|
68 bool any_element_not_one_or_zero (void) const; |
6989
|
69 bool all_elements_are_zero (void) const; |
4634
|
70 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
71 bool all_integers (double& max_val, double& min_val) const; |
|
72 bool too_large_for_float (void) const; |
|
73 |
5775
|
74 // FIXME -- this is not quite the right thing. |
4513
|
75 |
4556
|
76 boolNDArray all (int dim = -1) const; |
|
77 boolNDArray any (int dim = -1) const; |
4513
|
78 |
4584
|
79 NDArray cumprod (int dim = -1) const; |
|
80 NDArray cumsum (int dim = -1) const; |
4569
|
81 NDArray prod (int dim = -1) const; |
|
82 NDArray sum (int dim = -1) const; |
|
83 NDArray sumsq (int dim = -1) const; |
5275
|
84 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx); |
|
85 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx); |
|
86 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx); |
4844
|
87 |
|
88 NDArray max (int dim = 0) const; |
5275
|
89 NDArray max (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844
|
90 NDArray min (int dim = 0) const; |
5275
|
91 NDArray min (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844
|
92 |
5275
|
93 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c); |
|
94 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx); |
4915
|
95 |
4634
|
96 NDArray abs (void) const; |
|
97 |
4773
|
98 ComplexNDArray fourier (int dim = 1) const; |
|
99 ComplexNDArray ifourier (int dim = 1) const; |
|
100 |
|
101 ComplexNDArray fourier2d (void) const; |
|
102 ComplexNDArray ifourier2d (void) const; |
|
103 |
|
104 ComplexNDArray fourierNd (void) const; |
|
105 ComplexNDArray ifourierNd (void) const; |
|
106 |
6108
|
107 friend OCTAVE_API NDArray real (const ComplexNDArray& a); |
|
108 friend OCTAVE_API NDArray imag (const ComplexNDArray& a); |
4569
|
109 |
4513
|
110 Matrix matrix_value (void) const; |
|
111 |
4902
|
112 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); } |
4532
|
113 |
5275
|
114 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532
|
115 const dim_vector& dimensions, |
|
116 int start_dimension = 0); |
|
117 |
5275
|
118 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556
|
119 const dim_vector& dimensions); |
|
120 |
4511
|
121 // i/o |
|
122 |
6108
|
123 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const NDArray& a); |
|
124 friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a); |
4511
|
125 |
|
126 static double resize_fill_value (void) { return 0; } |
|
127 |
4513
|
128 private: |
4511
|
129 |
4634
|
130 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { } |
4511
|
131 }; |
|
132 |
5508
|
133 // Publish externally used friend functions. |
|
134 |
6108
|
135 extern OCTAVE_API NDArray real (const ComplexNDArray& a); |
|
136 extern OCTAVE_API NDArray imag (const ComplexNDArray& a); |
5508
|
137 |
6108
|
138 extern OCTAVE_API NDArray min (double d, const NDArray& m); |
|
139 extern OCTAVE_API NDArray min (const NDArray& m, double d); |
|
140 extern OCTAVE_API NDArray min (const NDArray& a, const NDArray& b); |
4844
|
141 |
6108
|
142 extern OCTAVE_API NDArray max (double d, const NDArray& m); |
|
143 extern OCTAVE_API NDArray max (const NDArray& m, double d); |
|
144 extern OCTAVE_API NDArray max (const NDArray& a, const NDArray& b); |
4844
|
145 |
6708
|
146 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API) |
|
147 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API) |
4543
|
148 |
6708
|
149 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API) |
|
150 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API) |
4543
|
151 |
6708
|
152 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API) |
|
153 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API) |
4543
|
154 |
4511
|
155 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double) |
|
156 |
|
157 #endif |
4513
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; End: *** |
|
163 */ |