GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-lazy-idx.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2010-2018 VZLU Prague
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_lazy_idx_h)
24 #define octave_ov_lazy_idx_h 1
25 
26 #include "octave-config.h"
27 
28 #include "ov-re-mat.h"
29 
30 // Lazy indices that stay in idx_vector form until the conversion to NDArray is
31 // actually needed.
32 
33 class
34 OCTINTERP_API
36 {
37 public:
38 
40  : octave_base_value (), index (), value () { }
41 
43  : octave_base_value (), index (idx), value () { }
44 
46  : octave_base_value (), index (i.index), value (i.value) { }
47 
48  ~octave_lazy_index (void) = default;
49 
50  octave_base_value * clone (void) const
51  { return new octave_lazy_index (*this); }
52  octave_base_value * empty_clone (void) const { return new octave_matrix (); }
53 
54  type_conv_info numeric_conversion_function (void) const;
55 
56  octave_base_value * try_narrowing_conversion (void);
57 
58  octave_value fast_elem_extract (octave_idx_type n) const;
59 
60  size_t byte_size (void) const { return numel () * sizeof (octave_idx_type); }
61 
62  octave_value squeeze (void) const;
63 
64  octave_value full_value (void) const { return make_value (); }
65 
66  idx_vector index_vector (bool /* require_integers */ = false) const { return index; }
67 
68  builtin_type_t builtin_type (void) const { return btyp_double; }
69 
70  bool is_real_matrix (void) const { return true; }
71 
72  bool isreal (void) const { return true; }
73 
74  bool is_double_type (void) const { return true; }
75 
76  bool isfloat (void) const { return true; }
77 
79  const std::list<octave_value_list>& idx)
80  { return make_value ().subsref (type, idx); }
81 
83  const std::list<octave_value_list>& idx, int)
84  { return subsref (type, idx); }
85 
87  bool resize_ok = false)
88  { return make_value ().do_index_op (idx, resize_ok); }
89 
90  dim_vector dims (void) const { return index.orig_dimensions (); }
91 
92  octave_idx_type numel (void) const { return index.length (0); }
93 
94  octave_idx_type nnz (void) const { return numel (); }
95 
96  octave_value reshape (const dim_vector& new_dims) const;
97 
98  octave_value permute (const Array<int>& vec, bool inv = false) const;
99 
100  octave_value resize (const dim_vector& dv, bool fill = false) const
101  { return make_value ().resize (dv, fill); }
102 
103  octave_value all (int dim = 0) const { return make_value ().all (dim); }
104  octave_value any (int dim = 0) const { return make_value ().any (dim); }
105 
106  MatrixType matrix_type (void) const { return make_value ().matrix_type (); }
107  MatrixType matrix_type (const MatrixType& _typ) const
108  { return make_value ().matrix_type (_typ); }
109 
110  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
111 
113  sortmode mode = ASCENDING) const;
114 
115  sortmode issorted (sortmode mode = UNSORTED) const;
116 
117  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
118 
119  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
120 
121  bool is_matrix_type (void) const { return true; }
122 
123  bool isnumeric (void) const { return true; }
124 
125  bool is_defined (void) const { return true; }
126 
127  bool is_constant (void) const { return true; }
128 
129  bool is_true (void) const
130  { return make_value ().is_true (); }
131 
132  bool print_as_scalar (void) const
133  { return make_value ().print_as_scalar (); }
134 
135  void print (std::ostream& os, bool pr_as_read_syntax = false)
136  { make_value ().print (os, pr_as_read_syntax); }
137 
138  void print_info (std::ostream& os, const std::string& prefix) const
139  { make_value ().print_info (os, prefix); }
140 
141 #define FORWARD_VALUE_QUERY(TYPE, NAME) \
142  TYPE NAME (void) const \
143  { \
144  return make_value ().NAME (); \
145  }
146 
147  FORWARD_VALUE_QUERY (int8NDArray, int8_array_value)
148  FORWARD_VALUE_QUERY (int16NDArray, int16_array_value)
149  FORWARD_VALUE_QUERY (int32NDArray, int32_array_value)
150  FORWARD_VALUE_QUERY (int64NDArray, int64_array_value)
151  FORWARD_VALUE_QUERY (uint8NDArray, uint8_array_value)
152  FORWARD_VALUE_QUERY (uint16NDArray, uint16_array_value)
153  FORWARD_VALUE_QUERY (uint32NDArray, uint32_array_value)
154  FORWARD_VALUE_QUERY (uint64NDArray, uint64_array_value)
155 
156 #define FORWARD_VALUE_QUERY1(TYPE, NAME) \
157  TYPE NAME (bool flag = false) const \
158  { \
159  return make_value ().NAME (flag); \
160  }
161 
162  FORWARD_VALUE_QUERY1 (double, double_value)
163  FORWARD_VALUE_QUERY1 (float, float_value)
164  FORWARD_VALUE_QUERY1 (double, scalar_value)
165  FORWARD_VALUE_QUERY1 (Matrix, matrix_value)
166  FORWARD_VALUE_QUERY1 (FloatMatrix, float_matrix_value)
167  FORWARD_VALUE_QUERY1 (Complex, complex_value)
168  FORWARD_VALUE_QUERY1 (FloatComplex, float_complex_value)
169  FORWARD_VALUE_QUERY1 (ComplexMatrix, complex_matrix_value)
170  FORWARD_VALUE_QUERY1 (FloatComplexMatrix, float_complex_matrix_value)
171  FORWARD_VALUE_QUERY1 (ComplexNDArray, complex_array_value)
172  FORWARD_VALUE_QUERY1 (FloatComplexNDArray, float_complex_array_value)
173  FORWARD_VALUE_QUERY1 (boolNDArray, bool_array_value)
174  FORWARD_VALUE_QUERY1 (charNDArray, char_array_value)
176  FORWARD_VALUE_QUERY1 (FloatNDArray, float_array_value)
177  FORWARD_VALUE_QUERY1 (SparseMatrix, sparse_matrix_value)
178  FORWARD_VALUE_QUERY1 (SparseComplexMatrix, sparse_complex_matrix_value)
179 
180  octave_value diag (octave_idx_type k = 0) const
181  {
182  return make_value ().diag (k);
183  }
184 
185  octave_value convert_to_str_internal (bool pad, bool force, char type) const
186  {
187  return make_value ().convert_to_str_internal (pad, force, type);
188  }
189 
190  octave_value as_double (void) const;
191  octave_value as_single (void) const;
192 
193  octave_value as_int8 (void) const;
194  octave_value as_int16 (void) const;
195  octave_value as_int32 (void) const;
196  octave_value as_int64 (void) const;
197 
198  octave_value as_uint8 (void) const;
199  octave_value as_uint16 (void) const;
200  octave_value as_uint32 (void) const;
201  octave_value as_uint64 (void) const;
202 
203  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
204  {
205  return make_value ().print_raw (os, pr_as_read_syntax);
206  }
207 
208  bool save_ascii (std::ostream& os);
209 
210  bool load_ascii (std::istream& is);
211 
212  bool save_binary (std::ostream& os, bool& save_as_floats);
213 
214  bool load_binary (std::istream& is, bool swap,
216 
217  int write (octave::stream& os, int block_size,
218  oct_data_conv::data_type output_type, int skip,
220  {
221  return make_value ().write (os, block_size, output_type, skip, flt_fmt);
222  }
223 
224  // Unsafe. This function exists to support the MEX interface.
225  // You should not use it anywhere else.
226  void * mex_get_data (void) const
227  {
228  return make_value ().mex_get_data ();
229  }
230 
231  mxArray * as_mxArray (void) const
232  {
233  return make_value ().as_mxArray ();
234  }
235 
237  {
238  return make_value ().map (umap);
239  }
240 
241 private:
242 
243  const octave_value& make_value (void) const
244  {
245  if (value.is_undefined ())
246  value = octave_value (index, false);
247 
248  return value;
249  }
250 
252  {
253  if (value.is_undefined ())
254  value = octave_value (index, false);
255 
256  return value;
257  }
258 
261 
262  static octave_base_value *
263  numeric_conversion_function (const octave_base_value&);
264 
266 };
267 
268 #endif
octave_value value
Definition: ov-lazy-idx.h:260
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1473
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-lazy-idx.h:203
octave_lazy_index(const idx_vector &idx)
Definition: ov-lazy-idx.h:42
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:418
void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition: ov-lazy-idx.h:135
MatrixType matrix_type(void) const
Definition: ov-lazy-idx.h:106
bool isfloat(void) const
Definition: ov-lazy-idx.h:76
octave_base_value * clone(void) const
Definition: ov-lazy-idx.h:50
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-lazy-idx.h:82
bool print_as_scalar(void) const
Definition: ov-lazy-idx.h:132
bool isnumeric(void) const
Definition: ov-lazy-idx.h:123
octave_value & make_value(void)
Definition: ov-lazy-idx.h:251
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-lazy-idx.h:86
sortmode
Definition: oct-sort.h:105
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
const octave_value & make_value(void) const
Definition: ov-lazy-idx.h:243
idx subsref(val, idx) esult
Definition: ov.cc:3065
dim_vector dims(void) const
Definition: ov-lazy-idx.h:90
for large enough k
Definition: lu.cc:617
octave_value full_value(void) const
Definition: ov-lazy-idx.h:64
octave_value all(int dim=0) const
Definition: ov.h:637
mxArray * as_mxArray(void) const
Definition: ov-lazy-idx.h:231
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
bool is_defined(void) const
Definition: ov-lazy-idx.h:125
octave_lazy_index(void)
Definition: ov-lazy-idx.h:39
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov-lazy-idx.h:185
builtin_type_t
Definition: ov-base.h:71
#define FORWARD_VALUE_QUERY1(TYPE, NAME)
Definition: ov-lazy-idx.h:156
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:511
static double as_double(time_t sec, long usec)
Definition: oct-time.h:34
bool swap
Definition: load-save.cc:738
builtin_type_t builtin_type(void) const
Definition: ov-lazy-idx.h:68
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-lazy-idx.h:100
size_t byte_size(void) const
Definition: ov-lazy-idx.h:60
octave_value all(int dim=0) const
Definition: ov-lazy-idx.h:103
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
void * mex_get_data(void) const
Definition: ov-lazy-idx.h:226
octave_lazy_index(const octave_lazy_index &i)
Definition: ov-lazy-idx.h:45
bool is_true(void) const
Definition: ov-lazy-idx.h:129
octave_value any(int dim=0) const
Definition: ov.h:640
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov.h:1256
bool save_as_floats
Definition: load-save.cc:1617
bool is_double_type(void) const
Definition: ov-lazy-idx.h:74
idx_vector index
Definition: ov-lazy-idx.h:259
bool is_real_matrix(void) const
Definition: ov-lazy-idx.h:70
#define FORWARD_VALUE_QUERY(TYPE, NAME)
Definition: ov-lazy-idx.h:141
idx type
Definition: ov.cc:3114
Definition: dMatrix.h:36
octave_value map(unary_mapper_t umap) const
Definition: ov-lazy-idx.h:236
octave_base_value * empty_clone(void) const
Definition: ov-lazy-idx.h:52
bool is_matrix_type(void) const
Definition: ov-lazy-idx.h:121
octave_idx_type numel(void) const
Definition: ov-lazy-idx.h:92
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1368
T::size_type numel(const T &str)
Definition: oct-string.cc:61
MatrixType matrix_type(const MatrixType &_typ) const
Definition: ov-lazy-idx.h:107
idx_vector index_vector(bool=false) const
Definition: ov-lazy-idx.h:66
void print_info(std::ostream &os, const std::string &prefix) const
Definition: ov-lazy-idx.h:138
bool is_constant(void) const
Definition: ov-lazy-idx.h:127
for i
Definition: data.cc:5264
octave_value any(int dim=0) const
Definition: ov-lazy-idx.h:104
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
octave_idx_type nnz(void) const
Definition: ov-lazy-idx.h:94
std::complex< double > Complex
Definition: oct-cmplx.h:31
write the output to stdout if nargout is
Definition: load-save.cc:1612
bool isreal(void) const
Definition: ov-lazy-idx.h:72
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
nd group nd example For each display the value
Definition: sysdep.cc:866
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
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
Definition: ov-lazy-idx.h:217
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-lazy-idx.h:78
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov.h:444