GNU Octave  4.4.1
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-2018 Jaroslav Hajek
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_ov_perm_h)
24 #define octave_ov_perm_h 1
25 
26 #include "octave-config.h"
27 
28 #include "mx-base.h"
29 #include "str-vec.h"
30 
31 #include "ov-base.h"
32 #include "ov-typeinfo.h"
33 #include "ovl.h"
34 
35 class
36 OCTINTERP_API
38 {
39 public:
40  octave_perm_matrix (void) : matrix (), dense_cache () { }
41 
42  octave_perm_matrix (const PermMatrix& p) : matrix (p), dense_cache () { }
43 
44  octave_base_value * clone (void) const
45  { return new octave_perm_matrix (*this); }
47  { return new octave_perm_matrix (); }
48 
49  type_conv_info numeric_conversion_function (void) const;
50 
51  octave_base_value * try_narrowing_conversion (void);
52 
53  size_t byte_size (void) const { return matrix.byte_size (); }
54 
55  octave_value squeeze (void) const { return matrix; }
56 
57  octave_value full_value (void) const { return to_dense (); }
58 
60  const std::list<octave_value_list>& idx);
61 
63  const std::list<octave_value_list>& idx, int)
64  { return subsref (type, idx); }
65 
66  octave_value do_index_op (const octave_value_list& idx,
67  bool resize_ok = false);
68 
69  dim_vector dims (void) const { return matrix.dims (); }
70 
71  octave_idx_type nnz (void) const { return matrix.rows (); }
72 
73  octave_value reshape (const dim_vector& new_dims) const
74  { return to_dense ().reshape (new_dims); }
75 
76  octave_value permute (const Array<int>& vec, bool inv = false) const
77  { return to_dense ().permute (vec, inv); }
78 
79  octave_value resize (const dim_vector& dv, bool fill = false) const
80  { return to_dense ().resize (dv, fill); }
81 
82  octave_value all (int dim = 0) const { return to_dense ().all (dim); }
83  octave_value any (int dim = 0) const { return to_dense ().any (dim); }
84 
87  { return matrix_type (); }
88 
90  { return to_dense () .diag (k); }
91 
93  { return to_dense ().sort (dim, mode); }
95  sortmode mode = ASCENDING) const
96  { return to_dense ().sort (sidx, dim, mode); }
97 
99  { return to_dense ().issorted (mode); }
100 
102  { return to_dense ().sort_rows_idx (mode); }
103 
105  { return to_dense ().is_sorted_rows (mode); }
106 
107  builtin_type_t builtin_type (void) const { return btyp_double; }
108 
109  bool is_perm_matrix (void) const { return true; }
110 
111  bool is_matrix_type (void) const { return true; }
112 
113  bool isnumeric (void) const { return true; }
114 
115  bool is_defined (void) const { return true; }
116 
117  bool is_constant (void) const { return true; }
118 
119  bool is_real_matrix (void) const { return true; }
120 
121  bool isreal (void) const { return true; }
122 
123  bool is_double_type (void) const { return true; }
124 
125  bool isfloat (void) const { return true; }
126 
127  bool is_true (void) const;
128 
129  double double_value (bool = false) const;
130 
131  float float_value (bool = false) const;
132 
133  double scalar_value (bool frc_str_conv = false) const
134  { return double_value (frc_str_conv); }
135 
136  idx_vector index_vector (bool require_integers = false) const;
137 
139  { return matrix; }
140 
141  Matrix matrix_value (bool = false) const;
142 
143  FloatMatrix float_matrix_value (bool = false) const;
144 
145  Complex complex_value (bool = false) const;
146 
147  FloatComplex float_complex_value (bool = false) const;
148 
149  ComplexMatrix complex_matrix_value (bool = false) const;
150 
151  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
152 
153  ComplexNDArray complex_array_value (bool = false) const;
154 
155  FloatComplexNDArray float_complex_array_value (bool = false) const;
156 
157  boolNDArray bool_array_value (bool warn = false) const;
158 
159  charNDArray char_array_value (bool = false) const;
160 
161  NDArray array_value (bool = false) const;
162 
163  FloatNDArray float_array_value (bool = false) const;
164 
165  SparseMatrix sparse_matrix_value (bool = false) const;
166 
167  SparseBoolMatrix sparse_bool_matrix_value (bool = false) const;
168 
169  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
170 
172  int8_array_value (void) const { return to_dense ().int8_array_value (); }
173 
175  int16_array_value (void) const { return to_dense ().int16_array_value (); }
176 
178  int32_array_value (void) const { return to_dense ().int32_array_value (); }
179 
181  int64_array_value (void) const { return to_dense ().int64_array_value (); }
182 
184  uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
185 
187  uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
188 
190  uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
191 
193  uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
194 
195  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
196 
197  octave_value as_double (void) const;
198  octave_value as_single (void) const;
199 
200  octave_value as_int8 (void) const;
201  octave_value as_int16 (void) const;
202  octave_value as_int32 (void) const;
203  octave_value as_int64 (void) const;
204 
205  octave_value as_uint8 (void) const;
206  octave_value as_uint16 (void) const;
207  octave_value as_uint32 (void) const;
208  octave_value as_uint64 (void) const;
209 
210  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
211 
213 
214  std::string edit_display (const float_display_format& fmt,
216 
217  bool save_ascii (std::ostream& os);
218 
219  bool load_ascii (std::istream& is);
220 
221  bool save_binary (std::ostream& os, bool& save_as_floats);
222 
223  bool load_binary (std::istream& is, bool swap,
225 
226  int write (octave::stream& os, int block_size,
227  oct_data_conv::data_type output_type, int skip,
229 
230  mxArray * as_mxArray (void) const;
231 
232  bool print_as_scalar (void) const;
233 
234  void print (std::ostream& os, bool pr_as_read_syntax = false);
235 
236  void print_info (std::ostream& os, const std::string& prefix) const;
237 
238  void short_disp (std::ostream& os) const;
239 
241  { return to_dense ().map (umap); }
242 
243  octave_value fast_elem_extract (octave_idx_type n) const;
244 
245 protected:
246 
248 
249  virtual octave_value to_dense (void) const;
250 
252 
253 private:
254 
256 };
257 
258 #endif
octave_value full_value(void) const
Definition: ov-perm.h:57
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1473
uint8NDArray uint8_array_value(void) const
Definition: ov-perm.h:184
PermMatrix perm_matrix_value(void) const
Definition: ov-perm.h:138
bool is_matrix_type(void) const
Definition: ov-perm.h:111
characters Given a string matrix
Definition: hex2num.cc:155
uint32NDArray uint32_array_value(void) const
Definition: ov-perm.h:190
int64NDArray int64_array_value(void) const
Definition: ov-perm.h:181
sortmode
Definition: oct-sort.h:105
bool is_defined(void) const
Definition: ov-perm.h:115
uint64NDArray uint64_array_value(void) const
Definition: ov-perm.h:193
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-perm.h:104
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
idx subsref(val, idx) esult
Definition: ov.cc:3065
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-perm.h:94
bool is_double_type(void) const
Definition: ov-perm.h:123
octave_base_value * empty_clone(void) const
Definition: ov-perm.h:46
for large enough k
Definition: lu.cc:617
octave_value squeeze(void) const
Definition: ov-perm.h:55
octave_value all(int dim=0) const
Definition: ov.h:637
MatrixType matrix_type(const MatrixType &) const
Definition: ov-perm.h:86
double scalar_value(bool frc_str_conv=false) const
Definition: ov-perm.h:133
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array.cc:2068
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-perm.h:76
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-perm.h:92
octave_perm_matrix(const PermMatrix &p)
Definition: ov-perm.h:42
builtin_type_t
Definition: ov-base.h:71
octave_value map(unary_mapper_t umap) const
Definition: ov-perm.h:240
bool isfloat(void) const
Definition: ov-perm.h:125
size_t byte_size(void) const
Definition: ov-perm.h:53
int32NDArray int32_array_value(void) const
Definition: ov-perm.h:178
MatrixType matrix_type(void) const
Definition: ov-perm.h:85
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:511
bool is_perm_matrix(void) const
Definition: ov-perm.h:109
static double as_double(time_t sec, long usec)
Definition: oct-time.h:34
bool swap
Definition: load-save.cc:738
octave_base_value * clone(void) const
Definition: ov-perm.h:44
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1374
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
octave_idx_type nnz(void) const
Definition: ov-perm.h:71
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-perm.h:98
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-perm.h:73
octave_value any(int dim=0) const
Definition: ov.h:640
dim_vector dims(void) const
Definition: ov-perm.h:69
bool save_as_floats
Definition: load-save.cc:1617
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:505
bool is_true(const std::string &s)
octave_value any(int dim=0) const
Definition: ov-perm.h:83
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-perm.h:62
idx type
Definition: ov.cc:3114
Definition: dMatrix.h:36
PermMatrix matrix
Definition: ov-perm.h:247
int8NDArray int8_array_value(void) const
Definition: ov-perm.h:172
octave_value diag(octave_idx_type k=0) const
Definition: ov-perm.h:89
octave_value dense_cache
Definition: ov-perm.h:251
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:502
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1368
bool is_constant(void) const
Definition: ov-perm.h:117
bool isreal(void) const
Definition: ov-perm.h:121
int16NDArray int16_array_value(void) const
Definition: ov-perm.h:175
bool is_real_matrix(void) const
Definition: ov-perm.h:119
p
Definition: lu.cc:138
octave_perm_matrix(void)
Definition: ov-perm.h:40
octave_value all(int dim=0) const
Definition: ov-perm.h:82
builtin_type_t builtin_type(void) const
Definition: ov-perm.h:107
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-perm.h:79
for i
Definition: data.cc:5264
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
std::complex< double > Complex
Definition: oct-cmplx.h:31
write the output to stdout if nargout is
Definition: load-save.cc:1612
bool isnumeric(void) const
Definition: ov-perm.h:113
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-perm.h:101
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
uint16NDArray uint16_array_value(void) const
Definition: ov-perm.h:187
static float_display_format get_edit_display_format(const octave_value &val)