GNU Octave  4.2.1
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-lazy-idx.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2010-2017 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 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_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
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) { }
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 is_real_type (void) const { return true; }
73 
74  bool is_double_type (void) const { return true; }
75 
76  bool is_float_type (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 is_sorted (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 is_numeric_type (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  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
191  {
192  return make_value ().print_raw (os, pr_as_read_syntax);
193  }
194 
195  bool save_ascii (std::ostream& os);
196 
197  bool load_ascii (std::istream& is);
198 
199  bool save_binary (std::ostream& os, bool& save_as_floats);
200 
201  bool load_binary (std::istream& is, bool swap,
203 
204  int write (octave_stream& os, int block_size,
205  oct_data_conv::data_type output_type, int skip,
207  {
208  return make_value ().write (os, block_size, output_type, skip, flt_fmt);
209  }
210 
211  // Unsafe. This function exists to support the MEX interface.
212  // You should not use it anywhere else.
213  void *mex_get_data (void) const
214  {
215  return make_value ().mex_get_data ();
216  }
217 
218  mxArray *as_mxArray (void) const
219  {
220  return make_value ().as_mxArray ();
221  }
222 
224  {
225  return make_value ().map (umap);
226  }
227 
228 private:
229 
230  const octave_value& make_value (void) const
231  {
232  if (value.is_undefined ())
233  value = octave_value (index, false);
234 
235  return value;
236  }
237 
239  {
240  if (value.is_undefined ())
241  value = octave_value (index, false);
242 
243  return value;
244  }
245 
248 
249  static octave_base_value *
250  numeric_conversion_function (const octave_base_value&);
251 
253 };
254 
255 #endif
octave_value value
Definition: ov-lazy-idx.h:247
bool is_numeric_type(void) const
Definition: ov-lazy-idx.h:123
bool is_matrix_type(void) const
Definition: ov-lazy-idx.h:121
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:417
void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition: ov-lazy-idx.h:135
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-lazy-idx.h:82
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-lazy-idx.h:190
octave_value & make_value(void)
Definition: ov-lazy-idx.h:238
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
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov-lazy-idx.h:185
octave_base_value * clone(void) const
Definition: ov-lazy-idx.h:50
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:6386
idx subsref(val, idx) esult
Definition: ov.cc:3080
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1311
for large enough k
Definition: lu.cc:606
mxArray * as_mxArray(void) const
Definition: ov-lazy-idx.h:218
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1413
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:524
bool is_real_type(void) const
Definition: ov-lazy-idx.h:72
octave_value any(int dim=0) const
Definition: ov-lazy-idx.h:104
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.h:1207
bool is_constant(void) const
Definition: ov-lazy-idx.h:127
builtin_type_t
Definition: ov-base.h:61
bool is_float_type(void) const
Definition: ov-lazy-idx.h:76
#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-lazy-idx.h:100
bool swap
Definition: load-save.cc:725
MatrixType matrix_type(void) const
Definition: ov-lazy-idx.h:106
void * mex_get_data(void) const
Definition: ov-lazy-idx.h:213
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:148
octave_value any(int dim=0) const
Definition: ov.h:616
octave_lazy_index(const octave_lazy_index &i)
Definition: ov-lazy-idx.h:45
#define OCTINTERP_API
Definition: mexproto.h:69
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:204
idx_vector index_vector(bool=false) const
Definition: ov-lazy-idx.h:66
bool is_true(void) const
Definition: ov-lazy-idx.h:129
const octave_value & make_value(void) const
Definition: ov-lazy-idx.h:230
bool save_as_floats
Definition: load-save.cc:1581
~octave_lazy_index(void)
Definition: ov-lazy-idx.h:48
idx_vector index
Definition: ov-lazy-idx.h:246
#define FORWARD_VALUE_QUERY(TYPE, NAME)
Definition: ov-lazy-idx.h:141
bool is_defined(void) const
Definition: ov-lazy-idx.h:125
idx type
Definition: ov.cc:3129
bool is_double_type(void) const
Definition: ov-lazy-idx.h:74
Definition: dMatrix.h:37
octave_value all(int dim=0) const
Definition: ov.h:613
octave_value full_value(void) const
Definition: ov-lazy-idx.h:64
bool print_as_scalar(void) const
Definition: ov-lazy-idx.h:132
octave_idx_type numel(void) const
Definition: ov-lazy-idx.h:92
bool is_real_matrix(void) const
Definition: ov-lazy-idx.h:70
octave_value map(unary_mapper_t umap) const
Definition: ov-lazy-idx.h:223
octave_value all(int dim=0) const
Definition: ov-lazy-idx.h:103
T::size_type numel(const T &str)
Definition: oct-string.cc:61
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_idx_type nnz(void) const
Definition: ov-lazy-idx.h:94
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
octave_base_value * empty_clone(void) const
Definition: ov-lazy-idx.h:52
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
MatrixType matrix_type(const MatrixType &_typ) const
Definition: ov-lazy-idx.h:107
std::complex< double > Complex
Definition: oct-cmplx.h:31
size_t byte_size(void) const
Definition: ov-lazy-idx.h:60
write the output to stdout if nargout is
Definition: load-save.cc:1576
dim_vector dims(void) const
Definition: ov-lazy-idx.h:90
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:854
dim_vector dv
Definition: sub2ind.cc:263
void print_info(std::ostream &os, const std::string &prefix) const
Definition: ov-lazy-idx.h:138
builtin_type_t builtin_type(void) const
Definition: ov-lazy-idx.h:68
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:454