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-lazy-idx.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2010-2013 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  size_t byte_size (void) const { return numel () * sizeof (octave_idx_type); }
57 
58  octave_value squeeze (void) const;
59 
60  octave_value full_value (void) const { return make_value (); }
61 
62  idx_vector index_vector (void) const
63  { return index; }
64 
65  builtin_type_t builtin_type (void) const { return btyp_double; }
66 
67  bool is_real_matrix (void) const { return true; }
68 
69  bool is_real_type (void) const { return true; }
70 
71  bool is_double_type (void) const { return true; }
72 
73  bool is_float_type (void) const { return true; }
74 
75  octave_value subsref (const std::string& type,
76  const std::list<octave_value_list>& idx)
77  { return make_value ().subsref (type, idx); }
78 
79  octave_value_list subsref (const std::string& type,
80  const std::list<octave_value_list>& idx, int)
81  { return subsref (type, idx); }
82 
83  octave_value do_index_op (const octave_value_list& idx,
84  bool resize_ok = false)
85  { return make_value ().do_index_op (idx, resize_ok); }
86 
87  dim_vector dims (void) const { return index.orig_dimensions (); }
88 
89  octave_idx_type numel (void) const { return index.length (0); }
90 
91  octave_idx_type nnz (void) const { return numel (); }
92 
93  octave_value reshape (const dim_vector& new_dims) const;
94 
95  octave_value permute (const Array<int>& vec, bool inv = false) const;
96 
97  octave_value resize (const dim_vector& dv, bool fill = false) const
98  { return make_value ().resize (dv, fill); }
99 
100  octave_value all (int dim = 0) const { return make_value ().all (dim); }
101  octave_value any (int dim = 0) const { return make_value ().any (dim); }
102 
103  MatrixType matrix_type (void) const { return make_value ().matrix_type (); }
104  MatrixType matrix_type (const MatrixType& _typ) const
105  { return make_value ().matrix_type (_typ); }
106 
107  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
108 
110  sortmode mode = ASCENDING) const;
111 
112  sortmode is_sorted (sortmode mode = UNSORTED) const;
113 
114  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
115 
116  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
117 
118  bool is_matrix_type (void) const { return true; }
119 
120  bool is_numeric_type (void) const { return true; }
121 
122  bool is_defined (void) const { return true; }
123 
124  bool is_constant (void) const { return true; }
125 
126  bool is_true (void) const
127  { return make_value ().is_true (); }
128 
129  bool print_as_scalar (void) const
130  { return make_value ().print_as_scalar (); }
131 
132  void print (std::ostream& os, bool pr_as_read_syntax = false) const
133  { make_value ().print (os, pr_as_read_syntax); }
134 
135  void print_info (std::ostream& os, const std::string& prefix) const
136  { make_value ().print_info (os, prefix); }
137 
138 #define FORWARD_VALUE_QUERY(TYPE,NAME) \
139  TYPE \
140  NAME (void) const { return make_value ().NAME (); }
141 
142  FORWARD_VALUE_QUERY (int8NDArray, int8_array_value)
143  FORWARD_VALUE_QUERY (int16NDArray, int16_array_value)
144  FORWARD_VALUE_QUERY (int32NDArray, int32_array_value)
145  FORWARD_VALUE_QUERY (int64NDArray, int64_array_value)
146  FORWARD_VALUE_QUERY (uint8NDArray, uint8_array_value)
147  FORWARD_VALUE_QUERY (uint16NDArray, uint16_array_value)
148  FORWARD_VALUE_QUERY (uint32NDArray, uint32_array_value)
149  FORWARD_VALUE_QUERY (uint64NDArray, uint64_array_value)
150 
151 #define FORWARD_VALUE_QUERY1(TYPE,NAME) \
152  TYPE \
153  NAME (bool flag = false) const { return make_value ().NAME (flag); }
154 
155  FORWARD_VALUE_QUERY1 (double, double_value)
156 
157  FORWARD_VALUE_QUERY1 (float, float_value)
158 
159  FORWARD_VALUE_QUERY1 (double, scalar_value)
160 
161  FORWARD_VALUE_QUERY1 (Matrix, matrix_value)
162 
163  FORWARD_VALUE_QUERY1 (FloatMatrix, float_matrix_value)
164 
165  FORWARD_VALUE_QUERY1 (Complex, complex_value)
166 
167  FORWARD_VALUE_QUERY1 (FloatComplex, float_complex_value)
168 
169  FORWARD_VALUE_QUERY1 (ComplexMatrix, complex_matrix_value)
170 
171  FORWARD_VALUE_QUERY1 (FloatComplexMatrix, float_complex_matrix_value)
172 
173  FORWARD_VALUE_QUERY1 (ComplexNDArray, complex_array_value)
174 
175  FORWARD_VALUE_QUERY1 (FloatComplexNDArray, float_complex_array_value)
176 
177  FORWARD_VALUE_QUERY1 (boolNDArray, bool_array_value)
178 
179  FORWARD_VALUE_QUERY1 (charNDArray, char_array_value)
180 
182 
183  FORWARD_VALUE_QUERY1 (FloatNDArray, float_array_value)
184 
185  FORWARD_VALUE_QUERY1 (SparseMatrix, sparse_matrix_value)
186 
187  FORWARD_VALUE_QUERY1 (SparseComplexMatrix, sparse_complex_matrix_value)
188 
189  octave_value diag (octave_idx_type k = 0) const
190  { return make_value ().diag (k); }
191 
192  octave_value convert_to_str_internal (bool pad, bool force, char type) const
193  { return make_value ().convert_to_str_internal (pad, force, type); }
194 
195  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
196  { return make_value ().print_raw (os, pr_as_read_syntax); }
197 
198  bool save_ascii (std::ostream& os);
199 
200  bool load_ascii (std::istream& is);
201 
202  bool save_binary (std::ostream& os, bool& save_as_floats);
203 
204  bool load_binary (std::istream& is, bool swap,
206 
207  // HDF5 functions not defined.
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 
222  octave_value map (unary_mapper_t umap) const
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 
234  octave_value& make_value (void)
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
252