GNU Octave  4.0.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-lazy-idx.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2010-2015 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 "ov-re-mat.h"
27 
28 // Lazy indices that stay in idx_vector form until the conversion to NDArray is
29 // actually needed.
30 
31 class
34 {
35 public:
36 
38  : octave_base_value (), index (), value () { }
39 
41  : octave_base_value (), index (idx), value () { }
42 
44  : octave_base_value (), index (i.index), value (i.value) { }
45 
46  ~octave_lazy_index (void) { }
47 
48  octave_base_value *clone (void) const
49  { return new octave_lazy_index (*this); }
50  octave_base_value *empty_clone (void) const { return new octave_matrix (); }
51 
52  type_conv_info numeric_conversion_function (void) const;
53 
54  octave_base_value *try_narrowing_conversion (void);
55 
56  octave_value fast_elem_extract (octave_idx_type n) const;
57 
58  size_t byte_size (void) const { return numel () * sizeof (octave_idx_type); }
59 
60  octave_value squeeze (void) const;
61 
62  octave_value full_value (void) const { return make_value (); }
63 
64  idx_vector index_vector (bool /* require_integers */ = false) const { return index; }
65 
66  builtin_type_t builtin_type (void) const { return btyp_double; }
67 
68  bool is_real_matrix (void) const { return true; }
69 
70  bool is_real_type (void) const { return true; }
71 
72  bool is_double_type (void) const { return true; }
73 
74  bool is_float_type (void) const { return true; }
75 
76  octave_value subsref (const std::string& type,
77  const std::list<octave_value_list>& idx)
78  { return make_value ().subsref (type, idx); }
79 
80  octave_value_list subsref (const std::string& type,
81  const std::list<octave_value_list>& idx, int)
82  { return subsref (type, idx); }
83 
85  bool resize_ok = false)
86  { return make_value ().do_index_op (idx, resize_ok); }
87 
88  dim_vector dims (void) const { return index.orig_dimensions (); }
89 
90  octave_idx_type numel (void) const { return index.length (0); }
91 
92  octave_idx_type nnz (void) const { return numel (); }
93 
94  octave_value reshape (const dim_vector& new_dims) const;
95 
96  octave_value permute (const Array<int>& vec, bool inv = false) const;
97 
98  octave_value resize (const dim_vector& dv, bool fill = false) const
99  { return make_value ().resize (dv, fill); }
100 
101  octave_value all (int dim = 0) const { return make_value ().all (dim); }
102  octave_value any (int dim = 0) const { return make_value ().any (dim); }
103 
104  MatrixType matrix_type (void) const { return make_value ().matrix_type (); }
105  MatrixType matrix_type (const MatrixType& _typ) const
106  { return make_value ().matrix_type (_typ); }
107 
108  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
109 
111  sortmode mode = ASCENDING) const;
112 
113  sortmode is_sorted (sortmode mode = UNSORTED) const;
114 
115  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
116 
117  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
118 
119  bool is_matrix_type (void) const { return true; }
120 
121  bool is_numeric_type (void) const { return true; }
122 
123  bool is_defined (void) const { return true; }
124 
125  bool is_constant (void) const { return true; }
126 
127  bool is_true (void) const
128  { return make_value ().is_true (); }
129 
130  bool print_as_scalar (void) const
131  { return make_value ().print_as_scalar (); }
132 
133  void print (std::ostream& os, bool pr_as_read_syntax = false)
134  { make_value ().print (os, pr_as_read_syntax); }
135 
136  void print_info (std::ostream& os, const std::string& prefix) const
137  { make_value ().print_info (os, prefix); }
138 
139 #define FORWARD_VALUE_QUERY(TYPE,NAME) \
140  TYPE \
141  NAME (void) const { return make_value ().NAME (); }
142 
143  FORWARD_VALUE_QUERY (int8NDArray, int8_array_value)
144  FORWARD_VALUE_QUERY (int16NDArray, int16_array_value)
145  FORWARD_VALUE_QUERY (int32NDArray, int32_array_value)
146  FORWARD_VALUE_QUERY (int64NDArray, int64_array_value)
147  FORWARD_VALUE_QUERY (uint8NDArray, uint8_array_value)
148  FORWARD_VALUE_QUERY (uint16NDArray, uint16_array_value)
149  FORWARD_VALUE_QUERY (uint32NDArray, uint32_array_value)
150  FORWARD_VALUE_QUERY (uint64NDArray, uint64_array_value)
151 
152 #define FORWARD_VALUE_QUERY1(TYPE,NAME) \
153  TYPE \
154  NAME (bool flag = false) const { return make_value ().NAME (flag); }
155 
156  FORWARD_VALUE_QUERY1 (double, double_value)
157 
158  FORWARD_VALUE_QUERY1 (float, float_value)
159 
160  FORWARD_VALUE_QUERY1 (double, scalar_value)
161 
162  FORWARD_VALUE_QUERY1 (Matrix, matrix_value)
163 
164  FORWARD_VALUE_QUERY1 (FloatMatrix, float_matrix_value)
165 
166  FORWARD_VALUE_QUERY1 (Complex, complex_value)
167 
168  FORWARD_VALUE_QUERY1 (FloatComplex, float_complex_value)
169 
170  FORWARD_VALUE_QUERY1 (ComplexMatrix, complex_matrix_value)
171 
172  FORWARD_VALUE_QUERY1 (FloatComplexMatrix, float_complex_matrix_value)
173 
174  FORWARD_VALUE_QUERY1 (ComplexNDArray, complex_array_value)
175 
176  FORWARD_VALUE_QUERY1 (FloatComplexNDArray, float_complex_array_value)
177 
178  FORWARD_VALUE_QUERY1 (boolNDArray, bool_array_value)
179 
180  FORWARD_VALUE_QUERY1 (charNDArray, char_array_value)
181 
183 
184  FORWARD_VALUE_QUERY1 (FloatNDArray, float_array_value)
185 
186  FORWARD_VALUE_QUERY1 (SparseMatrix, sparse_matrix_value)
187 
188  FORWARD_VALUE_QUERY1 (SparseComplexMatrix, sparse_complex_matrix_value)
189 
190  octave_value diag (octave_idx_type k = 0) const
191  { return make_value ().diag (k); }
192 
193  octave_value convert_to_str_internal (bool pad, bool force, char type) const
194  { return make_value ().convert_to_str_internal (pad, force, type); }
195 
196  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
197  { return make_value ().print_raw (os, pr_as_read_syntax); }
198 
199  bool save_ascii (std::ostream& os);
200 
201  bool load_ascii (std::istream& is);
202 
203  bool save_binary (std::ostream& os, bool& save_as_floats);
204 
205  bool load_binary (std::istream& is, bool swap,
207 
208 
209  int write (octave_stream& os, int block_size,
210  oct_data_conv::data_type output_type, int skip,
211  oct_mach_info::float_format flt_fmt) const
212  { return make_value ().write (os, block_size, output_type, skip, flt_fmt); }
213 
214  // Unsafe. This function exists to support the MEX interface.
215  // You should not use it anywhere else.
216  void *mex_get_data (void) const
217  { return make_value ().mex_get_data (); }
218 
219  mxArray *as_mxArray (void) const
220  { return make_value ().as_mxArray (); }
221 
223  { return make_value ().map (umap); }
224 
225 private:
226  const octave_value& make_value (void) const
227  {
228  if (value.is_undefined ())
229  value = octave_value (index, false);
230 
231  return value;
232  }
233 
235  {
236  if (value.is_undefined ())
237  value = octave_value (index, false);
238 
239  return value;
240  }
241 
244 
245  static octave_base_value *
246  numeric_conversion_function (const octave_base_value&);
247 
249 };
250 
251 #endif
octave_value value
Definition: ov-lazy-idx.h:243
bool is_numeric_type(void) const
Definition: ov-lazy-idx.h:121
bool is_matrix_type(void) const
Definition: ov-lazy-idx.h:119
octave_lazy_index(const idx_vector &idx)
Definition: ov-lazy-idx.h:40
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:401
void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition: ov-lazy-idx.h:133
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-lazy-idx.h:80
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-lazy-idx.h:196
octave_value & make_value(void)
Definition: ov-lazy-idx.h:234
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-lazy-idx.h:84
sortmode
Definition: oct-sort.h:103
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov-lazy-idx.h:193
octave_base_value * clone(void) const
Definition: ov-lazy-idx.h:48
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1126
mxArray * as_mxArray(void) const
Definition: ov-lazy-idx.h:219
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1226
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:507
bool is_real_type(void) const
Definition: ov-lazy-idx.h:70
octave_value any(int dim=0) const
Definition: ov-lazy-idx.h:102
octave_lazy_index(void)
Definition: ov-lazy-idx.h:37
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov.h:1022
bool is_constant(void) const
Definition: ov-lazy-idx.h:125
builtin_type_t
Definition: ov-base.h:59
bool is_float_type(void) const
Definition: ov-lazy-idx.h:74
#define FORWARD_VALUE_QUERY1(TYPE, NAME)
Definition: ov-lazy-idx.h:152
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-lazy-idx.h:98
MatrixType matrix_type(void) const
Definition: ov-lazy-idx.h:104
void * mex_get_data(void) const
Definition: ov-lazy-idx.h:216
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
octave_value any(int dim=0) const
Definition: ov.h:600
octave_lazy_index(const octave_lazy_index &i)
Definition: ov-lazy-idx.h:43
#define OCTINTERP_API
Definition: mexproto.h:66
idx_vector index_vector(bool=false) const
Definition: ov-lazy-idx.h:64
bool is_true(void) const
Definition: ov-lazy-idx.h:127
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
Definition: ov-lazy-idx.h:209
const octave_value & make_value(void) const
Definition: ov-lazy-idx.h:226
~octave_lazy_index(void)
Definition: ov-lazy-idx.h:46
idx_vector index
Definition: ov-lazy-idx.h:242
#define FORWARD_VALUE_QUERY(TYPE, NAME)
Definition: ov-lazy-idx.h:139
bool is_defined(void) const
Definition: ov-lazy-idx.h:123
bool is_double_type(void) const
Definition: ov-lazy-idx.h:72
Definition: dMatrix.h:35
octave_value all(int dim=0) const
Definition: ov.h:597
octave_value full_value(void) const
Definition: ov-lazy-idx.h:62
bool print_as_scalar(void) const
Definition: ov-lazy-idx.h:130
octave_idx_type numel(void) const
Definition: ov-lazy-idx.h:90
bool is_real_matrix(void) const
Definition: ov-lazy-idx.h:68
Handles the reference counting for all the derived classes.
Definition: Array.h:45
octave_value map(unary_mapper_t umap) const
Definition: ov-lazy-idx.h:222
octave_value all(int dim=0) const
Definition: ov-lazy-idx.h:101
octave_idx_type nnz(void) const
Definition: ov-lazy-idx.h:92
octave_base_value * empty_clone(void) const
Definition: ov-lazy-idx.h:50
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
MatrixType matrix_type(const MatrixType &_typ) const
Definition: ov-lazy-idx.h:105
std::complex< double > Complex
Definition: oct-cmplx.h:29
size_t byte_size(void) const
Definition: ov-lazy-idx.h:58
dim_vector dims(void) const
Definition: ov-lazy-idx.h:88
void print_info(std::ostream &os, const std::string &prefix) const
Definition: ov-lazy-idx.h:136
builtin_type_t builtin_type(void) const
Definition: ov-lazy-idx.h:66
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-lazy-idx.h:76
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov.h:438