GNU Octave  6.2.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-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_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 (void) = default;
85 
86  octave_base_value * clone (void) const
87  { return new octave_float_matrix (*this); }
89  { return new octave_float_matrix (); }
90 
91  octave_base_value * try_narrowing_conversion (void);
92 
93  idx_vector index_vector (bool /* require_integers */ = false) const
94  {
95  return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix));
96  }
97 
98  builtin_type_t builtin_type (void) const { return btyp_float; }
99 
100  bool is_real_matrix (void) const { return true; }
101 
102  bool isreal (void) const { return true; }
103 
104  bool is_single_type (void) const { return true; }
105 
106  bool isfloat (void) const { return true; }
107 
109  int8_array_value (void) const { return int8NDArray (matrix); }
110 
112  int16_array_value (void) const { return int16NDArray (matrix); }
113 
115  int32_array_value (void) const { return int32NDArray (matrix); }
116 
118  int64_array_value (void) const { return int64NDArray (matrix); }
119 
121  uint8_array_value (void) const { return uint8NDArray (matrix); }
122 
124  uint16_array_value (void) const { return uint16NDArray (matrix); }
125 
127  uint32_array_value (void) const { return uint32NDArray (matrix); }
128 
130  uint64_array_value (void) const { return uint64NDArray (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  float float_scalar_value (bool frc_str_conv = false) const
140  { return float_value (frc_str_conv); }
141 
142  Matrix matrix_value (bool = false) const;
143 
144  FloatMatrix float_matrix_value (bool = false) const;
145 
146  Complex complex_value (bool = false) const;
147 
148  FloatComplex float_complex_value (bool = false) const;
149 
150  ComplexMatrix complex_matrix_value (bool = false) const;
151 
152  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
153 
154  ComplexNDArray complex_array_value (bool = false) const;
155 
156  FloatComplexNDArray float_complex_array_value (bool = false) const;
157 
158  boolNDArray bool_array_value (bool warn = false) const;
159 
160  charNDArray char_array_value (bool = false) const;
161 
162  NDArray array_value (bool = false) const;
163 
164  FloatNDArray float_array_value (bool = false) const { return matrix; }
165 
166  SparseMatrix sparse_matrix_value (bool = false) const;
167 
168  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
169 
170  octave_value as_double (void) const;
171  octave_value as_single (void) const;
172 
173  octave_value as_int8 (void) const;
174  octave_value as_int16 (void) const;
175  octave_value as_int32 (void) const;
176  octave_value as_int64 (void) const;
177 
178  octave_value as_uint8 (void) const;
179  octave_value as_uint16 (void) const;
180  octave_value as_uint32 (void) const;
181  octave_value as_uint64 (void) const;
182 
183  octave_value diag (octave_idx_type k = 0) const;
184 
186 
187  // Use matrix_ref here to clear index cache.
188  void increment (void) { matrix_ref () += 1.0; }
189 
190  void decrement (void) { matrix_ref () -= 1.0; }
191 
192  void changesign (void) { matrix_ref ().changesign (); }
193 
194  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
195 
196  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
197 
198  bool save_ascii (std::ostream& os);
199 
200  bool load_ascii (std::istream& is);
201 
202  bool save_binary (std::ostream& os, bool save_as_floats);
203 
204  bool load_binary (std::istream& is, bool swap,
206 
207  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
208 
209  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
210 
211  int write (octave::stream& os, int block_size,
212  oct_data_conv::data_type output_type, int skip,
213  octave::mach_info::float_format flt_fmt) const
214  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
215 
216  // Unsafe. This function exists to support the MEX interface.
217  // You should not use it anywhere else.
218  void * mex_get_data (void) const { return matrix.mex_get_data (); }
219 
220  mxArray * as_mxArray (void) const;
221 
222  octave_value map (unary_mapper_t umap) const;
223 
224 private:
225 
227 };
228 
229 #endif
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:128
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
FloatNDArray float_array_value(bool=false) const
int8NDArray int8_array_value(void) const
bool isreal(void) const
octave_float_matrix(const octave_float_matrix &m)
Definition: ov-flt-re-mat.h:81
int32NDArray int32_array_value(void) const
octave_base_value * clone(void) const
Definition: ov-flt-re-mat.h:86
bool is_single_type(void) const
int64NDArray int64_array_value(void) const
octave_float_matrix(const FloatMatrix &m, const MatrixType &t)
Definition: ov-flt-re-mat.h:63
bool isfloat(void) const
octave_float_matrix(const FloatRowVector &v)
Definition: ov-flt-re-mat.h:75
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
uint32NDArray uint32_array_value(void) const
builtin_type_t builtin_type(void) const
Definition: ov-flt-re-mat.h:98
void * mex_get_data(void) const
octave_float_matrix(const FloatColumnVector &v)
Definition: ov-flt-re-mat.h:78
octave_base_value * empty_clone(void) const
Definition: ov-flt-re-mat.h:88
~octave_float_matrix(void)=default
float float_scalar_value(bool frc_str_conv=false) const
uint8NDArray uint8_array_value(void) const
bool is_real_matrix(void) const
octave_float_matrix(const Array< float > &m)
Definition: ov-flt-re-mat.h:69
idx_vector index_vector(bool=false) const
Definition: ov-flt-re-mat.h:93
uint64NDArray uint64_array_value(void) 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
int16NDArray int16_array_value(void) const
octave_float_matrix(const FloatMatrix &m)
Definition: ov-flt-re-mat.h:60
uint16NDArray uint16_array_value(void) const
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
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
int64_t octave_hdf5_id
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_float
Definition: ov-base.h:74
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