00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_NDArray_h)
00025 #define octave_NDArray_h 1
00026
00027 #include "MArrayN.h"
00028 #include "dMatrix.h"
00029 #include "intNDArray.h"
00030
00031 #include "mx-defs.h"
00032 #include "mx-op-decl.h"
00033
00034 class
00035 OCTAVE_API
00036 NDArray : public MArrayN<double>
00037 {
00038 public:
00039
00040 typedef Matrix matrix_type;
00041
00042 NDArray (void) : MArrayN<double> () { }
00043
00044 NDArray (const dim_vector& dv) : MArrayN<double> (dv) { }
00045
00046 NDArray (const dim_vector& dv, double val)
00047 : MArrayN<double> (dv, val) { }
00048
00049 NDArray (const NDArray& a) : MArrayN<double> (a) { }
00050
00051 NDArray (const Matrix& a) : MArrayN<double> (a) { }
00052
00053 NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
00054 bool negative_to_nan = false);
00055
00056 template <class U>
00057 NDArray (const MArrayN<U>& a) : MArrayN<double> (a) { }
00058
00059 template <class U>
00060 NDArray (const Array<U>& a) : MArrayN<double> (a) { }
00061
00062 template <class U>
00063 explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { }
00064
00065 NDArray (const charNDArray&);
00066
00067 NDArray& operator = (const NDArray& a)
00068 {
00069 MArrayN<double>::operator = (a);
00070 return *this;
00071 }
00072
00073
00074
00075 boolNDArray operator ! (void) const;
00076
00077 bool any_element_is_negative (bool = false) const;
00078 bool any_element_is_nan (void) const;
00079 bool any_element_is_inf_or_nan (void) const;
00080 bool any_element_not_one_or_zero (void) const;
00081 bool all_elements_are_zero (void) const;
00082 bool all_elements_are_int_or_inf_or_nan (void) const;
00083 bool all_integers (double& max_val, double& min_val) const;
00084 bool too_large_for_float (void) const;
00085
00086
00087
00088 boolNDArray all (int dim = -1) const;
00089 boolNDArray any (int dim = -1) const;
00090
00091 NDArray cumprod (int dim = -1) const;
00092 NDArray cumsum (int dim = -1) const;
00093 NDArray prod (int dim = -1) const;
00094 NDArray sum (int dim = -1) const;
00095 NDArray xsum (int dim = -1) const;
00096 NDArray sumsq (int dim = -1) const;
00097 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx);
00098 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx);
00099 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx);
00100
00101 NDArray max (int dim = 0) const;
00102 NDArray max (Array<octave_idx_type>& index, int dim = 0) const;
00103 NDArray min (int dim = 0) const;
00104 NDArray min (Array<octave_idx_type>& index, int dim = 0) const;
00105
00106 NDArray cummax (int dim = 0) const;
00107 NDArray cummax (Array<octave_idx_type>& index, int dim = 0) const;
00108 NDArray cummin (int dim = 0) const;
00109 NDArray cummin (Array<octave_idx_type>& index, int dim = 0) const;
00110
00111 NDArray diff (octave_idx_type order = 1, int dim = 0) const;
00112
00113 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c);
00114 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx);
00115
00116 NDArray abs (void) const;
00117 boolNDArray isnan (void) const;
00118 boolNDArray isinf (void) const;
00119 boolNDArray isfinite (void) const;
00120
00121 ComplexNDArray fourier (int dim = 1) const;
00122 ComplexNDArray ifourier (int dim = 1) const;
00123
00124 ComplexNDArray fourier2d (void) const;
00125 ComplexNDArray ifourier2d (void) const;
00126
00127 ComplexNDArray fourierNd (void) const;
00128 ComplexNDArray ifourierNd (void) const;
00129
00130 friend OCTAVE_API NDArray real (const ComplexNDArray& a);
00131 friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
00132
00133 friend class ComplexNDArray;
00134
00135 Matrix matrix_value (void) const;
00136
00137 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); }
00138
00139 static void increment_index (Array<octave_idx_type>& ra_idx,
00140 const dim_vector& dimensions,
00141 int start_dimension = 0);
00142
00143 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx,
00144 const dim_vector& dimensions);
00145
00146
00147
00148 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const NDArray& a);
00149 friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
00150
00151 static double resize_fill_value (void) { return 0; }
00152
00153 NDArray diag (octave_idx_type k = 0) const;
00154
00155 NDArray& changesign (void)
00156 {
00157 MArrayN<double>::changesign ();
00158 return *this;
00159 }
00160
00161 typedef double (*dmapper) (double);
00162 typedef Complex (*cmapper) (const Complex&);
00163 typedef bool (*bmapper) (double);
00164
00165 NDArray map (dmapper fcn) const;
00166 ComplexNDArray map (cmapper fcn) const;
00167 boolNDArray map (bmapper fcn) const;
00168
00169 private:
00170
00171 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { }
00172 };
00173
00174
00175
00176 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
00177 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
00178
00179 extern OCTAVE_API NDArray min (double d, const NDArray& m);
00180 extern OCTAVE_API NDArray min (const NDArray& m, double d);
00181 extern OCTAVE_API NDArray min (const NDArray& a, const NDArray& b);
00182
00183 extern OCTAVE_API NDArray max (double d, const NDArray& m);
00184 extern OCTAVE_API NDArray max (const NDArray& m, double d);
00185 extern OCTAVE_API NDArray max (const NDArray& a, const NDArray& b);
00186
00187 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
00188 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
00189
00190 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
00191 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
00192
00193 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
00194 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
00195
00196 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double)
00197
00198 #endif
00199
00200
00201
00202
00203
00204