GNU Octave 7.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-2022 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
38class
39OCTINTERP_API
41{
42public:
43 octave_perm_matrix (void) : m_matrix (), m_dense_cache () { }
44
45 octave_perm_matrix (const PermMatrix& p) : m_matrix (p), m_dense_cache () { }
46
47 octave_base_value * clone (void) const
48 { return new octave_perm_matrix (*this); }
50 { return new octave_perm_matrix (); }
51
52 type_conv_info numeric_conversion_function (void) const;
53
54 octave_base_value * try_narrowing_conversion (void);
55
56 std::size_t byte_size (void) const { return m_matrix.byte_size (); }
57
58 octave_value squeeze (void) const { return m_matrix; }
59
60 octave_value full_value (void) 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 (void) const { return m_matrix.dims (); }
78
79 octave_idx_type nnz (void) 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
120 builtin_type_t builtin_type (void) const { return btyp_double; }
121
122 bool is_perm_matrix (void) const { return true; }
123
124 bool is_matrix_type (void) const { return true; }
125
126 bool isnumeric (void) const { return true; }
127
128 bool is_defined (void) const { return true; }
129
130 bool is_constant (void) const { return true; }
131
132 bool is_real_matrix (void) const { return true; }
133
134 bool isreal (void) const { return true; }
135
136 bool is_double_type (void) const { return true; }
137
138 bool isfloat (void) const { return true; }
139
140 bool is_true (void) 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 (void) const { return to_dense ().int8_array_value (); }
186
188 int16_array_value (void) const { return to_dense ().int16_array_value (); }
189
191 int32_array_value (void) const { return to_dense ().int32_array_value (); }
192
194 int64_array_value (void) const { return to_dense ().int64_array_value (); }
195
197 uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
198
200 uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
201
203 uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
204
206 uint64_array_value (void) 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 (void) const;
211 octave_value as_single (void) const;
212
213 octave_value as_int8 (void) const;
214 octave_value as_int16 (void) const;
215 octave_value as_int32 (void) const;
216 octave_value as_int64 (void) const;
217
218 octave_value as_uint8 (void) const;
219 octave_value as_uint16 (void) const;
220 octave_value as_uint32 (void) const;
221 octave_value as_uint64 (void) const;
222
223 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
224
226
227 std::string edit_display (const float_display_format& fmt,
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 (void) 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
258protected:
259
261
262 virtual octave_value to_dense (void) const;
263
265
266private:
267
269};
270
271#endif
OCTARRAY_API Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array.cc:2059
@ 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:201
virtual octave_value diag(octave_idx_type k=0) const
Definition: ov-base.cc:1036
bool isnumeric(void) const
Definition: ov-perm.h:126
octave_value all(int dim=0) const
Definition: ov-perm.h:90
bool is_matrix_type(void) const
Definition: ov-perm.h:124
octave_idx_type nnz(void) const
Definition: ov-perm.h:79
bool is_double_type(void) const
Definition: ov-perm.h:136
octave_value squeeze(void) const
Definition: ov-perm.h:58
bool is_perm_matrix(void) const
Definition: ov-perm.h:122
double scalar_value(bool frc_str_conv=false) const
Definition: ov-perm.h:146
int8NDArray int8_array_value(void) const
Definition: ov-perm.h:185
octave_base_value * clone(void) const
Definition: ov-perm.h:47
dim_vector dims(void) const
Definition: ov-perm.h:77
PermMatrix m_matrix
Definition: ov-perm.h:260
octave_value diag(octave_idx_type k=0) const
Definition: ov-perm.h:102
int64NDArray int64_array_value(void) const
Definition: ov-perm.h:194
int16NDArray int16_array_value(void) const
Definition: ov-perm.h:188
MatrixType matrix_type(const MatrixType &) const
Definition: ov-perm.h:94
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 isfloat(void) const
Definition: ov-perm.h:138
octave_base_value * empty_clone(void) const
Definition: ov-perm.h:49
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-perm.h:107
int32NDArray int32_array_value(void) const
Definition: ov-perm.h:191
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-perm.h:117
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(void) const
Definition: ov-perm.h:197
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-perm.h:105
PermMatrix perm_matrix_value(void) const
Definition: ov-perm.h:151
bool is_constant(void) const
Definition: ov-perm.h:130
std::size_t byte_size(void) const
Definition: ov-perm.h:56
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-perm.h:84
octave_perm_matrix(void)
Definition: ov-perm.h:43
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
builtin_type_t builtin_type(void) const
Definition: ov-perm.h:120
uint64NDArray uint64_array_value(void) const
Definition: ov-perm.h:206
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-perm.h:114
MatrixType matrix_type(void) const
Definition: ov-perm.h:93
octave_value full_value(void) const
Definition: ov-perm.h:60
uint32NDArray uint32_array_value(void) const
Definition: ov-perm.h:203
bool is_real_matrix(void) const
Definition: ov-perm.h:132
octave_perm_matrix(const PermMatrix &p)
Definition: ov-perm.h:45
octave_value m_dense_cache
Definition: ov-perm.h:264
bool isreal(void) const
Definition: ov-perm.h:134
octave_value map(unary_mapper_t umap) const
Definition: ov-perm.h:253
uint16NDArray uint16_array_value(void) const
Definition: ov-perm.h:200
bool is_defined(void) const
Definition: ov-perm.h:128
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:619
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1537
octave_value any(int dim=0) const
Definition: ov.h:732
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:616
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1634
octave_value all(int dim=0) const
Definition: ov.h:729
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:625
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1531
bool is_true(const std::string &s)
static float_display_format get_edit_display_format(const octave_value &val)
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
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:173
builtin_type_t
Definition: ov-base.h:75
@ btyp_double
Definition: ov-base.h:76