GNU Octave  8.1.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-2023 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 "intNDArray-fwd.h"
32 #include "MArray.h"
33 #include "bsxfun-decl.h"
34 #include "mx-defs.h"
35 #include "mx-op-decl.h"
36 
37 class
39 NDArray : public MArray<double>
40 {
41 public:
42 
43  NDArray (void) : MArray<double> () { }
44 
45  NDArray (const dim_vector& dv) : MArray<double> (dv) { }
46 
47  NDArray (const dim_vector& dv, double val)
48  : MArray<double> (dv, val) { }
49 
50  NDArray (const NDArray& a) : MArray<double> (a) { }
51 
52  NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
53  bool negative_to_nan = false);
54 
55  template <typename U>
56  NDArray (const MArray<U>& a) : MArray<double> (a) { }
57 
58  template <typename U>
59  NDArray (const Array<U>& a) : MArray<double> (a) { }
60 
61  template <typename U>
62  explicit NDArray (const intNDArray<U>& a) : MArray<double> (a) { }
63 
64  NDArray (const charNDArray&);
65 
66  NDArray& operator = (const NDArray& a)
67  {
69  return *this;
70  }
71 
72  // unary operations
73 
75 
76  OCTAVE_API bool any_element_is_negative (bool = false) const;
77  OCTAVE_API bool any_element_is_positive (bool = false) const;
78  OCTAVE_API bool any_element_is_nan (void) const;
79  OCTAVE_API bool any_element_is_inf_or_nan (void) const;
80  OCTAVE_API bool any_element_not_one_or_zero (void) const;
81  OCTAVE_API bool all_elements_are_zero (void) const;
82  OCTAVE_API bool all_elements_are_int_or_inf_or_nan (void) const;
83  OCTAVE_API bool all_integers (double& max_val, double& min_val) const;
84  OCTAVE_API bool all_integers (void) const;
85  OCTAVE_API bool too_large_for_float (void) const;
86 
87  // FIXME: this is not quite the right thing.
88 
89  OCTAVE_API boolNDArray all (int dim = -1) const;
90  OCTAVE_API boolNDArray any (int dim = -1) const;
91 
92  OCTAVE_API NDArray cumprod (int dim = -1) const;
93  OCTAVE_API NDArray cumsum (int dim = -1) const;
94  OCTAVE_API NDArray prod (int dim = -1) const;
95  OCTAVE_API NDArray sum (int dim = -1) const;
96  OCTAVE_API NDArray xsum (int dim = -1) const;
97  OCTAVE_API NDArray sumsq (int dim = -1) const;
99  concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx);
103  concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx);
104 
105  OCTAVE_API NDArray max (int dim = -1) const;
106  OCTAVE_API NDArray max (Array<octave_idx_type>& index, int dim = -1) const;
107  OCTAVE_API NDArray min (int dim = -1) const;
108  OCTAVE_API NDArray min (Array<octave_idx_type>& index, int dim = -1) const;
109 
110  OCTAVE_API NDArray cummax (int dim = -1) const;
112  cummax (Array<octave_idx_type>& index, int dim = -1) const;
113  OCTAVE_API NDArray cummin (int dim = -1) const;
115  cummin (Array<octave_idx_type>& index, int dim = -1) const;
116 
117  OCTAVE_API NDArray diff (octave_idx_type order = 1, int dim = -1) const;
118 
120  insert (const NDArray& a, octave_idx_type r, octave_idx_type c);
122  insert (const NDArray& a, const Array<octave_idx_type>& ra_idx);
123 
124  OCTAVE_API NDArray abs (void) const;
125  OCTAVE_API boolNDArray isnan (void) const;
126  OCTAVE_API boolNDArray isinf (void) const;
127  OCTAVE_API boolNDArray isfinite (void) const;
128 
129  OCTAVE_API ComplexNDArray fourier (int dim = 1) const;
130  OCTAVE_API ComplexNDArray ifourier (int dim = 1) const;
131 
132  OCTAVE_API ComplexNDArray fourier2d (void) const;
133  OCTAVE_API ComplexNDArray ifourier2d (void) const;
134 
135  OCTAVE_API ComplexNDArray fourierNd (void) const;
136  OCTAVE_API ComplexNDArray ifourierNd (void) const;
137 
138  friend OCTAVE_API NDArray real (const ComplexNDArray& a);
139  friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
140 
141  friend class ComplexNDArray;
142 
143  NDArray squeeze (void) const { return MArray<double>::squeeze (); }
144 
145  static OCTAVE_API void
147  const dim_vector& dimensions, int start_dimension = 0);
148 
151 
152  // i/o
153 
154  friend OCTAVE_API std::ostream&
155  operator << (std::ostream& os, const NDArray& a);
156  friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
157 
158  OCTAVE_API NDArray diag (octave_idx_type k = 0) const;
159 
161 
163  {
165  return *this;
166  }
167 
168 };
169 
170 // Publish externally used friend functions.
171 
172 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
173 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
174 
176 
179 
182 
185 
187 
190 
196 
197 #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:130
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
#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
OCTAVE_API ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:585
OCTARRAY_API void changesign(void)
Definition: MArray.cc:216
MArray< T > & operator=(const MArray< T > &a)
Definition: MArray.h:81
MArray squeeze(void) const
Definition: MArray.h:97
NDArray(const intNDArray< U > &a)
Definition: dNDArray.h:62
NDArray(const NDArray &a)
Definition: dNDArray.h:50
NDArray & changesign(void)
Definition: dNDArray.h:162
NDArray(void)
Definition: dNDArray.h:43
NDArray(const dim_vector &dv, double val)
Definition: dNDArray.h:47
NDArray squeeze(void) const
Definition: dNDArray.h:143
NDArray(const Array< U > &a)
Definition: dNDArray.h:59
NDArray(const MArray< U > &a)
Definition: dNDArray.h:56
NDArray(const dim_vector &dv)
Definition: dNDArray.h:45
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
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
bool isfinite(double x)
Definition: lo-mappers.h:192
bool isinf(double x)
Definition: lo-mappers.h:203
bool isnan(bool)
Definition: lo-mappers.h:178
bool too_large_for_float(double x)
Definition: lo-utils.cc:55
#define OCTAVE_API
Definition: main.in.cc:55
class OCTAVE_API NDArray
Definition: mx-fwd.h:38
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:226
#define NDND_CMP_OP_DECLS(ND1, ND2, API)
Definition: mx-op-decl.h:218
#define NDS_BOOL_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:172
#define SND_CMP_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:191
#define MINMAX_DECLS(T, S, API)
Definition: mx-op-decl.h:288
#define NDS_CMP_OP_DECLS(ND, S, API)
Definition: mx-op-decl.h:164
#define SND_BOOL_OP_DECLS(S, ND, API)
Definition: mx-op-decl.h:199
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:1838
static T abs(T x)
Definition: pr-output.cc:1678