GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_dNDArray_h)
27 #define octave_dNDArray_h 1
28 
29 #include "octave-config.h"
30 
31 #include "MArray.h"
32 #include "bsxfun-decl.h"
33 #include "mx-defs.h"
34 #include "mx-op-decl.h"
35 
36 template <typename T> class intNDArray;
37 
38 class
39 OCTAVE_API
40 NDArray : public MArray<double>
41 {
42 public:
43 
44  NDArray (void) : MArray<double> () { }
45 
46  NDArray (const dim_vector& dv) : MArray<double> (dv) { }
47 
48  NDArray (const dim_vector& dv, double val)
49  : MArray<double> (dv, val) { }
50 
51  NDArray (const NDArray& a) : MArray<double> (a) { }
52 
53  NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
54  bool negative_to_nan = false);
55 
56  template <typename U>
57  NDArray (const MArray<U>& a) : MArray<double> (a) { }
58 
59  template <typename U>
60  NDArray (const Array<U>& a) : MArray<double> (a) { }
61 
62  template <typename U>
63  explicit NDArray (const intNDArray<U>& a) : MArray<double> (a) { }
64 
65  NDArray (const charNDArray&);
66 
67  // For jit support only
68  NDArray (double *sdata, octave_idx_type slen, octave_idx_type *adims,
69  void *arep)
70  : MArray<double> (sdata, slen, adims, arep) { }
71 
73  {
75  return *this;
76  }
77 
78  // unary operations
79 
80  boolNDArray operator ! (void) const;
81 
82  bool any_element_is_negative (bool = false) const;
83  bool any_element_is_positive (bool = false) const;
84  bool any_element_is_nan (void) const;
85  bool any_element_is_inf_or_nan (void) const;
86  bool any_element_not_one_or_zero (void) const;
87  bool all_elements_are_zero (void) const;
88  bool all_elements_are_int_or_inf_or_nan (void) const;
89  bool all_integers (double& max_val, double& min_val) const;
90  bool all_integers (void) const;
91  bool too_large_for_float (void) const;
92 
93  // FIXME: this is not quite the right thing.
94 
95  boolNDArray all (int dim = -1) const;
96  boolNDArray any (int dim = -1) const;
97 
98  NDArray cumprod (int dim = -1) const;
99  NDArray cumsum (int dim = -1) const;
100  NDArray prod (int dim = -1) const;
101  NDArray sum (int dim = -1) const;
102  NDArray xsum (int dim = -1) const;
103  NDArray sumsq (int dim = -1) const;
104  NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx);
107  charNDArray concat (const charNDArray& rb,
109 
110  NDArray max (int dim = -1) const;
111  NDArray max (Array<octave_idx_type>& index, int dim = -1) const;
112  NDArray min (int dim = -1) const;
113  NDArray min (Array<octave_idx_type>& index, int dim = -1) const;
114 
115  NDArray cummax (int dim = -1) const;
116  NDArray cummax (Array<octave_idx_type>& index, int dim = -1) const;
117  NDArray cummin (int dim = -1) const;
118  NDArray cummin (Array<octave_idx_type>& index, int dim = -1) const;
119 
120  NDArray diff (octave_idx_type order = 1, int dim = -1) const;
121 
123  NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx);
124 
125  NDArray abs (void) const;
126  boolNDArray isnan (void) const;
127  boolNDArray isinf (void) const;
128  boolNDArray isfinite (void) const;
129 
130  ComplexNDArray fourier (int dim = 1) const;
131  ComplexNDArray ifourier (int dim = 1) const;
132 
133  ComplexNDArray fourier2d (void) const;
134  ComplexNDArray ifourier2d (void) const;
135 
136  ComplexNDArray fourierNd (void) const;
137  ComplexNDArray ifourierNd (void) const;
138 
139  friend OCTAVE_API NDArray real (const ComplexNDArray& a);
140  friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
141 
142  friend class ComplexNDArray;
143 
144  NDArray squeeze (void) const { return MArray<double>::squeeze (); }
145 
147  const dim_vector& dimensions,
148  int start_dimension = 0);
149 
151  const dim_vector& dimensions);
152 
153  // i/o
154 
155  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
156  const NDArray& a);
157  friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
158 
159  NDArray diag (octave_idx_type k = 0) const;
160 
162 
164  {
166  return *this;
167  }
168 
169 };
170 
171 // Publish externally used friend functions.
172 
173 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
174 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
175 
176 MINMAX_DECLS (NDArray, double, OCTAVE_API)
177 
178 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
179 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
180 
181 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
182 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
183 
184 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
185 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
186 
188 
189 BSXFUN_STDOP_DECLS (NDArray, OCTAVE_API)
190 BSXFUN_STDREL_DECLS (NDArray, OCTAVE_API)
191 
192 BSXFUN_OP_DECL (pow, NDArray, OCTAVE_API)
194  NDArray, OCTAVE_API)
196  ComplexNDArray, OCTAVE_API)
197 
198 #endif
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:177
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
Definition: Array-util.cc:60
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray.h:128
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:281
#define BSXFUN_STDREL_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:53
#define BSXFUN_STDOP_DECLS(ARRAY, API)
Definition: bsxfun-decl.h:38
#define BSXFUN_OP2_DECL(OP, ARRAY, ARRAY1, ARRAY2, API)
Definition: bsxfun-decl.h:32
#define BSXFUN_OP_DECL(OP, ARRAY, API)
Definition: bsxfun-decl.h:29
dim_vector dimensions
Definition: Array.h:217
Array< T > index(const idx_vector &i) const
Indexing without resizing.
Definition: Array.cc:698
ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:584
void changesign(void)
Definition: MArray.cc:204
MArray< T > & operator=(const MArray< T > &a)
Definition: MArray.h:87
MArray squeeze(void) const
Definition: MArray.h:103
NDArray(const intNDArray< U > &a)
Definition: dNDArray.h:63
NDArray(const NDArray &a)
Definition: dNDArray.h:51
NDArray & changesign(void)
Definition: dNDArray.h:163
NDArray(void)
Definition: dNDArray.h:44
NDArray(const dim_vector &dv, double val)
Definition: dNDArray.h:48
NDArray squeeze(void) const
Definition: dNDArray.h:144
NDArray(const Array< U > &a)
Definition: dNDArray.h:60
NDArray(const MArray< U > &a)
Definition: dNDArray.h:57
NDArray(double *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
Definition: dNDArray.h:68
NDArray(const dim_vector &dv)
Definition: dNDArray.h:46
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
boolNDArray any(int dim=-1) const
Definition: intNDArray.cc:91
intNDArray & insert(const intNDArray< T > &a, octave_idx_type r, octave_idx_type c)
Definition: intNDArray.cc:125
intNDArray sum(int dim) const
Definition: intNDArray.cc:222
boolNDArray all(int dim=-1) const
Definition: intNDArray.cc:84
intNDArray cummin(int dim=-1) const
Definition: intNDArray.cc:285
intNDArray prod(int dim) const
Definition: intNDArray.cc:215
intNDArray & operator=(const intNDArray< T > &a)=default
bool any_element_is_nan(void) const
Definition: intNDArray.h:70
bool any_element_not_one_or_zero(void) const
Definition: intNDArray.cc:51
intNDArray cummax(int dim=-1) const
Definition: intNDArray.cc:271
intNDArray cumsum(int dim) const
Definition: intNDArray.cc:236
intNDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: intNDArray.cc:299
OCTAVE_API NDArray max(double d, const NDArray &m)
Definition: dNDArray.cc:656
OCTAVE_API NDArray real(const ComplexNDArray &a)
Definition: dNDArray.cc:544
OCTAVE_API NDArray imag(const ComplexNDArray &a)
Definition: dNDArray.cc:550
OCTAVE_API NDArray min(double d, const NDArray &m)
Definition: dNDArray.cc:656
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
T * r
Definition: mx-inlines.cc:773
#define NDND_BOOL_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:227
#define NDND_CMP_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:219
#define NDS_BOOL_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:173
#define SND_CMP_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:192
#define MINMAX_DECLS(T, S, API)
Definition: mx-op-decl.h:289
#define NDS_CMP_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:165
#define SND_BOOL_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:200
bool isfinite(double x)
Definition: lo-mappers.h:192
bool isnan(bool)
Definition: lo-mappers.h:178
bool isinf(double x)
Definition: lo-mappers.h:203
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
const octave_base_value const Array< octave_idx_type > & ra_idx
octave_value operator!(const octave_value &a)
Definition: ov.h:1536
static T abs(T x)
Definition: pr-output.cc:1678