ov-flt-re-mat.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 Copyright (C) 2009-2010 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #if !defined (octave_float_matrix_h)
00025 #define octave_float_matrix_h 1
00026 
00027 #include <cstdlib>
00028 
00029 #include <iosfwd>
00030 #include <string>
00031 
00032 #include "mx-base.h"
00033 #include "oct-alloc.h"
00034 #include "str-vec.h"
00035 
00036 #include "error.h"
00037 #include "oct-stream.h"
00038 #include "ov-base.h"
00039 #include "ov-base-mat.h"
00040 #include "ov-typeinfo.h"
00041 
00042 #include "MatrixType.h"
00043 
00044 class octave_value_list;
00045 
00046 class tree_walker;
00047 
00048 // Real matrix values.
00049 
00050 class
00051 OCTINTERP_API
00052 octave_float_matrix : public octave_base_matrix<FloatNDArray>
00053 {
00054 public:
00055 
00056   octave_float_matrix (void)
00057     : octave_base_matrix<FloatNDArray> () { }
00058 
00059   octave_float_matrix (const FloatMatrix& m)
00060     : octave_base_matrix<FloatNDArray> (m) { }
00061 
00062   octave_float_matrix (const FloatMatrix& m, const MatrixType& t)
00063     : octave_base_matrix<FloatNDArray> (m, t) { }
00064 
00065   octave_float_matrix (const FloatNDArray& nda)
00066     : octave_base_matrix<FloatNDArray> (nda) { }
00067 
00068   octave_float_matrix (const Array<float>& m)
00069     : octave_base_matrix<FloatNDArray> (FloatNDArray (m)) { }
00070 
00071   octave_float_matrix (const FloatDiagMatrix& d)
00072     : octave_base_matrix<FloatNDArray> (FloatMatrix (d)) { }
00073 
00074   octave_float_matrix (const FloatRowVector& v)
00075     : octave_base_matrix<FloatNDArray> (FloatMatrix (v)) { }
00076 
00077   octave_float_matrix (const FloatColumnVector& v)
00078     : octave_base_matrix<FloatNDArray> (FloatMatrix (v)) { }
00079 
00080   octave_float_matrix (const octave_float_matrix& m)
00081     : octave_base_matrix<FloatNDArray> (m) { }
00082 
00083   ~octave_float_matrix (void) { }
00084 
00085   octave_base_value *clone (void) const { return new octave_float_matrix (*this); }
00086   octave_base_value *empty_clone (void) const { return new octave_float_matrix (); }
00087 
00088   octave_base_value *try_narrowing_conversion (void);
00089 
00090   idx_vector index_vector (void) const
00091     { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
00092 
00093   builtin_type_t builtin_type (void) const { return btyp_float; }
00094 
00095   bool is_real_matrix (void) const { return true; }
00096 
00097   bool is_real_type (void) const { return true; }
00098 
00099   bool is_single_type (void) const { return true; }
00100 
00101   bool is_float_type (void) const { return true; }
00102 
00103   int8NDArray
00104   int8_array_value (void) const { return int8NDArray (matrix); }
00105 
00106   int16NDArray
00107   int16_array_value (void) const { return int16NDArray (matrix); }
00108 
00109   int32NDArray
00110   int32_array_value (void) const { return int32NDArray (matrix); }
00111 
00112   int64NDArray
00113   int64_array_value (void) const { return int64NDArray (matrix); }
00114 
00115   uint8NDArray
00116   uint8_array_value (void) const { return uint8NDArray (matrix); }
00117 
00118   uint16NDArray
00119   uint16_array_value (void) const { return uint16NDArray (matrix); }
00120 
00121   uint32NDArray
00122   uint32_array_value (void) const { return uint32NDArray (matrix); }
00123 
00124   uint64NDArray
00125   uint64_array_value (void) const { return uint64NDArray (matrix); }
00126 
00127   double double_value (bool = false) const;
00128 
00129   float float_value (bool = false) const;
00130 
00131   double scalar_value (bool frc_str_conv = false) const
00132     { return double_value (frc_str_conv); }
00133 
00134   float float_scalar_value (bool frc_str_conv = false) const
00135     { return float_value (frc_str_conv); }
00136 
00137   Matrix matrix_value (bool = false) const;
00138 
00139   FloatMatrix float_matrix_value (bool = false) const;
00140 
00141   Complex complex_value (bool = false) const;
00142 
00143   FloatComplex float_complex_value (bool = false) const;
00144 
00145   ComplexMatrix complex_matrix_value (bool = false) const;
00146 
00147   FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00148 
00149   ComplexNDArray complex_array_value (bool = false) const;
00150 
00151   FloatComplexNDArray float_complex_array_value (bool = false) const;
00152 
00153   boolNDArray bool_array_value (bool warn = false) const;
00154 
00155   charNDArray char_array_value (bool = false) const;
00156 
00157   NDArray array_value (bool = false) const;
00158 
00159   FloatNDArray float_array_value (bool = false) const { return matrix; }
00160 
00161   SparseMatrix sparse_matrix_value (bool = false) const;
00162 
00163   SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
00164 
00165   octave_value diag (octave_idx_type k = 0) const;
00166 
00167   // Use matrix_ref here to clear index cache.
00168   void increment (void) { matrix_ref () += 1.0; }
00169 
00170   void decrement (void) { matrix_ref () -= 1.0; }
00171 
00172   void changesign (void) { matrix_ref ().changesign (); }
00173 
00174   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00175 
00176   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00177 
00178   bool save_ascii (std::ostream& os);
00179 
00180   bool load_ascii (std::istream& is);
00181 
00182   bool save_binary (std::ostream& os, bool& save_as_floats);
00183 
00184   bool load_binary (std::istream& is, bool swap,
00185                     oct_mach_info::float_format fmt);
00186 
00187 #if defined (HAVE_HDF5)
00188   bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00189 
00190   bool load_hdf5 (hid_t loc_id, const char *name);
00191 #endif
00192 
00193   int write (octave_stream& os, int block_size,
00194              oct_data_conv::data_type output_type, int skip,
00195              oct_mach_info::float_format flt_fmt) const
00196     { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
00197 
00198   // Unsafe.  This function exists to support the MEX interface.
00199   // You should not use it anywhere else.
00200   void *mex_get_data (void) const { return matrix.mex_get_data (); }
00201 
00202   mxArray *as_mxArray (void) const;
00203 
00204   octave_value map (unary_mapper_t umap) const;
00205 
00206 private:
00207   DECLARE_OCTAVE_ALLOCATOR
00208 
00209   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00210 };
00211 
00212 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines