GNU Octave  3.8.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-2013 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 "dMatrix.h"
28 #include "intNDArray.h"
29 
30 #include "mx-defs.h"
31 #include "mx-op-decl.h"
32 #include "bsxfun-decl.h"
33 
34 class
35 OCTAVE_API
36 NDArray : public MArray<double>
37 {
38 public:
39 
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 Matrix& 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 <class U>
57  NDArray (const MArray<U>& a) : MArray<double> (a) { }
58 
59  template <class U>
60  NDArray (const Array<U>& a) : MArray<double> (a) { }
61 
62  template <class 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);
106  const Array<octave_idx_type>& ra_idx);
107  charNDArray concat (const charNDArray& rb,
108  const Array<octave_idx_type>& ra_idx);
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  Matrix matrix_value (void) const;
145 
146  NDArray squeeze (void) const { return MArray<double>::squeeze (); }
147 
148  static void increment_index (Array<octave_idx_type>& ra_idx,
149  const dim_vector& dimensions,
150  int start_dimension = 0);
151 
153  const dim_vector& dimensions);
154 
155  // i/o
156 
157  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
158  const NDArray& a);
159  friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
160 
161  NDArray diag (octave_idx_type k = 0) const;
162 
164 
166  {
168  return *this;
169  }
170 
171 };
172 
173 // Publish externally used friend functions.
174 
175 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
176 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
177 
178 MINMAX_DECLS (NDArray, double, OCTAVE_API)
179 
180 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
181 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
182 
183 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
184 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
185 
186 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
187 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
188 
189 MARRAY_FORWARD_DEFS (MArray, NDArray, double)
190 
191 BSXFUN_STDOP_DECLS (NDArray, OCTAVE_API)
192 BSXFUN_STDREL_DECLS (NDArray, OCTAVE_API)
193 
194 BSXFUN_OP_DECL (pow, NDArray, OCTAVE_API)
195 BSXFUN_OP2_DECL (pow, ComplexNDArray, ComplexNDArray,
196  NDArray, OCTAVE_API)
197 BSXFUN_OP2_DECL (pow, ComplexNDArray, NDArray,
198  ComplexNDArray, OCTAVE_API)
199 
200 #endif