GNU Octave  8.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-2023 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 (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  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 (void) const { return btyp_bool; }
99 
100  bool is_bool_matrix (void) const { return true; }
101 
102  bool islogical (void) const { return true; }
103 
104  bool isreal (void) const { return true; }
105 
106  bool isnumeric (void) const { return false; }
107 
109  int8_array_value (void) const { return int8NDArray (m_matrix); }
110 
112  int16_array_value (void) const { return int16NDArray (m_matrix); }
113 
115  int32_array_value (void) const { return int32NDArray (m_matrix); }
116 
118  int64_array_value (void) const { return int64NDArray (m_matrix); }
119 
121  uint8_array_value (void) const { return uint8NDArray (m_matrix); }
122 
124  uint16_array_value (void) const { return uint16NDArray (m_matrix); }
125 
127  uint32_array_value (void) const { return uint32NDArray (m_matrix); }
128 
130  uint64_array_value (void) 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 (void) const;
198  octave_value as_single (void) const;
199 
200  octave_value as_int8 (void) const;
201  octave_value as_int16 (void) const;
202  octave_value as_int32 (void) const;
203  octave_value as_int64 (void) const;
204 
205  octave_value as_uint8 (void) const;
206  octave_value as_uint16 (void) const;
207  octave_value as_uint32 (void) const;
208  octave_value as_uint64 (void) const;
209 
210  // Use matrix_ref here to clear index cache.
211  void invert (void) { 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
bool isreal(void) const
Definition: ov-bool-mat.h:104
int32NDArray int32_array_value(void) const
Definition: ov-bool-mat.h:115
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
boolNDArray bool_array_value(bool=false) const
Definition: ov-bool-mat.h:183
uint32NDArray uint32_array_value(void) const
Definition: ov-bool-mat.h:127
~octave_bool_matrix(void)=default
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
octave_base_value * clone(void) const
Definition: ov-bool-mat.h:82
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 is_bool_matrix(void) const
Definition: ov-bool-mat.h:100
octave_bool_matrix(const boolNDArray &bnda)
Definition: ov-bool-mat.h:59
builtin_type_t builtin_type(void) const
Definition: ov-bool-mat.h:98
boolMatrix bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:180
double scalar_value(bool frc_str_conv=false) const
Definition: ov-bool-mat.h:136
octave::idx_vector index_vector(bool=false) const
Definition: ov-bool-mat.h:92
int64NDArray int64_array_value(void) const
Definition: ov-bool-mat.h:118
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition: ov-bool-mat.h:192
void invert(void)
Definition: ov-bool-mat.h:211
int8NDArray int8_array_value(void) const
Definition: ov-bool-mat.h:109
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
int16NDArray int16_array_value(void) const
Definition: ov-bool-mat.h:112
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-bool-mat.h:155
uint64NDArray uint64_array_value(void) const
Definition: ov-bool-mat.h:130
octave_value map(unary_mapper_t umap) const
Definition: ov-bool-mat.h:236
uint16NDArray uint16_array_value(void) const
Definition: ov-bool-mat.h:124
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
octave_bool_matrix(void)
Definition: ov-bool-mat.h:56
Matrix matrix_value(bool=false) const
Definition: ov-bool-mat.h:139
uint8NDArray uint8_array_value(void) const
Definition: ov-bool-mat.h:121
bool isnumeric(void) const
Definition: ov-bool-mat.h:106
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
bool islogical(void) const
Definition: ov-bool-mat.h:102
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
octave_base_value * empty_clone(void) const
Definition: ov-bool-mat.h:85
Array< octave_value > array_value(void) const
Definition: ovl.h:90
octave::idx_vector idx_vector
Definition: idx-vector.h:1039
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
class OCTAVE_API NDArray
Definition: mx-fwd.h:38
class OCTAVE_API Matrix
Definition: mx-fwd.h:31
class OCTAVE_API boolMatrix
Definition: mx-fwd.h:35
class OCTAVE_API ComplexMatrix
Definition: mx-fwd.h:32
class OCTAVE_API SparseMatrix
Definition: mx-fwd.h:55
class OCTAVE_API FloatComplexMatrix
Definition: mx-fwd.h:34
class OCTAVE_API FloatMatrix
Definition: mx-fwd.h:33
class OCTAVE_API ComplexNDArray
Definition: mx-fwd.h:39
class OCTAVE_API SparseComplexMatrix
Definition: mx-fwd.h:56
class OCTAVE_API FloatComplexNDArray
Definition: mx-fwd.h:41
class OCTAVE_API SparseBoolMatrix
Definition: mx-fwd.h:57
class OCTAVE_API FloatNDArray
Definition: mx-fwd.h:40
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(OCTAVE_TIME_T sec, long usec)
Definition: oct-time.h:35
#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