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