GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dNDArray.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_dNDArray_h)
24 #define octave_dNDArray_h 1
25 
26 #include "MArray.h"
27 #include "intNDArray.h"
28 
29 #include "mx-defs.h"
30 #include "mx-op-decl.h"
31 #include "bsxfun-decl.h"
32 
33 class
34 OCTAVE_API
35 NDArray : public MArray<double>
36 {
37 public:
38 
39  NDArray (void) : MArray<double> () { }
40 
41  NDArray (const dim_vector& dv) : MArray<double> (dv) { }
42 
43  NDArray (const dim_vector& dv, double val)
44  : MArray<double> (dv, val) { }
45 
46  NDArray (const NDArray& a) : MArray<double> (a) { }
47 
48  NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
49  bool negative_to_nan = false);
50 
51  template <class U>
52  NDArray (const MArray<U>& a) : MArray<double> (a) { }
53 
54  template <class U>
55  NDArray (const Array<U>& a) : MArray<double> (a) { }
56 
57  template <class U>
58  explicit NDArray (const intNDArray<U>& a) : MArray<double> (a) { }
59 
60  NDArray (const charNDArray&);
61 
62  // For jit support only
63  NDArray (double *sdata, octave_idx_type slen, octave_idx_type *adims,
64  void *arep)
65  : MArray<double> (sdata, slen, adims, arep) { }
66 
68  {
70  return *this;
71  }
72 
73  // unary operations
74 
75  boolNDArray operator ! (void) const;
76 
77  bool any_element_is_negative (bool = false) const;
78  bool any_element_is_positive (bool = false) const;
79  bool any_element_is_nan (void) const;
80  bool any_element_is_inf_or_nan (void) const;
81  bool any_element_not_one_or_zero (void) const;
82  bool all_elements_are_zero (void) const;
83  bool all_elements_are_int_or_inf_or_nan (void) const;
84  bool all_integers (double& max_val, double& min_val) const;
85  bool all_integers (void) const;
86  bool too_large_for_float (void) const;
87 
88  // FIXME: this is not quite the right thing.
89 
90  boolNDArray all (int dim = -1) const;
91  boolNDArray any (int dim = -1) const;
92 
93  NDArray cumprod (int dim = -1) const;
94  NDArray cumsum (int dim = -1) const;
95  NDArray prod (int dim = -1) const;
96  NDArray sum (int dim = -1) const;
97  NDArray xsum (int dim = -1) const;
98  NDArray sumsq (int dim = -1) const;
102  charNDArray concat (const charNDArray& rb,
104 
105  NDArray max (int dim = -1) const;
106  NDArray max (Array<octave_idx_type>& index, int dim = -1) const;
107  NDArray min (int dim = -1) const;
108  NDArray min (Array<octave_idx_type>& index, int dim = -1) const;
109 
110  NDArray cummax (int dim = -1) const;
111  NDArray cummax (Array<octave_idx_type>& index, int dim = -1) const;
112  NDArray cummin (int dim = -1) const;
113  NDArray cummin (Array<octave_idx_type>& index, int dim = -1) const;
114 
115  NDArray diff (octave_idx_type order = 1, int dim = -1) const;
116 
118  NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx);
119 
120  NDArray abs (void) const;
121  boolNDArray isnan (void) const;
122  boolNDArray isinf (void) const;
123  boolNDArray isfinite (void) const;
124 
125  ComplexNDArray fourier (int dim = 1) const;
126  ComplexNDArray ifourier (int dim = 1) const;
127 
128  ComplexNDArray fourier2d (void) const;
129  ComplexNDArray ifourier2d (void) const;
130 
131  ComplexNDArray fourierNd (void) const;
132  ComplexNDArray ifourierNd (void) const;
133 
134  friend OCTAVE_API NDArray real (const ComplexNDArray& a);
135  friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
136 
137  friend class ComplexNDArray;
138 
139  NDArray squeeze (void) const { return MArray<double>::squeeze (); }
140 
142  const dim_vector& dimensions,
143  int start_dimension = 0);
144 
146  const dim_vector& dimensions);
147 
148  // i/o
149 
150  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
151  const NDArray& a);
152  friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
153 
154  NDArray diag (octave_idx_type k = 0) const;
155 
157 
159  {
161  return *this;
162  }
163 
164 };
165 
166 // Publish externally used friend functions.
167 
168 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
169 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
170 
171 MINMAX_DECLS (NDArray, double, OCTAVE_API)
172 
173 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
174 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
175 
176 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
177 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
178 
179 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
180 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
181 
182 MARRAY_FORWARD_DEFS (MArray, NDArray, double)
183 
184 BSXFUN_STDOP_DECLS (NDArray, OCTAVE_API)
185 BSXFUN_STDREL_DECLS (NDArray, OCTAVE_API)
186 
187 BSXFUN_OP_DECL (pow, NDArray, OCTAVE_API)
188 BSXFUN_OP2_DECL (pow, ComplexNDArray, ComplexNDArray,
189  NDArray, OCTAVE_API)
190 BSXFUN_OP2_DECL (pow, ComplexNDArray, NDArray,
191  ComplexNDArray, OCTAVE_API)
192 
193 #endif
dim_vector dimensions
Definition: Array.h:127
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:178
ComplexMatrix ifourier(void) const
Definition: CMatrix.cc:1292
NDArray(const dim_vector &dv, double val)
Definition: dNDArray.h:43
bool all_integers(double &max_val, double &min_val) const
Definition: CNDArray.cc:536
NDArray & changesign(void)
Definition: dNDArray.h:158
const octave_base_value const Array< octave_idx_type > & ra_idx
bool any_element_is_nan(void) const
Definition: CNDArray.cc:512
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
MArray squeeze(void) const
Definition: MArray.h:81
#define BSXFUN_STDREL_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:51
ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:834
#define NDND_CMP_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:216
#define SND_BOOL_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:197
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:664
#define NDND_BOOL_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:224
OCTAVE_API NDArray max(double d, const NDArray &m)
Definition: dNDArray.cc:909
ComplexNDArray ifourierNd(void) const
Definition: CNDArray.cc:176
NDArray(void)
Definition: dNDArray.h:39
OCTAVE_API NDArray real(const ComplexNDArray &a)
Definition: dNDArray.cc:795
NDArray(double *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
Definition: dNDArray.h:63
#define NDS_BOOL_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:170
void changesign(void)
Definition: MArray.cc:208
ComplexMatrix prod(int dim=-1) const
Definition: CMatrix.cc:3143
bool too_large_for_float(void) const
Definition: CNDArray.cc:586
#define NDS_CMP_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:162
NDArray(const intNDArray< U > &a)
Definition: dNDArray.h:58
#define SND_CMP_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:189
ComplexMatrix cumprod(int dim=-1) const
Definition: CMatrix.cc:3131
NDArray squeeze(void) const
Definition: dNDArray.h:139
ComplexMatrix cumsum(int dim=-1) const
Definition: CMatrix.cc:3137
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
Definition: Array-util.cc:59
boolMatrix all(int dim=-1) const
Definition: CMatrix.cc:3119
ComplexNDArray cummin(int dim=-1) const
Definition: CNDArray.cc:711
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
boolMatrix any(int dim=-1) const
Definition: CMatrix.cc:3125
ComplexMatrix fourier(void) const
Definition: CMatrix.cc:1263
ComplexNDArray & operator=(const ComplexNDArray &a)
Definition: CNDArray.h:55
ComplexNDArray xsum(int dim=-1) const
Definition: CNDArray.cc:628
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray-decl.h:236
ComplexMatrix sumsq(int dim=-1) const
Definition: CMatrix.cc:3155
bool any_element_is_inf_or_nan(void) const
Definition: CNDArray.cc:518
ComplexMatrix & insert(const Matrix &a, octave_idx_type r, octave_idx_type c)
Definition: CMatrix.cc:400
NDArray(const MArray< U > &a)
Definition: dNDArray.h:52
OCTAVE_API NDArray imag(const ComplexNDArray &a)
Definition: dNDArray.cc:801
ComplexNDArray fourierNd(void) const
Definition: CNDArray.cc:161
NDArray(const dim_vector &dv)
Definition: dNDArray.h:41
boolNDArray isfinite(void) const
Definition: CNDArray.cc:741
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
NDArray(const Array< U > &a)
Definition: dNDArray.h:55
ComplexMatrix sum(int dim=-1) const
Definition: CMatrix.cc:3149
ComplexNDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: CNDArray.cc:640
ComplexMatrix ifourier2d(void) const
Definition: CMatrix.cc:1335
boolNDArray isinf(void) const
Definition: CNDArray.cc:735
#define BSXFUN_OP2_DECL(OP, ARRAY, ARRAY1, ARRAY2, API)
Definition: bsxfun-decl.h:30
NDArray(const NDArray &a)
Definition: dNDArray.h:46
#define BSXFUN_STDOP_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:36
octave_value operator!(const octave_value &a)
Definition: ov.h:1293
OCTAVE_API NDArray min(double d, const NDArray &m)
Definition: dNDArray.cc:909
#define MINMAX_DECLS(T, S, API)
Definition: mx-op-decl.h:286
T abs(T x)
Definition: pr-output.cc:3062
ComplexNDArray cummax(int dim=-1) const
Definition: CNDArray.cc:699
MArray< T > & operator=(const MArray< T > &a)
Definition: MArray.h:65
#define BSXFUN_OP_DECL(OP, ARRAY, API)
Definition: bsxfun-decl.h:27
Array< Complex > index(const idx_vector &i) const
Indexing without resizing.
boolNDArray isnan(void) const
Definition: CNDArray.cc:729
ComplexMatrix fourier2d(void) const
Definition: CMatrix.cc:1321