ov-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_matrix_h)
00025 #define octave_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_matrix : public octave_base_matrix<NDArray>
00053 {
00054 public:
00055 
00056   octave_matrix (void)
00057     : octave_base_matrix<NDArray> () { }
00058 
00059   octave_matrix (const Matrix& m)
00060     : octave_base_matrix<NDArray> (m) { }
00061 
00062   octave_matrix (const Matrix& m, const MatrixType& t)
00063     : octave_base_matrix<NDArray> (m, t) { }
00064 
00065   octave_matrix (const NDArray& nda)
00066     : octave_base_matrix<NDArray> (nda) { }
00067 
00068   octave_matrix (const Array<double>& m)
00069     : octave_base_matrix<NDArray> (NDArray (m)) { }
00070 
00071   octave_matrix (const DiagMatrix& d)
00072     : octave_base_matrix<NDArray> (Matrix (d)) { }
00073 
00074   octave_matrix (const RowVector& v)
00075     : octave_base_matrix<NDArray> (Matrix (v)) { }
00076 
00077   octave_matrix (const ColumnVector& v)
00078     : octave_base_matrix<NDArray> (Matrix (v)) { }
00079 
00080   octave_matrix (const octave_matrix& m)
00081     : octave_base_matrix<NDArray> (m) { }
00082 
00083   octave_matrix (const Array<octave_idx_type>& idx,
00084                  bool zero_based = false, bool cache_index = false)
00085     : octave_base_matrix<NDArray> (NDArray (idx, zero_based))
00086     {
00087       // Auto-create cache to speed up subsequent indexing.
00088       if (zero_based && cache_index)
00089         set_idx_cache (idx_vector (idx));
00090     }
00091 
00092   octave_matrix (const NDArray& nda, const idx_vector& cache)
00093     : octave_base_matrix<NDArray> (nda)
00094     {
00095       set_idx_cache (cache);
00096     }
00097 
00098   ~octave_matrix (void) { }
00099 
00100   octave_base_value *clone (void) const { return new octave_matrix (*this); }
00101   octave_base_value *empty_clone (void) const { return new octave_matrix (); }
00102 
00103   type_conv_info numeric_demotion_function (void) const;
00104 
00105   octave_base_value *try_narrowing_conversion (void);
00106 
00107   idx_vector index_vector (void) const
00108     { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
00109 
00110   builtin_type_t builtin_type (void) const { return btyp_double; }
00111 
00112   bool is_real_matrix (void) const { return true; }
00113 
00114   bool is_real_type (void) const { return true; }
00115 
00116   bool is_double_type (void) const { return true; }
00117 
00118   bool is_float_type (void) const { return true; }
00119 
00120   int8NDArray
00121   int8_array_value (void) const { return int8NDArray (matrix); }
00122 
00123   int16NDArray
00124   int16_array_value (void) const { return int16NDArray (matrix); }
00125 
00126   int32NDArray
00127   int32_array_value (void) const { return int32NDArray (matrix); }
00128 
00129   int64NDArray
00130   int64_array_value (void) const { return int64NDArray (matrix); }
00131 
00132   uint8NDArray
00133   uint8_array_value (void) const { return uint8NDArray (matrix); }
00134 
00135   uint16NDArray
00136   uint16_array_value (void) const { return uint16NDArray (matrix); }
00137 
00138   uint32NDArray
00139   uint32_array_value (void) const { return uint32NDArray (matrix); }
00140 
00141   uint64NDArray
00142   uint64_array_value (void) const { return uint64NDArray (matrix); }
00143 
00144   double double_value (bool = false) const;
00145 
00146   float float_value (bool = false) const;
00147 
00148   double scalar_value (bool frc_str_conv = false) const
00149     { return double_value (frc_str_conv); }
00150 
00151   Matrix matrix_value (bool = false) const;
00152 
00153   FloatMatrix float_matrix_value (bool = false) const;
00154 
00155   Complex complex_value (bool = false) const;
00156 
00157   FloatComplex float_complex_value (bool = false) const;
00158 
00159   ComplexMatrix complex_matrix_value (bool = false) const;
00160 
00161   FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00162 
00163   ComplexNDArray complex_array_value (bool = false) const;
00164 
00165   FloatComplexNDArray float_complex_array_value (bool = false) const;
00166 
00167   boolNDArray bool_array_value (bool warn = false) const;
00168 
00169   charNDArray char_array_value (bool = false) const;
00170 
00171   NDArray array_value (bool = false) const { return matrix; }
00172 
00173   FloatNDArray float_array_value (bool = false) const { return matrix; }
00174 
00175   SparseMatrix sparse_matrix_value (bool = false) const;
00176 
00177   SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
00178 
00179   octave_value diag (octave_idx_type k = 0) const;
00180 
00181   octave_value reshape (const dim_vector& new_dims) const;
00182 
00183   octave_value squeeze (void) const;
00184 
00185   octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
00186   octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00187                      sortmode mode = ASCENDING) const;
00188 
00189   sortmode is_sorted (sortmode mode = UNSORTED) const;
00190 
00191   Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
00192 
00193   sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
00194 
00195   // Use matrix_ref here to clear index cache.
00196   void increment (void) { matrix_ref () += 1.0; }
00197 
00198   void decrement (void) { matrix_ref () -= 1.0; }
00199 
00200   void changesign (void) { matrix_ref ().changesign (); }
00201 
00202   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00203 
00204   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00205 
00206   bool save_ascii (std::ostream& os);
00207 
00208   bool load_ascii (std::istream& is);
00209 
00210   bool save_binary (std::ostream& os, bool& save_as_floats);
00211 
00212   bool load_binary (std::istream& is, bool swap,
00213                     oct_mach_info::float_format fmt);
00214 
00215 #if defined (HAVE_HDF5)
00216   bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00217 
00218   bool load_hdf5 (hid_t loc_id, const char *name);
00219 #endif
00220 
00221   int write (octave_stream& os, int block_size,
00222              oct_data_conv::data_type output_type, int skip,
00223              oct_mach_info::float_format flt_fmt) const
00224     { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
00225 
00226   // Unsafe.  This function exists to support the MEX interface.
00227   // You should not use it anywhere else.
00228   void *mex_get_data (void) const { return matrix.mex_get_data (); }
00229 
00230   mxArray *as_mxArray (void) const;
00231 
00232   octave_value map (unary_mapper_t umap) const;
00233 
00234 private:
00235   DECLARE_OCTAVE_ALLOCATOR
00236 
00237   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00238 };
00239 
00240 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines