GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-bool-mat.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://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 "octave-config.h"
28 
29 #include <cstdlib>
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "mx-base.h"
35 
36 #include "error.h"
37 #include "oct-stream.h"
38 #include "ov-base.h"
39 #include "ov-base-mat.h"
40 #include "ov-re-mat.h"
41 #include "ov-typeinfo.h"
42 
43 #include "MatrixType.h"
44 
45 class octave_value_list;
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 
69  octave_bool_matrix (const boolNDArray& bm, const idx_vector& cache)
71  {
72  set_idx_cache (cache);
73  }
74 
77 
78  ~octave_bool_matrix (void) = default;
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 islogical (void) const { return true; }
100 
101  bool isreal (void) const { return true; }
102 
103  bool isnumeric (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 
188 
190  { return SparseBoolMatrix (boolMatrix (matrix)); }
191 
192  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
193 
194  octave_value as_double (void) const;
195  octave_value as_single (void) const;
196 
197  octave_value as_int8 (void) const;
198  octave_value as_int16 (void) const;
199  octave_value as_int32 (void) const;
200  octave_value as_int64 (void) const;
201 
202  octave_value as_uint8 (void) const;
203  octave_value as_uint16 (void) const;
204  octave_value as_uint32 (void) const;
205  octave_value as_uint64 (void) const;
206 
207  // Use matrix_ref here to clear index cache.
208  void invert (void) { matrix_ref ().invert (); }
209 
210  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
211 
212  bool save_ascii (std::ostream& os);
213 
214  bool load_ascii (std::istream& is);
215 
216  bool save_binary (std::ostream& os, bool& save_as_floats);
217 
218  bool load_binary (std::istream& is, bool swap,
220 
221  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
222 
223  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
224 
225  int write (octave::stream& os, int block_size,
226  oct_data_conv::data_type output_type, int skip,
228  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
229 
230  // Unsafe. This function exists to support the MEX interface.
231  // You should not use it anywhere else.
232  void * mex_get_data (void) const { return matrix.mex_get_data (); }
233 
234  mxArray * as_mxArray (void) const;
235 
236  // Mapper functions are converted to double for treatment
238  {
239  octave_matrix m (array_value ());
240  return m.map (umap);
241  }
242 
243 protected:
244 
246 };
247 
248 #endif
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6704
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:155
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:186
int32NDArray int32_array_value(void) const
Definition: ov-bool-mat.h:112
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:33
characters Given a string matrix
Definition: hex2num.cc:155
octave_base_value * clone(void) const
Definition: ov-bool-mat.h:80
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:33
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:33
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:33
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:152
double scalar_value(bool frc_str_conv=false) const
Definition: ov-bool-mat.h:133
void * mex_get_data(void) const
Definition: ov-bool-mat.h:232
uint16NDArray uint16_array_value(void) const
Definition: ov-bool-mat.h:121
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
int64NDArray int64_array_value(void) const
Definition: ov-bool-mat.h:115
bool isreal(void) const
Definition: ov-bool-mat.h:101
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-bool-mat.h:139
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:33
int16NDArray int16_array_value(void) const
Definition: ov-bool-mat.h:109
builtin_type_t
Definition: ov-base.h:71
uint64NDArray uint64_array_value(void) const
Definition: ov-bool-mat.h:127
octave_bool_matrix(void)
Definition: ov-bool-mat.h:54
static double as_double(time_t sec, long usec)
Definition: oct-time.h:34
idx_vector index_vector(bool=false) const
Definition: ov-bool-mat.h:90
bool swap
Definition: load-save.cc:738
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
nd deftypefn *std::string name
Definition: sysdep.cc:647
uint32NDArray uint32_array_value(void) const
Definition: ov-bool-mat.h:124
octave_bool_matrix(const boolNDArray &bm, const idx_vector &cache)
Definition: ov-bool-mat.h:69
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:33
octave_base_value * empty_clone(void) const
Definition: ov-bool-mat.h:83
octave_bool_matrix(const octave_bool_matrix &bm)
Definition: ov-bool-mat.h:75
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:189
octave_bool_matrix(const boolMatrix &bm)
Definition: ov-bool-mat.h:63
octave_bool_matrix(const Array< bool > &bnda)
Definition: ov-bool-mat.h:60
Array< octave_value > array_value(void) const
Definition: ovl.h:86
bool save_as_floats
Definition: load-save.cc:1617
octave_value retval
Definition: data.cc:6246
int64_t octave_hdf5_id
int write(octave::stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
Definition: ov-bool-mat.h:225
octave_value map(unary_mapper_t umap) const
Definition: ov-re-mat.cc:900
idx type
Definition: ov.cc:3114
boolMatrix bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:177
Definition: dMatrix.h:36
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-bool-mat.h:183
bool is_bool_matrix(void) const
Definition: ov-bool-mat.h:97
FloatNDArray float_array_value(bool=false) const
Definition: ov-bool-mat.h:145
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:33
T::size_type numel(const T &str)
Definition: oct-string.cc:61
octave_value map(unary_mapper_t umap) const
Definition: ov-bool-mat.h:237
octave_bool_matrix(const boolMatrix &bm, const MatrixType &t)
Definition: ov-bool-mat.h:66
builtin_type_t builtin_type(void) const
Definition: ov-bool-mat.h:95
int8NDArray int8_array_value(void) const
Definition: ov-bool-mat.h:106
void invert(void)
Definition: ov-bool-mat.h:208
Matrix matrix_value(bool=false) const
Definition: ov-bool-mat.h:136
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-bool-mat.h:158
bool islogical(void) const
Definition: ov-bool-mat.h:99
charNDArray char_array_value(bool=false) const
Definition: ov-bool-mat.h:165
for i
Definition: data.cc:5264
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-bool-mat.h:161
std::complex< double > Complex
Definition: oct-cmplx.h:31
octave_bool_matrix(const boolNDArray &bnda)
Definition: ov-bool-mat.h:57
write the output to stdout if nargout is
Definition: load-save.cc:1612
uint8NDArray uint8_array_value(void) const
Definition: ov-bool-mat.h:118
bool isnumeric(void) const
Definition: ov-bool-mat.h:103
octave::stream os
Definition: file-io.cc:627
boolNDArray bool_array_value(bool=false) const
Definition: ov-bool-mat.h:180
NDArray array_value(bool=false) const
Definition: ov-bool-mat.h:142
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:33