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 |
|
35 NDArray : public MArrayN<double> |
4511
|
36 { |
4513
|
37 public: |
5523
|
38 |
4511
|
39 NDArray (void) : MArrayN<double> () { } |
|
40 |
4587
|
41 NDArray (const dim_vector& dv) : MArrayN<double> (dv) { } |
4511
|
42 |
4587
|
43 NDArray (const dim_vector& dv, double val) |
|
44 : MArrayN<double> (dv, val) { } |
4511
|
45 |
4513
|
46 NDArray (const NDArray& a) : MArrayN<double> (a) { } |
|
47 |
|
48 NDArray (const Matrix& a) : MArrayN<double> (a) { } |
4511
|
49 |
|
50 NDArray (const MArrayN<double>& a) : MArrayN<double> (a) { } |
|
51 |
4902
|
52 template <class U> |
|
53 explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { } |
4543
|
54 |
4511
|
55 NDArray& operator = (const NDArray& a) |
|
56 { |
|
57 MArrayN<double>::operator = (a); |
|
58 return *this; |
|
59 } |
|
60 |
4543
|
61 // unary operations |
|
62 |
|
63 boolNDArray operator ! (void) const; |
|
64 |
4634
|
65 bool any_element_is_negative (bool = false) const; |
|
66 bool any_element_is_inf_or_nan (void) const; |
5943
|
67 bool any_element_not_one_or_zero (void) const; |
4634
|
68 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
69 bool all_integers (double& max_val, double& min_val) const; |
|
70 bool too_large_for_float (void) const; |
|
71 |
5775
|
72 // FIXME -- this is not quite the right thing. |
4513
|
73 |
4556
|
74 boolNDArray all (int dim = -1) const; |
|
75 boolNDArray any (int dim = -1) const; |
4513
|
76 |
4584
|
77 NDArray cumprod (int dim = -1) const; |
|
78 NDArray cumsum (int dim = -1) const; |
4569
|
79 NDArray prod (int dim = -1) const; |
|
80 NDArray sum (int dim = -1) const; |
|
81 NDArray sumsq (int dim = -1) const; |
5275
|
82 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx); |
|
83 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx); |
|
84 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx); |
4844
|
85 |
|
86 NDArray max (int dim = 0) const; |
5275
|
87 NDArray max (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844
|
88 NDArray min (int dim = 0) const; |
5275
|
89 NDArray min (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844
|
90 |
5275
|
91 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c); |
|
92 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx); |
4915
|
93 |
4634
|
94 NDArray abs (void) const; |
|
95 |
4773
|
96 ComplexNDArray fourier (int dim = 1) const; |
|
97 ComplexNDArray ifourier (int dim = 1) const; |
|
98 |
|
99 ComplexNDArray fourier2d (void) const; |
|
100 ComplexNDArray ifourier2d (void) const; |
|
101 |
|
102 ComplexNDArray fourierNd (void) const; |
|
103 ComplexNDArray ifourierNd (void) const; |
|
104 |
4634
|
105 friend NDArray real (const ComplexNDArray& a); |
|
106 friend NDArray imag (const ComplexNDArray& a); |
4569
|
107 |
4513
|
108 Matrix matrix_value (void) const; |
|
109 |
4902
|
110 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); } |
4532
|
111 |
5275
|
112 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532
|
113 const dim_vector& dimensions, |
|
114 int start_dimension = 0); |
|
115 |
5275
|
116 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556
|
117 const dim_vector& dimensions); |
|
118 |
4511
|
119 // i/o |
|
120 |
4687
|
121 friend std::ostream& operator << (std::ostream& os, const NDArray& a); |
|
122 friend std::istream& operator >> (std::istream& is, NDArray& a); |
4511
|
123 |
|
124 static double resize_fill_value (void) { return 0; } |
|
125 |
4513
|
126 private: |
4511
|
127 |
4634
|
128 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { } |
4511
|
129 }; |
|
130 |
5508
|
131 // Publish externally used friend functions. |
|
132 |
|
133 extern NDArray real (const ComplexNDArray& a); |
|
134 extern NDArray imag (const ComplexNDArray& a); |
|
135 |
4844
|
136 extern NDArray min (double d, const NDArray& m); |
|
137 extern NDArray min (const NDArray& m, double d); |
|
138 extern NDArray min (const NDArray& a, const NDArray& b); |
|
139 |
|
140 extern NDArray max (double d, const NDArray& m); |
|
141 extern NDArray max (const NDArray& m, double d); |
|
142 extern NDArray max (const NDArray& a, const NDArray& b); |
|
143 |
4543
|
144 NDS_CMP_OP_DECLS (NDArray, double) |
|
145 NDS_BOOL_OP_DECLS (NDArray, double) |
|
146 |
|
147 SND_CMP_OP_DECLS (double, NDArray) |
|
148 SND_BOOL_OP_DECLS (double, NDArray) |
|
149 |
|
150 NDND_CMP_OP_DECLS (NDArray, NDArray) |
|
151 NDND_BOOL_OP_DECLS (NDArray, NDArray) |
|
152 |
4511
|
153 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double) |
|
154 |
|
155 #endif |
4513
|
156 |
|
157 /* |
|
158 ;;; Local Variables: *** |
|
159 ;;; mode: C++ *** |
|
160 ;;; End: *** |
|
161 */ |