GNU Octave  3.8.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-2013 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 #include "oct-alloc.h"
34 
35 #include "error.h"
36 #include "oct-stream.h"
37 #include "ov-base.h"
38 #include "ov-base-mat.h"
39 #include "ov-re-mat.h"
40 #include "ov-typeinfo.h"
41 
42 #include "MatrixType.h"
43 
44 class octave_value_list;
45 
46 class tree_walker;
47 
48 // Character matrix values.
49 
50 class
52 {
53 public:
54 
57 
59  : octave_base_matrix<boolNDArray> (bnda) { }
60 
62  : octave_base_matrix<boolNDArray> (bnda) { }
63 
66 
68  : octave_base_matrix<boolNDArray> (bm, t) { }
69 
72  {
73  set_idx_cache (cache);
74  }
75 
78 
80 
81  octave_base_value *clone (void) const
82  { return new octave_bool_matrix (*this); }
83 
84  octave_base_value *empty_clone (void) const
85  { return new octave_bool_matrix (); }
86 
87  type_conv_info numeric_conversion_function (void) const;
88 
89  octave_base_value *try_narrowing_conversion (void);
90 
91  idx_vector index_vector (void) const
92  { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
93 
94  builtin_type_t builtin_type (void) const { return btyp_bool; }
95 
96  bool is_bool_matrix (void) const { return true; }
97 
98  bool is_bool_type (void) const { return true; }
99 
100  bool is_real_type (void) const { return true; }
101 
102  bool is_numeric_type (void) const { return false; }
103 
105  int8_array_value (void) const { return int8NDArray (matrix); }
106 
108  int16_array_value (void) const { return int16NDArray (matrix); }
109 
111  int32_array_value (void) const { return int32NDArray (matrix); }
112 
114  int64_array_value (void) const { return int64NDArray (matrix); }
115 
117  uint8_array_value (void) const { return uint8NDArray (matrix); }
118 
120  uint16_array_value (void) const { return uint16NDArray (matrix); }
121 
123  uint32_array_value (void) const { return uint32NDArray (matrix); }
124 
126  uint64_array_value (void) const { return uint64NDArray (matrix); }
127 
128  double double_value (bool = false) const;
129 
130  float float_value (bool = false) const;
131 
132  double scalar_value (bool frc_str_conv = false) const
133  { return double_value (frc_str_conv); }
134 
135  Matrix matrix_value (bool = false) const
136  { return Matrix (matrix.matrix_value ()); }
137 
138  FloatMatrix float_matrix_value (bool = false) const
139  { return FloatMatrix (matrix.matrix_value ()); }
140 
141  NDArray array_value (bool = false) const
142  { return NDArray (matrix); }
143 
144  FloatNDArray float_array_value (bool = false) const
145  { return FloatNDArray (matrix); }
146 
147  Complex complex_value (bool = false) const;
148 
149  FloatComplex float_complex_value (bool = false) const;
150 
151  ComplexMatrix complex_matrix_value (bool = false) const
152  { return ComplexMatrix (matrix.matrix_value ( )); }
153 
154  FloatComplexMatrix float_complex_matrix_value (bool = false) const
155  { return FloatComplexMatrix (matrix.matrix_value ( )); }
156 
157  ComplexNDArray complex_array_value (bool = false) const
158  { return ComplexNDArray (matrix); }
159 
160  FloatComplexNDArray float_complex_array_value (bool = false) const
161  { return FloatComplexNDArray (matrix); }
162 
164  char_array_value (bool = false) const
165  {
166  charNDArray retval (dims ());
167 
168  octave_idx_type nel = numel ();
169 
170  for (octave_idx_type i = 0; i < nel; i++)
171  retval(i) = static_cast<char>(matrix(i));
172 
173  return retval;
174  }
175 
176  boolMatrix bool_matrix_value (bool = false) const
177  { return matrix.matrix_value (); }
178 
179  boolNDArray bool_array_value (bool = false) const
180  { return matrix; }
181 
182  SparseMatrix sparse_matrix_value (bool = false) const
183  { return SparseMatrix (Matrix (matrix.matrix_value ())); }
184 
185  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
186  { return SparseComplexMatrix (ComplexMatrix (matrix.matrix_value ())); }
187 
188  SparseBoolMatrix sparse_bool_matrix_value (bool = false) const
189  { return SparseBoolMatrix (matrix.matrix_value ()); }
190 
191  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
192 
193  // Use matrix_ref here to clear index cache.
194  void invert (void) { matrix_ref ().invert (); }
195 
196  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
197 
198  bool save_ascii (std::ostream& os);
199 
200  bool load_ascii (std::istream& is);
201 
202  bool save_binary (std::ostream& os, bool& save_as_floats);
203 
204  bool load_binary (std::istream& is, bool swap,
206 
207 #if defined (HAVE_HDF5)
208  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
209 
210  bool load_hdf5 (hid_t loc_id, const char *name);
211 #endif
212 
213  int write (octave_stream& os, int block_size,
214  oct_data_conv::data_type output_type, int skip,
215  oct_mach_info::float_format flt_fmt) const
216  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
217 
218  // Unsafe. This function exists to support the MEX interface.
219  // You should not use it anywhere else.
220  void *mex_get_data (void) const { return matrix.mex_get_data (); }
221 
222  mxArray *as_mxArray (void) const;
223 
224  // Mapper functions are converted to double for treatment
225  octave_value map (unary_mapper_t umap) const
226  {
227  octave_matrix m (array_value ());
228  return m.map (umap);
229  }
230 
231 protected:
232 
234 
236 };
237 
238 #endif