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