GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
dNDArray.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 #include "bsxfun-decl.h"
30 #include "mx-defs.h"
31 #include "mx-op-decl.h"
32 
33 template <typename T> class intNDArray;
34 
35 class
36 OCTAVE_API
37 NDArray : public MArray<double>
38 {
39 public:
40 
41  NDArray (void) : MArray<double> () { }
42 
43  NDArray (const dim_vector& dv) : MArray<double> (dv) { }
44 
45  NDArray (const dim_vector& dv, double val)
46  : MArray<double> (dv, val) { }
47 
48  NDArray (const NDArray& a) : MArray<double> (a) { }
49 
50  NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
51  bool negative_to_nan = false);
52 
53  template <typename U>
54  NDArray (const MArray<U>& a) : MArray<double> (a) { }
55 
56  template <typename U>
57  NDArray (const Array<U>& a) : MArray<double> (a) { }
58 
59  template <typename U>
60  explicit NDArray (const intNDArray<U>& a) : MArray<double> (a) { }
61 
62  NDArray (const charNDArray&);
63 
64  // For jit support only
65  NDArray (double *sdata, octave_idx_type slen, octave_idx_type *adims,
66  void *arep)
67  : MArray<double> (sdata, slen, adims, arep) { }
68 
70  {
72  return *this;
73  }
74 
75  // unary operations
76 
77  boolNDArray operator ! (void) const;
78 
79  bool any_element_is_negative (bool = false) const;
80  bool any_element_is_positive (bool = false) const;
81  bool any_element_is_nan (void) const;
82  bool any_element_is_inf_or_nan (void) const;
83  bool any_element_not_one_or_zero (void) const;
84  bool all_elements_are_zero (void) const;
85  bool all_elements_are_int_or_inf_or_nan (void) const;
86  bool all_integers (double& max_val, double& min_val) const;
87  bool all_integers (void) const;
88  bool too_large_for_float (void) const;
89 
90  // FIXME: this is not quite the right thing.
91 
92  boolNDArray all (int dim = -1) const;
93  boolNDArray any (int dim = -1) const;
94 
95  NDArray cumprod (int dim = -1) const;
96  NDArray cumsum (int dim = -1) const;
97  NDArray prod (int dim = -1) const;
98  NDArray sum (int dim = -1) const;
99  NDArray xsum (int dim = -1) const;
100  NDArray sumsq (int dim = -1) const;
101  NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx);
104  charNDArray concat (const charNDArray& rb,
106 
107  NDArray max (int dim = -1) const;
108  NDArray max (Array<octave_idx_type>& index, int dim = -1) const;
109  NDArray min (int dim = -1) const;
110  NDArray min (Array<octave_idx_type>& index, int dim = -1) const;
111 
112  NDArray cummax (int dim = -1) const;
113  NDArray cummax (Array<octave_idx_type>& index, int dim = -1) const;
114  NDArray cummin (int dim = -1) const;
115  NDArray cummin (Array<octave_idx_type>& index, int dim = -1) const;
116 
117  NDArray diff (octave_idx_type order = 1, int dim = -1) const;
118 
121 
122  NDArray abs (void) const;
123  boolNDArray isnan (void) const;
124  boolNDArray isinf (void) const;
125  boolNDArray isfinite (void) const;
126 
127  ComplexNDArray fourier (int dim = 1) const;
128  ComplexNDArray ifourier (int dim = 1) const;
129 
130  ComplexNDArray fourier2d (void) const;
131  ComplexNDArray ifourier2d (void) const;
132 
133  ComplexNDArray fourierNd (void) const;
134  ComplexNDArray ifourierNd (void) const;
135 
136  friend OCTAVE_API NDArray real (const ComplexNDArray& a);
137  friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
138 
139  friend class ComplexNDArray;
140 
141  NDArray squeeze (void) const { return MArray<double>::squeeze (); }
142 
144  const dim_vector& dimensions,
145  int start_dimension = 0);
146 
148  const dim_vector& dimensions);
149 
150  // i/o
151 
152  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
153  const NDArray& a);
154  friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
155 
156  NDArray diag (octave_idx_type k = 0) const;
157 
159 
161  {
163  return *this;
164  }
165 
166 };
167 
168 // Publish externally used friend functions.
169 
170 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
171 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
172 
173 MINMAX_DECLS (NDArray, double, OCTAVE_API)
174 
175 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
176 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
177 
178 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
179 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
180 
181 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
182 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
183 
185 
186 BSXFUN_STDOP_DECLS (NDArray, OCTAVE_API)
187 BSXFUN_STDREL_DECLS (NDArray, OCTAVE_API)
188 
189 BSXFUN_OP_DECL (pow, NDArray, OCTAVE_API)
191  NDArray, OCTAVE_API)
193  ComplexNDArray, OCTAVE_API)
194 
195 #endif
dim_vector dimensions
Definition: Array.h:216
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:175
intNDArray cummin(int dim=-1) const
Definition: intNDArray.cc:283
intNDArray cumsum(int dim) const
Definition: intNDArray.cc:234
NDArray(const dim_vector &dv, double val)
Definition: dNDArray.h:45
NDArray & changesign(void)
Definition: dNDArray.h:160
bool any_element_is_nan(void) const
Definition: intNDArray.h:67
const octave_base_value const Array< octave_idx_type > & ra_idx
intNDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: intNDArray.cc:297
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
#define BSXFUN_STDREL_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:51
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
#define NDND_CMP_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:218
void changesign(void)
Definition: MArray.cc:204
for large enough k
Definition: lu.cc:617
#define SND_BOOL_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:199
bool isnan(bool)
Definition: lo-mappers.h:187
ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:819
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
#define NDND_BOOL_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:226
bool isinf(double x)
Definition: lo-mappers.h:225
OCTAVE_API NDArray max(double d, const NDArray &m)
Definition: dNDArray.cc:891
intNDArray sum(int dim) const
Definition: intNDArray.cc:220
static T abs(T x)
Definition: pr-output.cc:1696
NDArray(void)
Definition: dNDArray.h:41
OCTAVE_API NDArray real(const ComplexNDArray &a)
Definition: dNDArray.cc:779
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:1499
NDArray(double *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
Definition: dNDArray.h:65
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
#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
#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:400
NDArray(const intNDArray< U > &a)
Definition: dNDArray.h:60
#define SND_CMP_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:191
Array< T > index(const idx_vector &i) const
Indexing without resizing.
Definition: Array.cc:697
bool any_element_not_one_or_zero(void) const
Definition: intNDArray.cc:49
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
Definition: Array-util.cc:58
intNDArray & insert(const intNDArray< T > &a, octave_idx_type r, octave_idx_type c)
Definition: intNDArray.cc:123
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
intNDArray cummax(int dim=-1) const
Definition: intNDArray.cc:269
NDArray(const MArray< U > &a)
Definition: dNDArray.h:54
OCTAVE_API NDArray imag(const ComplexNDArray &a)
Definition: dNDArray.cc:785
NDArray(const dim_vector &dv)
Definition: dNDArray.h:43
MArray< T > & operator=(const MArray< T > &a)
Definition: MArray.h:85
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
NDArray(const Array< U > &a)
Definition: dNDArray.h:57
bool isfinite(double x)
Definition: lo-mappers.h:201
MArray squeeze(void) const
Definition: MArray.h:101
#define BSXFUN_OP2_DECL(OP, ARRAY, ARRAY1, ARRAY2, API)
Definition: bsxfun-decl.h:30
NDArray(const NDArray &a)
Definition: dNDArray.h:48
#define BSXFUN_STDOP_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:36
octave_value operator!(const octave_value &a)
Definition: ov.h:1573
intNDArray prod(int dim) const
Definition: intNDArray.cc:213
intNDArray & operator=(const intNDArray< T > &a)
Definition: intNDArray.h:59
boolNDArray all(int dim=-1) const
Definition: intNDArray.cc:82
OCTAVE_API NDArray min(double d, const NDArray &m)
Definition: dNDArray.cc:891
write the output to stdout if nargout is
Definition: load-save.cc:1612
#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
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
#define BSXFUN_OP_DECL(OP, ARRAY, API)
Definition: bsxfun-decl.h:27
NDArray squeeze(void) const
Definition: dNDArray.h:141