GNU Octave  9.1.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-2024 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 
73  {
74  set_idx_cache (cache);
75  }
76 
79 
80  ~octave_bool_matrix () = default;
81 
83  { return new octave_bool_matrix (*this); }
84 
86  { return new octave_bool_matrix (); }
87 
88  type_conv_info numeric_conversion_function () const;
89 
90  octave_base_value * try_narrowing_conversion ();
91 
92  octave::idx_vector index_vector (bool /* require_integers */ = false) const
93  {
94  return m_idx_cache ? *m_idx_cache
95  : set_idx_cache (octave::idx_vector (m_matrix));
96  }
97 
98  builtin_type_t builtin_type () const { return btyp_bool; }
99 
100  bool is_bool_matrix () const { return true; }
101 
102  bool islogical () const { return true; }
103 
104  bool isreal () const { return true; }
105 
106  bool isnumeric () const { return false; }
107 
109  int8_array_value () const { return int8NDArray (m_matrix); }
110 
112  int16_array_value () const { return int16NDArray (m_matrix); }
113 
115  int32_array_value () const { return int32NDArray (m_matrix); }
116 
118  int64_array_value () const { return int64NDArray (m_matrix); }
119 
121  uint8_array_value () const { return uint8NDArray (m_matrix); }
122 
124  uint16_array_value () const { return uint16NDArray (m_matrix); }
125 
127  uint32_array_value () const { return uint32NDArray (m_matrix); }
128 
130  uint64_array_value () const { return uint64NDArray (m_matrix); }
131 
132  double double_value (bool = false) const;
133 
134  float float_value (bool = false) const;
135 
136  double scalar_value (bool frc_str_conv = false) const
137  { return double_value (frc_str_conv); }
138 
139  Matrix matrix_value (bool = false) const
140  { return Matrix (boolMatrix (m_matrix)); }
141 
142  FloatMatrix float_matrix_value (bool = false) const
143  { return FloatMatrix (boolMatrix (m_matrix)); }
144 
145  NDArray array_value (bool = false) const
146  { return NDArray (m_matrix); }
147 
148  FloatNDArray float_array_value (bool = false) const
149  { return FloatNDArray (m_matrix); }
150 
151  Complex complex_value (bool = false) const;
152 
153  FloatComplex float_complex_value (bool = false) const;
154 
155  ComplexMatrix complex_matrix_value (bool = false) const
156  { return ComplexMatrix (boolMatrix (m_matrix)); }
157 
159  { return FloatComplexMatrix (boolMatrix (m_matrix)); }
160 
161  ComplexNDArray complex_array_value (bool = false) const
162  { return ComplexNDArray (m_matrix); }
163 
165  { return FloatComplexNDArray (m_matrix); }
166 
168  char_array_value (bool = false) const
169  {
170  charNDArray retval (dims ());
171 
172  octave_idx_type nel = numel ();
173 
174  for (octave_idx_type i = 0; i < nel; i++)
175  retval(i) = static_cast<char> (m_matrix(i));
176 
177  return retval;
178  }
179 
180  boolMatrix bool_matrix_value (bool = false) const
181  { return boolMatrix (m_matrix); }
182 
183  boolNDArray bool_array_value (bool = false) const
184  { return m_matrix; }
185 
186  SparseMatrix sparse_matrix_value (bool = false) const
187  { return SparseMatrix (Matrix (boolMatrix (m_matrix))); }
188 
190  { return SparseComplexMatrix (ComplexMatrix (boolMatrix (m_matrix))); }
191 
193  { return SparseBoolMatrix (boolMatrix (m_matrix)); }
194 
195  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
196 
197  octave_value as_double () const;
198  octave_value as_single () const;
199 
200  octave_value as_int8 () const;
201  octave_value as_int16 () const;
202  octave_value as_int32 () const;
203  octave_value as_int64 () const;
204 
205  octave_value as_uint8 () const;
206  octave_value as_uint16 () const;
207  octave_value as_uint32 () const;
208  octave_value as_uint64 () const;
209 
210  // Use matrix_ref here to clear index cache.
211  void invert () { matrix_ref ().invert (); }
212 
213  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
214 
215  bool save_ascii (std::ostream& os);
216 
217  bool load_ascii (std::istream& is);
218 
219  bool save_binary (std::ostream& os, bool save_as_floats);
220 
221  bool load_binary (std::istream& is, bool swap,
223 
224  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
225 
226  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
227 
228  int write (octave::stream& os, int block_size,
229  oct_data_conv::data_type output_type, int skip,
230  octave::mach_info::float_format flt_fmt) const
231  { return os.write (m_matrix, block_size, output_type, skip, flt_fmt); }
232 
233  mxArray * as_mxArray (bool interleaved) const;
234 
235  // Mapper functions are converted to double for treatment
237  {
239  return m.map (umap);
240  }
241 
242 protected:
243 
245 };
246 
247 #endif
Definition: dMatrix.h:42
int8NDArray int8_array_value() const
Definition: ov-bool-mat.h:109
int64NDArray int64_array_value() const
Definition: ov-bool-mat.h:118
charNDArray char_array_value(bool=false) const
Definition: ov-bool-mat.h:168
octave_bool_matrix(const boolMatrix &bm, const MatrixType &t)
Definition: ov-bool-mat.h:68
octave_base_value * clone() const
Definition: ov-bool-mat.h:82
uint8NDArray uint8_array_value() const
Definition: ov-bool-mat.h:121
boolNDArray bool_array_value(bool=false) const
Definition: ov-bool-mat.h:183
uint64NDArray uint64_array_value() const
Definition: ov-bool-mat.h:130
builtin_type_t builtin_type() const
Definition: ov-bool-mat.h:98
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:158
octave_bool_matrix(const boolNDArray &bm, const octave::idx_vector &cache)
Definition: ov-bool-mat.h:71
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-bool-mat.h:161
octave_bool_matrix(const Array< bool > &bnda)
Definition: ov-bool-mat.h:62
NDArray array_value(bool=false) const
Definition: ov-bool-mat.h:145
bool isnumeric() const
Definition: ov-bool-mat.h:106
octave_bool_matrix(const boolNDArray &bnda)
Definition: ov-bool-mat.h:59
boolMatrix bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:180
octave_base_value * empty_clone() const
Definition: ov-bool-mat.h:85
double scalar_value(bool frc_str_conv=false) const
Definition: ov-bool-mat.h:136
int32NDArray int32_array_value() const
Definition: ov-bool-mat.h:115
octave::idx_vector index_vector(bool=false) const
Definition: ov-bool-mat.h:92
uint32NDArray uint32_array_value() const
Definition: ov-bool-mat.h:127
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:192
uint16NDArray uint16_array_value() const
Definition: ov-bool-mat.h:124
bool is_bool_matrix() const
Definition: ov-bool-mat.h:100
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-bool-mat.h:142
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-bool-mat.h:186
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:155
bool islogical() const
Definition: ov-bool-mat.h:102
octave_value map(unary_mapper_t umap) const
Definition: ov-bool-mat.h:236
FloatNDArray float_array_value(bool=false) const
Definition: ov-bool-mat.h:148
octave_bool_matrix(const boolMatrix &bm)
Definition: ov-bool-mat.h:65
Matrix matrix_value(bool=false) const
Definition: ov-bool-mat.h:139
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:189
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:228
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:164
int16NDArray int16_array_value() const
Definition: ov-bool-mat.h:112
bool isreal() const
Definition: ov-bool-mat.h:104
~octave_bool_matrix()=default
Array< octave_value > array_value() const
Definition: ovl.h:90
octave::idx_vector idx_vector
Definition: idx-vector.h:1022
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
float_format
Definition: mach-info.h:38
T octave_idx_type m
Definition: mx-inlines.cc:781
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:74
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:181
builtin_type_t
Definition: ov-base.h:83
@ btyp_bool
Definition: ov-base.h:96
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