ov-bool-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_bool_matrix_h)
00025 #define octave_bool_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 
00035 #include "error.h"
00036 #include "oct-stream.h"
00037 #include "ov-base.h"
00038 #include "ov-base-mat.h"
00039 #include "ov-re-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 // Character matrix values.
00049 
00050 class
00051 octave_bool_matrix : public octave_base_matrix<boolNDArray>
00052 {
00053 public:
00054 
00055   octave_bool_matrix (void)
00056     : octave_base_matrix<boolNDArray> () { }
00057 
00058   octave_bool_matrix (const boolNDArray& bnda)
00059     : octave_base_matrix<boolNDArray> (bnda) { }
00060 
00061   octave_bool_matrix (const Array<bool>& bnda)
00062     : octave_base_matrix<boolNDArray> (bnda) { }
00063 
00064   octave_bool_matrix (const boolMatrix& bm)
00065     : octave_base_matrix<boolNDArray> (bm) { }
00066 
00067   octave_bool_matrix (const boolMatrix& bm, const MatrixType& t)
00068     : octave_base_matrix<boolNDArray> (bm, t) { }
00069 
00070   octave_bool_matrix (const boolNDArray& bm, const idx_vector& cache)
00071     : octave_base_matrix<boolNDArray> (bm)
00072     {
00073       set_idx_cache (cache);
00074     }
00075 
00076   octave_bool_matrix (const octave_bool_matrix& bm)
00077     : octave_base_matrix<boolNDArray> (bm) { }
00078 
00079   ~octave_bool_matrix (void) { }
00080 
00081   octave_base_value *clone (void) const { return new octave_bool_matrix (*this); }
00082   octave_base_value *empty_clone (void) const { return new octave_bool_matrix (); }
00083 
00084   type_conv_info numeric_conversion_function (void) const;
00085 
00086   octave_base_value *try_narrowing_conversion (void);
00087 
00088   idx_vector index_vector (void) const
00089     { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
00090 
00091   builtin_type_t builtin_type (void) const { return btyp_bool; }
00092 
00093   bool is_bool_matrix (void) const { return true; }
00094 
00095   bool is_bool_type (void) const { return true; }
00096 
00097   bool is_real_type (void) const { return true; }
00098 
00099   bool is_numeric_type (void) const { return false; }
00100 
00101   int8NDArray
00102   int8_array_value (void) const { return int8NDArray (matrix); }
00103 
00104   int16NDArray
00105   int16_array_value (void) const { return int16NDArray (matrix); }
00106 
00107   int32NDArray
00108   int32_array_value (void) const { return int32NDArray (matrix); }
00109 
00110   int64NDArray
00111   int64_array_value (void) const { return int64NDArray (matrix); }
00112 
00113   uint8NDArray
00114   uint8_array_value (void) const { return uint8NDArray (matrix); }
00115 
00116   uint16NDArray
00117   uint16_array_value (void) const { return uint16NDArray (matrix); }
00118 
00119   uint32NDArray
00120   uint32_array_value (void) const { return uint32NDArray (matrix); }
00121 
00122   uint64NDArray
00123   uint64_array_value (void) const { return uint64NDArray (matrix); }
00124 
00125   double double_value (bool = false) const;
00126 
00127   float float_value (bool = false) const;
00128 
00129   double scalar_value (bool frc_str_conv = false) const
00130     { return double_value (frc_str_conv); }
00131 
00132   Matrix matrix_value (bool = false) const
00133     { return Matrix (matrix.matrix_value ()); }
00134 
00135   FloatMatrix float_matrix_value (bool = false) const
00136     { return FloatMatrix (matrix.matrix_value ()); }
00137 
00138   NDArray array_value (bool = false) const
00139     { return NDArray (matrix); }
00140 
00141   FloatNDArray float_array_value (bool = false) const
00142     { return FloatNDArray (matrix); }
00143 
00144   Complex complex_value (bool = false) const;
00145 
00146   FloatComplex float_complex_value (bool = false) const;
00147 
00148   ComplexMatrix complex_matrix_value (bool = false) const
00149     { return ComplexMatrix (matrix.matrix_value ( )); }
00150 
00151   FloatComplexMatrix float_complex_matrix_value (bool = false) const
00152     { return FloatComplexMatrix (matrix.matrix_value ( )); }
00153 
00154   ComplexNDArray complex_array_value (bool = false) const
00155     { return ComplexNDArray (matrix); }
00156 
00157   FloatComplexNDArray float_complex_array_value (bool = false) const
00158     { return FloatComplexNDArray (matrix); }
00159 
00160   charNDArray
00161   char_array_value (bool = false) const
00162   {
00163     charNDArray retval (dims ());
00164 
00165     octave_idx_type nel = numel ();
00166 
00167     for (octave_idx_type i = 0; i < nel; i++)
00168       retval(i) = static_cast<char>(matrix(i));
00169 
00170     return retval;
00171   }
00172 
00173   boolMatrix bool_matrix_value (bool = false) const
00174     { return matrix.matrix_value (); }
00175 
00176   boolNDArray bool_array_value (bool = false) const
00177     { return matrix; }
00178 
00179   SparseMatrix sparse_matrix_value (bool = false) const
00180   { return SparseMatrix (Matrix (matrix.matrix_value ())); }
00181 
00182   SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
00183   { return SparseComplexMatrix (ComplexMatrix (matrix.matrix_value ())); }
00184 
00185   SparseBoolMatrix sparse_bool_matrix_value (bool = false) const
00186   { return SparseBoolMatrix (matrix.matrix_value ()); }
00187 
00188   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00189 
00190   // Use matrix_ref here to clear index cache.
00191   void invert (void) { matrix_ref ().invert (); }
00192 
00193   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00194 
00195   bool save_ascii (std::ostream& os);
00196 
00197   bool load_ascii (std::istream& is);
00198 
00199   bool save_binary (std::ostream& os, bool& save_as_floats);
00200 
00201   bool load_binary (std::istream& is, bool swap,
00202                     oct_mach_info::float_format fmt);
00203 
00204 #if defined (HAVE_HDF5)
00205   bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00206 
00207   bool load_hdf5 (hid_t loc_id, const char *name);
00208 #endif
00209 
00210   int write (octave_stream& os, int block_size,
00211              oct_data_conv::data_type output_type, int skip,
00212              oct_mach_info::float_format flt_fmt) const
00213     { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
00214 
00215   // Unsafe.  This function exists to support the MEX interface.
00216   // You should not use it anywhere else.
00217   void *mex_get_data (void) const { return matrix.mex_get_data (); }
00218 
00219   mxArray *as_mxArray (void) const;
00220 
00221   // Mapper functions are converted to double for treatment
00222   octave_value map (unary_mapper_t umap) const
00223     {
00224       octave_matrix m (array_value ());
00225       return m.map (umap);
00226     }
00227 
00228 protected:
00229 
00230   DECLARE_OCTAVE_ALLOCATOR
00231 
00232   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00233 };
00234 
00235 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines