GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-flt-re-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_flt_re_mat_h)
27 #define octave_ov_flt_re_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 #include "str-vec.h"
38 
39 #include "error.h"
40 #include "oct-stream.h"
41 #include "ov-base.h"
42 #include "ov-base-mat.h"
43 #include "ov-typeinfo.h"
44 
45 #include "MatrixType.h"
46 
47 class octave_value_list;
48 
49 // Real matrix values.
50 
51 class
52 OCTINTERP_API
54 {
55 public:
56 
59 
62 
65 
67  : octave_base_matrix<FloatNDArray> (nda) { }
68 
71 
74 
77 
80 
83 
84  ~octave_float_matrix () = default;
85 
87  { return new octave_float_matrix (*this); }
89  { return new octave_float_matrix (); }
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 
99  builtin_type_t builtin_type () const { return btyp_float; }
100 
101  bool is_real_matrix () const { return true; }
102 
103  bool isreal () const { return true; }
104 
105  bool is_single_type () const { return true; }
106 
107  bool isfloat () const { return true; }
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  float float_scalar_value (bool frc_str_conv = false) const
141  { return float_value (frc_str_conv); }
142 
143  Matrix matrix_value (bool = false) const;
144 
145  FloatMatrix float_matrix_value (bool = false) const;
146 
147  Complex complex_value (bool = false) const;
148 
149  FloatComplex float_complex_value (bool = false) const;
150 
151  ComplexMatrix complex_matrix_value (bool = false) const;
152 
153  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
154 
155  ComplexNDArray complex_array_value (bool = false) const;
156 
157  FloatComplexNDArray float_complex_array_value (bool = false) const;
158 
159  boolNDArray bool_array_value (bool warn = false) const;
160 
161  charNDArray char_array_value (bool = false) const;
162 
163  NDArray array_value (bool = false) const;
164 
165  FloatNDArray float_array_value (bool = false) const { return m_matrix; }
166 
167  SparseMatrix sparse_matrix_value (bool = false) const;
168 
169  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
170 
171  octave_value as_double () const;
172  octave_value as_single () const;
173 
174  octave_value as_int8 () const;
175  octave_value as_int16 () const;
176  octave_value as_int32 () const;
177  octave_value as_int64 () const;
178 
179  octave_value as_uint8 () const;
180  octave_value as_uint16 () const;
181  octave_value as_uint32 () const;
182  octave_value as_uint64 () const;
183 
184  octave_value diag (octave_idx_type k = 0) const;
185 
187 
188  // Use matrix_ref here to clear index cache.
189  void increment () { matrix_ref () += 1.0; }
190 
191  void decrement () { matrix_ref () -= 1.0; }
192 
193  void changesign () { matrix_ref ().changesign (); }
194 
195  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
196 
197  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
198 
199  bool save_ascii (std::ostream& os);
200 
201  bool load_ascii (std::istream& is);
202 
203  bool save_binary (std::ostream& os, bool save_as_floats);
204 
205  bool load_binary (std::istream& is, bool swap,
207 
208  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
209 
210  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
211 
212  int write (octave::stream& os, int block_size,
213  oct_data_conv::data_type output_type, int skip,
214  octave::mach_info::float_format flt_fmt) const
215  { return os.write (m_matrix, block_size, output_type, skip, flt_fmt); }
216 
217  mxArray * as_mxArray (bool interleaved) const;
218 
219  octave_value map (unary_mapper_t umap) const;
220 
221 private:
222 
224 };
225 
226 #endif
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:130
Definition: dMatrix.h:42
FloatNDArray float_array_value(bool=false) const
bool is_real_matrix() const
int32NDArray int32_array_value() const
bool isreal() const
octave_float_matrix(const octave_float_matrix &m)
Definition: ov-flt-re-mat.h:81
int64NDArray int64_array_value() const
octave_float_matrix(const FloatMatrix &m, const MatrixType &t)
Definition: ov-flt-re-mat.h:63
bool isfloat() const
octave_float_matrix(const FloatRowVector &v)
Definition: ov-flt-re-mat.h:75
octave::idx_vector index_vector(bool=false) const
Definition: ov-flt-re-mat.h:93
octave_base_value * clone() const
Definition: ov-flt-re-mat.h:86
~octave_float_matrix()=default
uint64NDArray uint64_array_value() const
octave_float_matrix(const FloatNDArray &nda)
Definition: ov-flt-re-mat.h:66
octave_float_matrix(const FloatDiagMatrix &d)
Definition: ov-flt-re-mat.h:72
octave_float_matrix(const FloatColumnVector &v)
Definition: ov-flt-re-mat.h:78
bool is_single_type() const
uint32NDArray uint32_array_value() const
octave_base_value * empty_clone() const
Definition: ov-flt-re-mat.h:88
float float_scalar_value(bool frc_str_conv=false) const
uint16NDArray uint16_array_value() const
uint8NDArray uint8_array_value() const
builtin_type_t builtin_type() const
Definition: ov-flt-re-mat.h:99
octave_float_matrix(const Array< float > &m)
Definition: ov-flt-re-mat.h:69
int8NDArray int8_array_value() const
int16NDArray int16_array_value() 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
double scalar_value(bool frc_str_conv=false) const
octave_float_matrix(const FloatMatrix &m)
Definition: ov-flt-re-mat.h:60
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
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
float_format
Definition: mach-info.h:38
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
int64_t octave_hdf5_id
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:181
builtin_type_t
Definition: ov-base.h:83
@ btyp_float
Definition: ov-base.h:85
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