GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-perm.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2013 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_ov_perm_h)
24 #define octave_ov_perm_h 1
25 
26 #include "mx-base.h"
27 #include "str-vec.h"
28 
29 #include "ov-base.h"
30 #include "ov-typeinfo.h"
31 #include "oct-obj.h"
32 
33 class
36 {
37 public:
38  octave_perm_matrix (void) : matrix (), dense_cache () { }
39 
40  octave_perm_matrix (const PermMatrix& p) : matrix (p), dense_cache () { }
41 
42  octave_base_value *clone (void) const
43  { return new octave_perm_matrix (*this); }
44  octave_base_value *empty_clone (void) const
45  { return new octave_perm_matrix (); }
46 
47  type_conv_info numeric_conversion_function (void) const;
48 
49  octave_base_value *try_narrowing_conversion (void);
50 
51  size_t byte_size (void) const { return matrix.byte_size (); }
52 
53  octave_value squeeze (void) const { return matrix; }
54 
55  octave_value full_value (void) const { return to_dense (); }
56 
57  octave_value subsref (const std::string& type,
58  const std::list<octave_value_list>& idx);
59 
60  octave_value_list subsref (const std::string& type,
61  const std::list<octave_value_list>& idx, int)
62  { return subsref (type, idx); }
63 
64  octave_value do_index_op (const octave_value_list& idx,
65  bool resize_ok = false);
66 
67  dim_vector dims (void) const { return matrix.dims (); }
68 
69  octave_idx_type nnz (void) const { return matrix.rows (); }
70 
71  octave_value reshape (const dim_vector& new_dims) const
72  { return to_dense ().reshape (new_dims); }
73 
74  octave_value permute (const Array<int>& vec, bool inv = false) const
75  { return to_dense ().permute (vec, inv); }
76 
77  octave_value resize (const dim_vector& dv, bool fill = false) const
78  { return to_dense ().resize (dv, fill); }
79 
80  octave_value all (int dim = 0) const { return to_dense ().all (dim); }
81  octave_value any (int dim = 0) const { return to_dense ().any (dim); }
82 
84  MatrixType matrix_type (const MatrixType&) const
85  { return matrix_type (); }
86 
87  octave_value diag (octave_idx_type k = 0) const
88  { return to_dense () .diag (k); }
89 
90  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
91  { return to_dense ().sort (dim, mode); }
93  sortmode mode = ASCENDING) const
94  { return to_dense ().sort (sidx, dim, mode); }
95 
96  sortmode is_sorted (sortmode mode = UNSORTED) const
97  { return to_dense ().is_sorted (mode); }
98 
99  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
100  { return to_dense ().sort_rows_idx (mode); }
101 
102  sortmode is_sorted_rows (sortmode mode = UNSORTED) const
103  { return to_dense ().is_sorted_rows (mode); }
104 
105  builtin_type_t builtin_type (void) const { return btyp_double; }
106 
107  bool is_perm_matrix (void) const { return true; }
108 
109  bool is_matrix_type (void) const { return true; }
110 
111  bool is_numeric_type (void) const { return true; }
112 
113  bool is_defined (void) const { return true; }
114 
115  bool is_constant (void) const { return true; }
116 
117  bool is_real_matrix (void) const { return true; }
118 
119  bool is_real_type (void) const { return true; }
120 
121  bool is_double_type (void) const { return true; }
122 
123  bool is_float_type (void) const { return true; }
124 
125  bool is_true (void) const;
126 
127  double double_value (bool = false) const;
128 
129  float float_value (bool = false) const;
130 
131  double scalar_value (bool frc_str_conv = false) const
132  { return double_value (frc_str_conv); }
133 
134  idx_vector index_vector (void) const;
135 
136  PermMatrix perm_matrix_value (void) const
137  { return matrix; }
138 
139  Matrix matrix_value (bool = false) const;
140 
141  FloatMatrix float_matrix_value (bool = false) const;
142 
143  Complex complex_value (bool = false) const;
144 
145  FloatComplex float_complex_value (bool = false) const;
146 
147  ComplexMatrix complex_matrix_value (bool = false) const;
148 
149  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
150 
151  ComplexNDArray complex_array_value (bool = false) const;
152 
153  FloatComplexNDArray float_complex_array_value (bool = false) const;
154 
155  boolNDArray bool_array_value (bool warn = false) const;
156 
157  charNDArray char_array_value (bool = false) const;
158 
159  NDArray array_value (bool = false) const;
160 
161  FloatNDArray float_array_value (bool = false) const;
162 
163  SparseMatrix sparse_matrix_value (bool = false) const;
164 
165  SparseBoolMatrix sparse_bool_matrix_value (bool = false) const;
166 
167  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
168 
170  int8_array_value (void) const { return to_dense ().int8_array_value (); }
171 
173  int16_array_value (void) const { return to_dense ().int16_array_value (); }
174 
176  int32_array_value (void) const { return to_dense ().int32_array_value (); }
177 
179  int64_array_value (void) const { return to_dense ().int64_array_value (); }
180 
182  uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
183 
185  uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
186 
188  uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
189 
191  uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
192 
193  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
194 
195  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
196 
197  bool save_ascii (std::ostream& os);
198 
199  bool load_ascii (std::istream& is);
200 
201  bool save_binary (std::ostream& os, bool& save_as_floats);
202 
203  bool load_binary (std::istream& is, bool swap,
205 
206  int write (octave_stream& os, int block_size,
207  oct_data_conv::data_type output_type, int skip,
208  oct_mach_info::float_format flt_fmt) const;
209 
210  mxArray *as_mxArray (void) const;
211 
212  bool print_as_scalar (void) const;
213 
214  void print (std::ostream& os, bool pr_as_read_syntax = false) const;
215 
216  void print_info (std::ostream& os, const std::string& prefix) const;
217 
218  octave_value map (unary_mapper_t umap) const
219  { return to_dense ().map (umap); }
220 
221 protected:
222 
224 
225  virtual octave_value to_dense (void) const;
226 
228 
229 private:
230 
232 
234 };
235 
236 #endif