GNU Octave  4.2.1
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-2017 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 "octave-config.h"
27 
28 #include "MArray.h"
29 
30 #include "mx-defs.h"
31 #include "mx-op-decl.h"
32 #include "bsxfun-decl.h"
33 
34 template <typename T> class intNDArray;
35 
36 class
37 OCTAVE_API
38 NDArray : public MArray<double>
39 {
40 public:
41 
42  NDArray (void) : MArray<double> () { }
43 
44  NDArray (const dim_vector& dv) : MArray<double> (dv) { }
45 
46  NDArray (const dim_vector& dv, double val)
47  : MArray<double> (dv, val) { }
48 
49  NDArray (const NDArray& a) : MArray<double> (a) { }
50 
51  NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
52  bool negative_to_nan = false);
53 
54  template <typename U>
55  NDArray (const MArray<U>& a) : MArray<double> (a) { }
56 
57  template <typename U>
58  NDArray (const Array<U>& a) : MArray<double> (a) { }
59 
60  template <typename U>
61  explicit NDArray (const intNDArray<U>& a) : MArray<double> (a) { }
62 
63  NDArray (const charNDArray&);
64 
65  // For jit support only
66  NDArray (double *sdata, octave_idx_type slen, octave_idx_type *adims,
67  void *arep)
68  : MArray<double> (sdata, slen, adims, arep) { }
69 
71  {
73  return *this;
74  }
75 
76  // unary operations
77 
78  boolNDArray operator ! (void) const;
79 
80  bool any_element_is_negative (bool = false) const;
81  bool any_element_is_positive (bool = false) const;
82  bool any_element_is_nan (void) const;
83  bool any_element_is_inf_or_nan (void) const;
84  bool any_element_not_one_or_zero (void) const;
85  bool all_elements_are_zero (void) const;
86  bool all_elements_are_int_or_inf_or_nan (void) const;
87  bool all_integers (double& max_val, double& min_val) const;
88  bool all_integers (void) const;
89  bool too_large_for_float (void) const;
90 
91  // FIXME: this is not quite the right thing.
92 
93  boolNDArray all (int dim = -1) const;
94  boolNDArray any (int dim = -1) const;
95 
96  NDArray cumprod (int dim = -1) const;
97  NDArray cumsum (int dim = -1) const;
98  NDArray prod (int dim = -1) const;
99  NDArray sum (int dim = -1) const;
100  NDArray xsum (int dim = -1) const;
101  NDArray sumsq (int dim = -1) const;
102  NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx);
105  charNDArray concat (const charNDArray& rb,
107 
108  NDArray max (int dim = -1) const;
109  NDArray max (Array<octave_idx_type>& index, int dim = -1) const;
110  NDArray min (int dim = -1) const;
111  NDArray min (Array<octave_idx_type>& index, int dim = -1) const;
112 
113  NDArray cummax (int dim = -1) const;
114  NDArray cummax (Array<octave_idx_type>& index, int dim = -1) const;
115  NDArray cummin (int dim = -1) const;
116  NDArray cummin (Array<octave_idx_type>& index, int dim = -1) const;
117 
118  NDArray diff (octave_idx_type order = 1, int dim = -1) const;
119 
122 
123  NDArray abs (void) const;
124  boolNDArray isnan (void) const;
125  boolNDArray isinf (void) const;
126  boolNDArray isfinite (void) const;
127 
128  ComplexNDArray fourier (int dim = 1) const;
129  ComplexNDArray ifourier (int dim = 1) const;
130 
131  ComplexNDArray fourier2d (void) const;
132  ComplexNDArray ifourier2d (void) const;
133 
134  ComplexNDArray fourierNd (void) const;
135  ComplexNDArray ifourierNd (void) const;
136 
137  friend OCTAVE_API NDArray real (const ComplexNDArray& a);
138  friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
139 
140  friend class ComplexNDArray;
141 
142  NDArray squeeze (void) const { return MArray<double>::squeeze (); }
143 
145  const dim_vector& dimensions,
146  int start_dimension = 0);
147 
149  const dim_vector& dimensions);
150 
151  // i/o
152 
153  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
154  const NDArray& a);
155  friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
156 
157  NDArray diag (octave_idx_type k = 0) const;
158 
160 
162  {
164  return *this;
165  }
166 
167 };
168 
169 // Publish externally used friend functions.
170 
171 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
172 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
173 
174 MINMAX_DECLS (NDArray, double, OCTAVE_API)
175 
176 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
177 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
178 
179 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
180 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
181 
182 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
183 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
184 
185 MARRAY_FORWARD_DEFS (MArray, NDArray, double)
186 
187 BSXFUN_STDOP_DECLS (NDArray, OCTAVE_API)
188 BSXFUN_STDREL_DECLS (NDArray, OCTAVE_API)
189 
190 BSXFUN_OP_DECL (pow, NDArray, OCTAVE_API)
191 BSXFUN_OP2_DECL (pow, ComplexNDArray, ComplexNDArray,
192  NDArray, OCTAVE_API)
193 BSXFUN_OP2_DECL (pow, ComplexNDArray, NDArray,
194  ComplexNDArray, OCTAVE_API)
195 
196 #endif
dim_vector dimensions
Definition: Array.h:214
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:176
NDArray(const dim_vector &dv, double val)
Definition: dNDArray.h:46
bool any_element_not_one_or_zero(void) const
Definition: intNDArray.cc:50
NDArray & changesign(void)
Definition: dNDArray.h:161
const octave_base_value const Array< octave_idx_type > & ra_idx
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
MArray squeeze(void) const
Definition: MArray.h:101
#define BSXFUN_STDREL_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:53
ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:821
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
#define NDND_CMP_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:218
bool isnan(double x)
Definition: lo-mappers.cc:347
for large enough k
Definition: lu.cc:606
#define SND_BOOL_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:199
intNDArray & insert(const intNDArray< T > &a, octave_idx_type r, octave_idx_type c)
Definition: intNDArray.cc:124
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:655
#define NDND_BOOL_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:226
OCTAVE_API NDArray max(double d, const NDArray &m)
Definition: dNDArray.cc:893
NDArray(void)
Definition: dNDArray.h:42
intNDArray cumsum(int dim) const
Definition: intNDArray.cc:235
OCTAVE_API NDArray real(const ComplexNDArray &a)
Definition: dNDArray.cc:781
NDArray(double *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
Definition: dNDArray.h:66
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray.h:126
#define NDS_BOOL_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:172
void changesign(void)
Definition: MArray.cc:204
intNDArray sum(int dim) const
Definition: intNDArray.cc:221
#define NDS_CMP_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:164
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
NDArray(const intNDArray< U > &a)
Definition: dNDArray.h:61
intNDArray cummin(int dim=-1) const
Definition: intNDArray.cc:284
#define SND_CMP_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:191
intNDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: intNDArray.cc:298
NDArray squeeze(void) const
Definition: dNDArray.h:142
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
Definition: Array-util.cc:59
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
NDArray(const MArray< U > &a)
Definition: dNDArray.h:55
OCTAVE_API NDArray imag(const ComplexNDArray &a)
Definition: dNDArray.cc:787
bool isinf(double x)
Definition: lo-mappers.cc:387
intNDArray cummax(int dim=-1) const
Definition: intNDArray.cc:270
NDArray(const dim_vector &dv)
Definition: dNDArray.h:44
intNDArray & operator=(const intNDArray< T > &a)
Definition: intNDArray.h:58
bool any_element_is_nan(void) const
Definition: intNDArray.h:66
OCTAVE_EXPORT octave_value_list return the value of the option it must match the dimension of the state and the relative tolerance must also be a vector of the same length tem it must match the dimension of the state and the absolute tolerance must also be a vector of the same length The local error test applied at each integration step is xample roup abs(local error in x(i))<
boolNDArray all(int dim=-1) const
Definition: intNDArray.cc:83
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
issues an error eealso double
Definition: ov-bool-mat.cc:594
NDArray(const Array< U > &a)
Definition: dNDArray.h:58
#define BSXFUN_OP2_DECL(OP, ARRAY, ARRAY1, ARRAY2, API)
Definition: bsxfun-decl.h:32
NDArray(const NDArray &a)
Definition: dNDArray.h:49
#define BSXFUN_STDOP_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:38
octave_value operator!(const octave_value &a)
Definition: ov.h:1484
intNDArray prod(int dim) const
Definition: intNDArray.cc:214
OCTAVE_API NDArray min(double d, const NDArray &m)
Definition: dNDArray.cc:893
write the output to stdout if nargout is
Definition: load-save.cc:1576
#define MINMAX_DECLS(T, S, API)
Definition: mx-op-decl.h:288
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
the second is matched to the second specifier and placed in the second column and so forth If there are more words than specifiers then the process is repeated until all words have been processed or the limit imposed by any(non-whitespace) text in the format that is not one of these specifiers is considered a literal.If there is a literal between two format specifiers then that same literal must appear in the input stream between the matching words.The following specifiers are valid
Definition: file-io.cc:1491
dim_vector dv
Definition: sub2ind.cc:263
MArray< T > & operator=(const MArray< T > &a)
Definition: MArray.h:85
#define BSXFUN_OP_DECL(OP, ARRAY, API)
Definition: bsxfun-decl.h:29
Array< T > index(const idx_vector &i) const
Indexing without resizing.
Definition: Array.cc:718