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: |
4511
|
38 |
|
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; |
|
67 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
68 bool all_integers (double& max_val, double& min_val) const; |
|
69 bool too_large_for_float (void) const; |
|
70 |
4513
|
71 // XXX FIXME XXX -- this is not quite the right thing. |
|
72 |
4556
|
73 boolNDArray all (int dim = -1) const; |
|
74 boolNDArray any (int dim = -1) const; |
4513
|
75 |
4584
|
76 NDArray cumprod (int dim = -1) const; |
|
77 NDArray cumsum (int dim = -1) const; |
4569
|
78 NDArray prod (int dim = -1) const; |
|
79 NDArray sum (int dim = -1) const; |
|
80 NDArray sumsq (int dim = -1) const; |
5275
|
81 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx); |
|
82 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx); |
|
83 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx); |
4844
|
84 |
|
85 NDArray max (int dim = 0) const; |
5275
|
86 NDArray max (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844
|
87 NDArray min (int dim = 0) const; |
5275
|
88 NDArray min (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844
|
89 |
5275
|
90 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c); |
|
91 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx); |
4915
|
92 |
4634
|
93 NDArray abs (void) const; |
|
94 |
4773
|
95 ComplexNDArray fourier (int dim = 1) const; |
|
96 ComplexNDArray ifourier (int dim = 1) const; |
|
97 |
|
98 ComplexNDArray fourier2d (void) const; |
|
99 ComplexNDArray ifourier2d (void) const; |
|
100 |
|
101 ComplexNDArray fourierNd (void) const; |
|
102 ComplexNDArray ifourierNd (void) const; |
|
103 |
4634
|
104 friend NDArray real (const ComplexNDArray& a); |
|
105 friend NDArray imag (const ComplexNDArray& a); |
4569
|
106 |
4513
|
107 Matrix matrix_value (void) const; |
|
108 |
4902
|
109 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); } |
4532
|
110 |
5275
|
111 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532
|
112 const dim_vector& dimensions, |
|
113 int start_dimension = 0); |
|
114 |
5275
|
115 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556
|
116 const dim_vector& dimensions); |
|
117 |
4511
|
118 // i/o |
|
119 |
4687
|
120 friend std::ostream& operator << (std::ostream& os, const NDArray& a); |
|
121 friend std::istream& operator >> (std::istream& is, NDArray& a); |
4511
|
122 |
|
123 static double resize_fill_value (void) { return 0; } |
|
124 |
4513
|
125 private: |
4511
|
126 |
4634
|
127 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { } |
4511
|
128 }; |
|
129 |
4844
|
130 extern NDArray min (double d, const NDArray& m); |
|
131 extern NDArray min (const NDArray& m, double d); |
|
132 extern NDArray min (const NDArray& a, const NDArray& b); |
|
133 |
|
134 extern NDArray max (double d, const NDArray& m); |
|
135 extern NDArray max (const NDArray& m, double d); |
|
136 extern NDArray max (const NDArray& a, const NDArray& b); |
|
137 |
4543
|
138 NDS_CMP_OP_DECLS (NDArray, double) |
|
139 NDS_BOOL_OP_DECLS (NDArray, double) |
|
140 |
|
141 SND_CMP_OP_DECLS (double, NDArray) |
|
142 SND_BOOL_OP_DECLS (double, NDArray) |
|
143 |
|
144 NDND_CMP_OP_DECLS (NDArray, NDArray) |
|
145 NDND_BOOL_OP_DECLS (NDArray, NDArray) |
|
146 |
4511
|
147 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double) |
|
148 |
|
149 #endif |
4513
|
150 |
|
151 /* |
|
152 ;;; Local Variables: *** |
|
153 ;;; mode: C++ *** |
|
154 ;;; End: *** |
|
155 */ |