GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-bool-mat.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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
48
49// Character matrix values.
50
51extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<boolNDArray>;
52
54{
55public:
56
59
62
65
68
71
72 octave_bool_matrix (const boolNDArray& bm, const octave::idx_vector& cache)
74 {
75 set_idx_cache (cache);
76 }
77
80
81 ~octave_bool_matrix () = default;
82
84 { return new octave_bool_matrix (*this); }
85
87 { return new octave_bool_matrix (); }
88
89 type_conv_info numeric_conversion_function () const;
90
91 octave_base_value * try_narrowing_conversion ();
92
93 octave::idx_vector index_vector (bool /* require_integers */ = false) const
94 {
95 return m_idx_cache ? *m_idx_cache
96 : set_idx_cache (octave::idx_vector (m_matrix));
97 }
98
100
101 bool is_bool_matrix () const { return true; }
102
103 bool islogical () const { return true; }
104
105 bool isreal () const { return true; }
106
107 bool isnumeric () const { return false; }
108
110 int8_array_value () const { return int8NDArray (m_matrix); }
111
113 int16_array_value () const { return int16NDArray (m_matrix); }
114
116 int32_array_value () const { return int32NDArray (m_matrix); }
117
119 int64_array_value () const { return int64NDArray (m_matrix); }
120
122 uint8_array_value () const { return uint8NDArray (m_matrix); }
123
125 uint16_array_value () const { return uint16NDArray (m_matrix); }
126
128 uint32_array_value () const { return uint32NDArray (m_matrix); }
129
131 uint64_array_value () const { return uint64NDArray (m_matrix); }
132
133 double double_value (bool = false) const;
134
135 float float_value (bool = false) const;
136
137 double scalar_value (bool frc_str_conv = false) const
138 { return double_value (frc_str_conv); }
139
140 Matrix matrix_value (bool = false) const
141 { return Matrix (boolMatrix (m_matrix)); }
142
143 FloatMatrix float_matrix_value (bool = false) const
144 { return FloatMatrix (boolMatrix (m_matrix)); }
145
146 NDArray array_value (bool = false) const
147 { return NDArray (m_matrix); }
148
149 FloatNDArray float_array_value (bool = false) const
150 { return FloatNDArray (m_matrix); }
151
152 Complex complex_value (bool = false) const;
153
154 FloatComplex float_complex_value (bool = false) const;
155
157 { return ComplexMatrix (boolMatrix (m_matrix)); }
158
160 { return FloatComplexMatrix (boolMatrix (m_matrix)); }
161
163 { return ComplexNDArray (m_matrix); }
164
166 { return FloatComplexNDArray (m_matrix); }
167
169 char_array_value (bool = false) const
170 {
171 charNDArray retval (dims ());
172
173 octave_idx_type nel = numel ();
174
175 for (octave_idx_type i = 0; i < nel; i++)
176 retval(i) = static_cast<char> (m_matrix(i));
177
178 return retval;
179 }
180
181 boolMatrix bool_matrix_value (bool = false) const
182 { return boolMatrix (m_matrix); }
183
184 boolNDArray bool_array_value (bool = false) const
185 { return m_matrix; }
186
188 { return SparseMatrix (Matrix (boolMatrix (m_matrix))); }
189
192
194 { return SparseBoolMatrix (boolMatrix (m_matrix)); }
195
196 octave_value convert_to_str_internal (bool pad, bool force, char type) const;
197
198 octave_value as_double () const;
199 octave_value as_single () const;
200
201 octave_value as_int8 () const;
202 octave_value as_int16 () const;
203 octave_value as_int32 () const;
204 octave_value as_int64 () const;
205
206 octave_value as_uint8 () const;
207 octave_value as_uint16 () const;
208 octave_value as_uint32 () const;
209 octave_value as_uint64 () const;
210
211 // Use matrix_ref here to clear index cache.
212 void invert () { matrix_ref ().invert (); }
213
214 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
215
216 bool save_ascii (std::ostream& os);
217
218 bool load_ascii (std::istream& is);
219
220 bool save_binary (std::ostream& os, bool save_as_floats);
221
222 bool load_binary (std::istream& is, bool swap,
223 octave::mach_info::float_format fmt);
224
225 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
226
227 bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
228
229 int write (octave::stream& os, int block_size,
230 oct_data_conv::data_type output_type, int skip,
231 octave::mach_info::float_format flt_fmt) const
232 { return os.write (m_matrix, block_size, output_type, skip, flt_fmt); }
233
234 mxArray * as_mxArray (bool interleaved) const;
235
236 // Mapper functions are converted to double for treatment
238 {
240 return m.map (umap);
241 }
242
243protected:
244
246};
247
248#endif
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
int8NDArray int8_array_value() const
int64NDArray int64_array_value() const
charNDArray char_array_value(bool=false) const
octave_bool_matrix(const boolMatrix &bm, const MatrixType &t)
Definition ov-bool-mat.h:69
uint8NDArray uint8_array_value() const
boolNDArray bool_array_value(bool=false) const
uint64NDArray uint64_array_value() const
builtin_type_t builtin_type() const
Definition ov-bool-mat.h:99
FloatComplexMatrix float_complex_matrix_value(bool=false) const
octave_bool_matrix(const boolNDArray &bm, const octave::idx_vector &cache)
Definition ov-bool-mat.h:72
ComplexNDArray complex_array_value(bool=false) const
octave_bool_matrix(const Array< bool > &bnda)
Definition ov-bool-mat.h:63
NDArray array_value(bool=false) const
bool isnumeric() const
octave_bool_matrix(const boolNDArray &bnda)
Definition ov-bool-mat.h:60
boolMatrix bool_matrix_value(bool=false) const
double scalar_value(bool frc_str_conv=false) const
int32NDArray int32_array_value() const
octave::idx_vector index_vector(bool=false) const
Definition ov-bool-mat.h:93
uint32NDArray uint32_array_value() const
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
uint16NDArray uint16_array_value() const
bool is_bool_matrix() const
octave_base_value * empty_clone() const
Definition ov-bool-mat.h:86
octave_base_value * clone() const
Definition ov-bool-mat.h:83
FloatMatrix float_matrix_value(bool=false) const
SparseMatrix sparse_matrix_value(bool=false) const
ComplexMatrix complex_matrix_value(bool=false) const
bool islogical() const
octave_value map(unary_mapper_t umap) const
FloatNDArray float_array_value(bool=false) const
octave_bool_matrix(const boolMatrix &bm)
Definition ov-bool-mat.h:66
Matrix matrix_value(bool=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
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
octave_bool_matrix(const octave_bool_matrix &bm)
Definition ov-bool-mat.h:78
FloatComplexNDArray float_complex_array_value(bool=false) const
int16NDArray int16_array_value() const
bool isreal() const
~octave_bool_matrix()=default
octave_value map(unary_mapper_t umap) const
Definition ov-re-mat.cc:910
Array< octave_value > array_value() const
Definition ovl.h:88
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
Definition int8NDArray.h:36
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_API(API)
Definition ov-base.h:185
builtin_type_t
Definition ov-base.h:83
@ btyp_bool
Definition ov-base.h:96
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray