dNDArray.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_NDArray_h)
00024 #define octave_NDArray_h 1
00025 
00026 #include "MArray.h"
00027 #include "dMatrix.h"
00028 #include "intNDArray.h"
00029 
00030 #include "mx-defs.h"
00031 #include "mx-op-decl.h"
00032 #include "bsxfun-decl.h"
00033 
00034 class
00035 OCTAVE_API
00036 NDArray : public MArray<double>
00037 {
00038 public:
00039 
00040   typedef Matrix matrix_type;
00041 
00042   NDArray (void) : MArray<double> () { }
00043 
00044   NDArray (const dim_vector& dv) : MArray<double> (dv) { }
00045 
00046   NDArray (const dim_vector& dv, double val)
00047     : MArray<double> (dv, val) { }
00048 
00049   NDArray (const NDArray& a) : MArray<double> (a) { }
00050 
00051   NDArray (const Matrix& a) : MArray<double> (a) { }
00052 
00053   NDArray (const Array<octave_idx_type>& a, bool zero_based = false,
00054            bool negative_to_nan = false);
00055 
00056   template <class U>
00057   NDArray (const MArray<U>& a) : MArray<double> (a) { }
00058 
00059   template <class U>
00060   NDArray (const Array<U>& a) : MArray<double> (a) { }
00061 
00062   template <class U>
00063   explicit NDArray (const intNDArray<U>& a) : MArray<double> (a) { }
00064 
00065   NDArray (const charNDArray&);
00066 
00067   NDArray& operator = (const NDArray& a)
00068     {
00069       MArray<double>::operator = (a);
00070       return *this;
00071     }
00072 
00073   // unary operations
00074 
00075   boolNDArray operator ! (void) const;
00076 
00077   bool any_element_is_negative (bool = false) const;
00078   bool any_element_is_positive (bool = false) const;
00079   bool any_element_is_nan (void) const;
00080   bool any_element_is_inf_or_nan (void) const;
00081   bool any_element_not_one_or_zero (void) const;
00082   bool all_elements_are_zero (void) const;
00083   bool all_elements_are_int_or_inf_or_nan (void) const;
00084   bool all_integers (double& max_val, double& min_val) const;
00085   bool all_integers (void) const;
00086   bool too_large_for_float (void) const;
00087 
00088   // FIXME -- this is not quite the right thing.
00089 
00090   boolNDArray all (int dim = -1) const;
00091   boolNDArray any (int dim = -1) const;
00092 
00093   NDArray cumprod (int dim = -1) const;
00094   NDArray cumsum (int dim = -1) const;
00095   NDArray prod (int dim = -1) const;
00096   NDArray sum (int dim = -1) const;
00097   NDArray xsum (int dim = -1) const;
00098   NDArray sumsq (int dim = -1) const;
00099   NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx);
00100   ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx);
00101   charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx);
00102 
00103   NDArray max (int dim = -1) const;
00104   NDArray max (Array<octave_idx_type>& index, int dim = -1) const;
00105   NDArray min (int dim = -1) const;
00106   NDArray min (Array<octave_idx_type>& index, int dim = -1) const;
00107 
00108   NDArray cummax (int dim = -1) const;
00109   NDArray cummax (Array<octave_idx_type>& index, int dim = -1) const;
00110   NDArray cummin (int dim = -1) const;
00111   NDArray cummin (Array<octave_idx_type>& index, int dim = -1) const;
00112 
00113   NDArray diff (octave_idx_type order = 1, int dim = -1) const;
00114 
00115   NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c);
00116   NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx);
00117 
00118   NDArray abs (void) const;
00119   boolNDArray isnan (void) const;
00120   boolNDArray isinf (void) const;
00121   boolNDArray isfinite (void) const;
00122 
00123   ComplexNDArray fourier (int dim = 1) const;
00124   ComplexNDArray ifourier (int dim = 1) const;
00125 
00126   ComplexNDArray fourier2d (void) const;
00127   ComplexNDArray ifourier2d (void) const;
00128 
00129   ComplexNDArray fourierNd (void) const;
00130   ComplexNDArray ifourierNd (void) const;
00131 
00132   friend OCTAVE_API NDArray real (const ComplexNDArray& a);
00133   friend OCTAVE_API NDArray imag (const ComplexNDArray& a);
00134 
00135   friend class ComplexNDArray;
00136 
00137   Matrix matrix_value (void) const;
00138 
00139   NDArray squeeze (void) const { return MArray<double>::squeeze (); }
00140 
00141   static void increment_index (Array<octave_idx_type>& ra_idx,
00142                                const dim_vector& dimensions,
00143                                int start_dimension = 0);
00144 
00145   static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx,
00146                             const dim_vector& dimensions);
00147 
00148   // i/o
00149 
00150   friend OCTAVE_API std::ostream& operator << (std::ostream& os, const NDArray& a);
00151   friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a);
00152 
00153   static double resize_fill_value (void) { return 0; }
00154 
00155   NDArray diag (octave_idx_type k = 0) const;
00156 
00157   NDArray& changesign (void)
00158     {
00159       MArray<double>::changesign ();
00160       return *this;
00161     }
00162 
00163 };
00164 
00165 // Publish externally used friend functions.
00166 
00167 extern OCTAVE_API NDArray real (const ComplexNDArray& a);
00168 extern OCTAVE_API NDArray imag (const ComplexNDArray& a);
00169 
00170 MINMAX_DECLS (NDArray, double, OCTAVE_API)
00171 
00172 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API)
00173 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API)
00174 
00175 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API)
00176 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API)
00177 
00178 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API)
00179 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API)
00180 
00181 MARRAY_FORWARD_DEFS (MArray, NDArray, double)
00182 
00183 BSXFUN_STDOP_DECLS (NDArray, OCTAVE_API)
00184 BSXFUN_STDREL_DECLS (NDArray, OCTAVE_API)
00185 
00186 BSXFUN_OP_DECL (pow, NDArray, OCTAVE_API)
00187 BSXFUN_OP2_DECL (pow, ComplexNDArray, ComplexNDArray,
00188                  NDArray, OCTAVE_API)
00189 BSXFUN_OP2_DECL (pow, ComplexNDArray, NDArray,
00190                  ComplexNDArray, OCTAVE_API)
00191 
00192 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines