GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-perm.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2008-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_perm_h)
27 #define octave_ov_perm_h 1
28 
29 #include "octave-config.h"
30 
31 #include "mx-base.h"
32 #include "str-vec.h"
33 
34 #include "ov-base.h"
35 #include "ov-typeinfo.h"
36 #include "ovl.h"
37 
38 class
39 OCTINTERP_API
41 {
42 public:
43  octave_perm_matrix () : m_matrix (), m_dense_cache () { }
44 
45  octave_perm_matrix (const PermMatrix& p) : m_matrix (p), m_dense_cache () { }
46 
48  { return new octave_perm_matrix (*this); }
50  { return new octave_perm_matrix (); }
51 
52  type_conv_info numeric_conversion_function () const;
53 
54  octave_base_value * try_narrowing_conversion ();
55 
56  std::size_t byte_size () const { return m_matrix.byte_size (); }
57 
58  octave_value squeeze () const { return m_matrix; }
59 
60  octave_value full_value () const { return to_dense (); }
61 
62  // We don't need to override all three forms of subsref. The using
63  // declaration will avoid warnings about partially-overloaded virtual
64  // functions.
66 
67  octave_value subsref (const std::string& type,
68  const std::list<octave_value_list>& idx);
69 
70  octave_value_list subsref (const std::string& type,
71  const std::list<octave_value_list>& idx, int)
72  { return subsref (type, idx); }
73 
74  octave_value do_index_op (const octave_value_list& idx,
75  bool resize_ok = false);
76 
77  dim_vector dims () const { return m_matrix.dims (); }
78 
79  octave_idx_type nnz () const { return m_matrix.rows (); }
80 
81  octave_value reshape (const dim_vector& new_dims) const
82  { return to_dense ().reshape (new_dims); }
83 
84  octave_value permute (const Array<int>& vec, bool inv = false) const
85  { return to_dense ().permute (vec, inv); }
86 
87  octave_value resize (const dim_vector& dv, bool fill = false) const
88  { return to_dense ().resize (dv, fill); }
89 
90  octave_value all (int dim = 0) const { return to_dense ().all (dim); }
91  octave_value any (int dim = 0) const { return to_dense ().any (dim); }
92 
95  { return matrix_type (); }
96 
97  // We don't need to override both forms of the diag method. The using
98  // declaration will avoid warnings about partially-overloaded virtual
99  // functions.
101 
103  { return to_dense () .diag (k); }
104 
106  { return to_dense ().sort (dim, mode); }
108  sortmode mode = ASCENDING) const
109  { return to_dense ().sort (sidx, dim, mode); }
110 
112  { return to_dense ().issorted (mode); }
113 
115  { return to_dense ().sort_rows_idx (mode); }
116 
118  { return to_dense ().is_sorted_rows (mode); }
119 
121 
122  bool is_perm_matrix () const { return true; }
123 
124  bool is_matrix_type () const { return true; }
125 
126  bool isnumeric () const { return true; }
127 
128  bool is_defined () const { return true; }
129 
130  bool is_constant () const { return true; }
131 
132  bool is_real_matrix () const { return true; }
133 
134  bool isreal () const { return true; }
135 
136  bool is_double_type () const { return true; }
137 
138  bool isfloat () const { return true; }
139 
140  bool is_true () const;
141 
142  double double_value (bool = false) const;
143 
144  float float_value (bool = false) const;
145 
146  double scalar_value (bool frc_str_conv = false) const
147  { return double_value (frc_str_conv); }
148 
149  octave::idx_vector index_vector (bool require_integers = false) const;
150 
152  { return m_matrix; }
153 
154  Matrix matrix_value (bool = false) const;
155 
156  FloatMatrix float_matrix_value (bool = false) const;
157 
158  Complex complex_value (bool = false) const;
159 
160  FloatComplex float_complex_value (bool = false) const;
161 
162  ComplexMatrix complex_matrix_value (bool = false) const;
163 
164  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
165 
166  ComplexNDArray complex_array_value (bool = false) const;
167 
168  FloatComplexNDArray float_complex_array_value (bool = false) const;
169 
170  boolNDArray bool_array_value (bool warn = false) const;
171 
172  charNDArray char_array_value (bool = false) const;
173 
174  NDArray array_value (bool = false) const;
175 
176  FloatNDArray float_array_value (bool = false) const;
177 
178  SparseMatrix sparse_matrix_value (bool = false) const;
179 
180  SparseBoolMatrix sparse_bool_matrix_value (bool = false) const;
181 
182  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
183 
185  int8_array_value () const { return to_dense ().int8_array_value (); }
186 
188  int16_array_value () const { return to_dense ().int16_array_value (); }
189 
191  int32_array_value () const { return to_dense ().int32_array_value (); }
192 
194  int64_array_value () const { return to_dense ().int64_array_value (); }
195 
197  uint8_array_value () const { return to_dense ().uint8_array_value (); }
198 
200  uint16_array_value () const { return to_dense ().uint16_array_value (); }
201 
203  uint32_array_value () const { return to_dense ().uint32_array_value (); }
204 
206  uint64_array_value () const { return to_dense ().uint64_array_value (); }
207 
208  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
209 
210  octave_value as_double () const;
211  octave_value as_single () const;
212 
213  octave_value as_int8 () const;
214  octave_value as_int16 () const;
215  octave_value as_int32 () const;
216  octave_value as_int64 () const;
217 
218  octave_value as_uint8 () const;
219  octave_value as_uint16 () const;
220  octave_value as_uint32 () const;
221  octave_value as_uint64 () const;
222 
223  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
224 
225  float_display_format get_edit_display_format () const;
226 
227  std::string edit_display (const float_display_format& fmt,
228  octave_idx_type i, octave_idx_type j) const;
229 
230  bool save_ascii (std::ostream& os);
231 
232  bool load_ascii (std::istream& is);
233 
234  bool save_binary (std::ostream& os, bool save_as_floats);
235 
236  bool load_binary (std::istream& is, bool swap,
238 
239  int write (octave::stream& os, int block_size,
240  oct_data_conv::data_type output_type, int skip,
241  octave::mach_info::float_format flt_fmt) const;
242 
243  mxArray * as_mxArray (bool interleaved) const;
244 
245  bool print_as_scalar () const;
246 
247  void print (std::ostream& os, bool pr_as_read_syntax = false);
248 
249  void print_info (std::ostream& os, const std::string& prefix) const;
250 
251  void short_disp (std::ostream& os) const;
252 
254  { return to_dense ().map (umap); }
255 
256  octave_value fast_elem_extract (octave_idx_type n) const;
257 
258 protected:
259 
261 
262  virtual octave_value to_dense () const;
263 
265 
266 private:
267 
269 };
270 
271 #endif
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array-base.cc:2079
@ Permuted_Diagonal
Definition: MatrixType.h:44
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:248
virtual octave_value diag(octave_idx_type k=0) const
Definition: ov-base.cc:1041
octave_value all(int dim=0) const
Definition: ov-perm.h:90
bool is_matrix_type() const
Definition: ov-perm.h:124
uint16NDArray uint16_array_value() const
Definition: ov-perm.h:200
uint64NDArray uint64_array_value() const
Definition: ov-perm.h:206
bool is_double_type() const
Definition: ov-perm.h:136
bool is_constant() const
Definition: ov-perm.h:130
double scalar_value(bool frc_str_conv=false) const
Definition: ov-perm.h:146
PermMatrix m_matrix
Definition: ov-perm.h:260
octave_value diag(octave_idx_type k=0) const
Definition: ov-perm.h:102
MatrixType matrix_type(const MatrixType &) const
Definition: ov-perm.h:94
int8NDArray int8_array_value() const
Definition: ov-perm.h:185
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-perm.h:111
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-perm.h:81
bool isreal() const
Definition: ov-perm.h:134
dim_vector dims() const
Definition: ov-perm.h:77
int32NDArray int32_array_value() const
Definition: ov-perm.h:191
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-perm.h:107
builtin_type_t builtin_type() const
Definition: ov-perm.h:120
int64NDArray int64_array_value() const
Definition: ov-perm.h:194
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-perm.h:117
bool isfloat() const
Definition: ov-perm.h:138
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-perm.h:70
uint8NDArray uint8_array_value() const
Definition: ov-perm.h:197
octave_base_value * clone() const
Definition: ov-perm.h:47
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-perm.h:105
bool is_perm_matrix() const
Definition: ov-perm.h:122
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-perm.h:114
bool is_defined() const
Definition: ov-perm.h:128
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-perm.h:84
std::size_t byte_size() const
Definition: ov-perm.h:56
int16NDArray int16_array_value() const
Definition: ov-perm.h:188
uint32NDArray uint32_array_value() const
Definition: ov-perm.h:203
bool is_real_matrix() const
Definition: ov-perm.h:132
octave_value any(int dim=0) const
Definition: ov-perm.h:91
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-perm.h:87
PermMatrix perm_matrix_value() const
Definition: ov-perm.h:151
octave_idx_type nnz() const
Definition: ov-perm.h:79
octave_value squeeze() const
Definition: ov-perm.h:58
MatrixType matrix_type() const
Definition: ov-perm.h:93
bool isnumeric() const
Definition: ov-perm.h:126
octave_perm_matrix(const PermMatrix &p)
Definition: ov-perm.h:45
octave_value full_value() const
Definition: ov-perm.h:60
octave_value m_dense_cache
Definition: ov-perm.h:264
octave_value map(unary_mapper_t umap) const
Definition: ov-perm.h:253
octave_base_value * empty_clone() const
Definition: ov-perm.h:49
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:574
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1416
octave_value any(int dim=0) const
Definition: ov.h:687
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:571
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1513
octave_value all(int dim=0) const
Definition: ov.h:684
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:580
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1410
octave::idx_vector idx_vector
Definition: idx-vector.h:1022
float_format
Definition: mach-info.h:38
bool is_true(const std::string &s)
Definition: mkoctfile.cc:604
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
sortmode
Definition: oct-sort.h:97
@ UNSORTED
Definition: oct-sort.h:97
@ ASCENDING
Definition: oct-sort.h:97
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:181
builtin_type_t
Definition: ov-base.h:83
@ btyp_double
Definition: ov-base.h:84