GNU Octave  4.0.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
ov-bool-mat.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_ov_bool_mat_h)
25 #define octave_ov_bool_mat_h 1
26 
27 #include <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 
32 #include "mx-base.h"
33 
34 #include "error.h"
35 #include "oct-stream.h"
36 #include "ov-base.h"
37 #include "ov-base-mat.h"
38 #include "ov-re-mat.h"
39 #include "ov-typeinfo.h"
40 
41 #include "MatrixType.h"
42 
43 class octave_value_list;
44 
45 class tree_walker;
46 
47 // Character matrix values.
48 
49 class
51 {
52 public:
53 
56 
58  : octave_base_matrix<boolNDArray> (bnda) { }
59 
61  : octave_base_matrix<boolNDArray> (bnda) { }
62 
65 
67  : octave_base_matrix<boolNDArray> (bm, t) { }
68 
71  {
72  set_idx_cache (cache);
73  }
74 
77 
79 
80  octave_base_value *clone (void) const
81  { return new octave_bool_matrix (*this); }
82 
84  { return new octave_bool_matrix (); }
85 
86  type_conv_info numeric_conversion_function (void) const;
87 
88  octave_base_value *try_narrowing_conversion (void);
89 
90  idx_vector index_vector (bool /* require_integers */ = false) const
91  {
92  return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix));
93  }
94 
95  builtin_type_t builtin_type (void) const { return btyp_bool; }
96 
97  bool is_bool_matrix (void) const { return true; }
98 
99  bool is_bool_type (void) const { return true; }
100 
101  bool is_real_type (void) const { return true; }
102 
103  bool is_numeric_type (void) const { return false; }
104 
106  int8_array_value (void) const { return int8NDArray (matrix); }
107 
109  int16_array_value (void) const { return int16NDArray (matrix); }
110 
112  int32_array_value (void) const { return int32NDArray (matrix); }
113 
115  int64_array_value (void) const { return int64NDArray (matrix); }
116 
118  uint8_array_value (void) const { return uint8NDArray (matrix); }
119 
121  uint16_array_value (void) const { return uint16NDArray (matrix); }
122 
124  uint32_array_value (void) const { return uint32NDArray (matrix); }
125 
127  uint64_array_value (void) const { return uint64NDArray (matrix); }
128 
129  double double_value (bool = false) const;
130 
131  float float_value (bool = false) const;
132 
133  double scalar_value (bool frc_str_conv = false) const
134  { return double_value (frc_str_conv); }
135 
136  Matrix matrix_value (bool = false) const
137  { return Matrix (boolMatrix (matrix)); }
138 
139  FloatMatrix float_matrix_value (bool = false) const
140  { return FloatMatrix (boolMatrix (matrix)); }
141 
142  NDArray array_value (bool = false) const
143  { return NDArray (matrix); }
144 
145  FloatNDArray float_array_value (bool = false) const
146  { return FloatNDArray (matrix); }
147 
148  Complex complex_value (bool = false) const;
149 
150  FloatComplex float_complex_value (bool = false) const;
151 
152  ComplexMatrix complex_matrix_value (bool = false) const
153  { return ComplexMatrix (boolMatrix (matrix)); }
154 
156  { return FloatComplexMatrix (boolMatrix (matrix)); }
157 
158  ComplexNDArray complex_array_value (bool = false) const
159  { return ComplexNDArray (matrix); }
160 
162  { return FloatComplexNDArray (matrix); }
163 
165  char_array_value (bool = false) const
166  {
167  charNDArray retval (dims ());
168 
169  octave_idx_type nel = numel ();
170 
171  for (octave_idx_type i = 0; i < nel; i++)
172  retval(i) = static_cast<char>(matrix(i));
173 
174  return retval;
175  }
176 
177  boolMatrix bool_matrix_value (bool = false) const
178  { return boolMatrix (matrix); }
179 
180  boolNDArray bool_array_value (bool = false) const
181  { return matrix; }
182 
183  SparseMatrix sparse_matrix_value (bool = false) const
184  { return SparseMatrix (Matrix (boolMatrix (matrix))); }
185 
187  { return SparseComplexMatrix (ComplexMatrix (boolMatrix (matrix))); }
188 
190  { return SparseBoolMatrix (boolMatrix (matrix)); }
191 
192  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
193 
194  // Use matrix_ref here to clear index cache.
195  void invert (void) { matrix_ref ().invert (); }
196 
197  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
198 
199  bool save_ascii (std::ostream& os);
200 
201  bool load_ascii (std::istream& is);
202 
203  bool save_binary (std::ostream& os, bool& save_as_floats);
204 
205  bool load_binary (std::istream& is, bool swap,
207 
208  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
209 
210  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
211 
212  int write (octave_stream& os, int block_size,
213  oct_data_conv::data_type output_type, int skip,
214  oct_mach_info::float_format flt_fmt) const
215  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
216 
217  // Unsafe. This function exists to support the MEX interface.
218  // You should not use it anywhere else.
219  void *mex_get_data (void) const { return matrix.mex_get_data (); }
220 
221  mxArray *as_mxArray (void) const;
222 
223  // Mapper functions are converted to double for treatment
225  {
226  octave_matrix m (array_value ());
227  return m.map (umap);
228  }
229 
230 protected:
231 
232 
234 };
235 
236 #endif
builtin_type_t builtin_type(void) const
Definition: ov-bool-mat.h:95
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-bool-mat.h:183
uint16NDArray uint16_array_value(void) const
Definition: ov-bool-mat.h:121
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:31
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:31
bool is_bool_matrix(void) const
Definition: ov-bool-mat.h:97
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:31
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:31
int16NDArray int16_array_value(void) const
Definition: ov-bool-mat.h:109
octave_base_value * empty_clone(void) const
Definition: ov-bool-mat.h:83
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-bool-mat.h:139
int32NDArray int32_array_value(void) const
Definition: ov-bool-mat.h:112
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:31
FloatNDArray float_array_value(bool=false) const
Definition: ov-bool-mat.h:145
builtin_type_t
Definition: ov-base.h:59
double scalar_value(bool frc_str_conv=false) const
Definition: ov-bool-mat.h:133
octave_bool_matrix(void)
Definition: ov-bool-mat.h:54
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:186
bool is_numeric_type(void) const
Definition: ov-bool-mat.h:103
bool is_real_type(void) const
Definition: ov-bool-mat.h:101
octave_value map(unary_mapper_t umap) const
Definition: ov-re-mat.cc:878
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
octave_bool_matrix(const boolNDArray &bm, const idx_vector &cache)
Definition: ov-bool-mat.h:69
uint32NDArray uint32_array_value(void) const
Definition: ov-bool-mat.h:124
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:31
void * mex_get_data(void) const
Definition: ov-bool-mat.h:219
octave_bool_matrix(const octave_bool_matrix &bm)
Definition: ov-bool-mat.h:75
octave_bool_matrix(const boolMatrix &bm)
Definition: ov-bool-mat.h:63
~octave_bool_matrix(void)
Definition: ov-bool-mat.h:78
octave_bool_matrix(const Array< bool > &bnda)
Definition: ov-bool-mat.h:60
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
Definition: ov-bool-mat.h:212
static void cache(const std::string key, str_llist_type *value)
Definition: kpse.cc:2105
Definition: dMatrix.h:35
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-bool-mat.h:158
charNDArray char_array_value(bool=false) const
Definition: ov-bool-mat.h:165
octave_base_value * clone(void) const
Definition: ov-bool-mat.h:80
int64NDArray int64_array_value(void) const
Definition: ov-bool-mat.h:115
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:31
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:155
octave_bool_matrix(const boolMatrix &bm, const MatrixType &t)
Definition: ov-bool-mat.h:66
NDArray array_value(bool=false) const
Definition: ov-bool-mat.h:142
void invert(void)
Definition: ov-bool-mat.h:195
uint64NDArray uint64_array_value(void) const
Definition: ov-bool-mat.h:127
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, oct_mach_info::float_format flt_fmt)
Definition: oct-stream.cc:3546
uint8NDArray uint8_array_value(void) const
Definition: ov-bool-mat.h:118
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:189
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
boolMatrix bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:177
std::complex< double > Complex
Definition: oct-cmplx.h:29
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:152
octave_bool_matrix(const boolNDArray &bnda)
Definition: ov-bool-mat.h:57
int8NDArray int8_array_value(void) const
Definition: ov-bool-mat.h:106
idx_vector index_vector(bool=false) const
Definition: ov-bool-mat.h:90
octave_value map(unary_mapper_t umap) const
Definition: ov-bool-mat.h:224
Matrix matrix_value(bool=false) const
Definition: ov-bool-mat.h:136
bool is_bool_type(void) const
Definition: ov-bool-mat.h:99
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-bool-mat.h:161
boolNDArray bool_array_value(bool=false) const
Definition: ov-bool-mat.h:180
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:31