GNU Octave 7.1.0
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-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_ov_lazy_idx_h)
27#define octave_ov_lazy_idx_h 1
28
29#include "octave-config.h"
30
31#include "ov-re-mat.h"
32
33// Lazy indices that stay in idx_vector form until the conversion to NDArray is
34// actually needed.
35
36class
37OCTINTERP_API
39{
40public:
41
43 : octave_base_value (), m_index (), m_value () { }
44
46 : octave_base_value (), m_index (idx), m_value () { }
47
49 : octave_base_value (), m_index (i.m_index), m_value (i.m_value) { }
50
51 ~octave_lazy_index (void) = default;
52
53 octave_base_value * clone (void) const
54 { return new octave_lazy_index (*this); }
55 octave_base_value * empty_clone (void) const { return new octave_matrix (); }
56
57 type_conv_info numeric_conversion_function (void) const;
58
59 octave_base_value * try_narrowing_conversion (void);
60
61 octave_value fast_elem_extract (octave_idx_type n) const;
62
63 std::size_t byte_size (void) const { return numel () * sizeof (octave_idx_type); }
64
65 octave_value squeeze (void) const;
66
67 octave_value full_value (void) const { return make_value (); }
68
69 octave::idx_vector index_vector (bool /* require_integers */ = false) const
70 { return m_index; }
71
72 builtin_type_t builtin_type (void) const { return btyp_double; }
73
74 bool is_real_matrix (void) const { return true; }
75
76 bool isreal (void) const { return true; }
77
78 bool is_double_type (void) const { return true; }
79
80 bool isfloat (void) const { return true; }
81
82 // We don't need to override all three forms of subsref. The using
83 // declaration will avoid warnings about partially-overloaded virtual
84 // functions.
86
87 octave_value subsref (const std::string& type,
88 const std::list<octave_value_list>& idx)
89 { return make_value ().subsref (type, idx); }
90
91 octave_value_list subsref (const std::string& type,
92 const std::list<octave_value_list>& idx, int)
93 { return subsref (type, idx); }
94
96 bool resize_ok = false)
97 { return make_value ().index_op (idx, resize_ok); }
98
99 dim_vector dims (void) const { return m_index.orig_dimensions (); }
100
101 octave_idx_type numel (void) const { return m_index.length (0); }
102
103 octave_idx_type nnz (void) const { return numel (); }
104
105 octave_value reshape (const dim_vector& new_dims) const;
106
107 octave_value permute (const Array<int>& vec, bool inv = false) const;
108
109 octave_value resize (const dim_vector& dv, bool fill = false) const
110 { return make_value ().resize (dv, fill); }
111
112 octave_value all (int dim = 0) const { return make_value ().all (dim); }
113 octave_value any (int dim = 0) const { return make_value ().any (dim); }
114
115 MatrixType matrix_type (void) const { return make_value ().matrix_type (); }
117 { return make_value ().matrix_type (_typ); }
118
119 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
120
122 sortmode mode = ASCENDING) const;
123
124 sortmode issorted (sortmode mode = UNSORTED) const;
125
126 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
127
128 sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
129
130 bool is_matrix_type (void) const { return true; }
131
132 bool isnumeric (void) const { return true; }
133
134 bool is_defined (void) const { return true; }
135
136 bool is_constant (void) const { return true; }
137
138 bool is_true (void) const
139 { return make_value ().is_true (); }
140
141 bool print_as_scalar (void) const
142 { return make_value ().print_as_scalar (); }
143
144 void print (std::ostream& os, bool pr_as_read_syntax = false)
145 { make_value ().print (os, pr_as_read_syntax); }
146
147 void print_info (std::ostream& os, const std::string& prefix) const
148 { make_value ().print_info (os, prefix); }
149
150#define FORWARD_VALUE_QUERY(TYPE, NAME) \
151 TYPE NAME (void) const \
152 { \
153 return make_value ().NAME (); \
154 }
155
161 FORWARD_VALUE_QUERY (uint16NDArray, uint16_array_value)
162 FORWARD_VALUE_QUERY (uint32NDArray, uint32_array_value)
163 FORWARD_VALUE_QUERY (uint64NDArray, uint64_array_value)
164
165#define FORWARD_VALUE_QUERY1(TYPE, NAME) \
166 TYPE NAME (bool flag = false) const \
167 { \
168 return make_value ().NAME (flag); \
169 }
170
171 FORWARD_VALUE_QUERY1 (double, double_value)
172 FORWARD_VALUE_QUERY1 (float, float_value)
173 FORWARD_VALUE_QUERY1 (double, scalar_value)
175 FORWARD_VALUE_QUERY1 (FloatMatrix, float_matrix_value)
177 FORWARD_VALUE_QUERY1 (FloatComplex, float_complex_value)
178 FORWARD_VALUE_QUERY1 (ComplexMatrix, complex_matrix_value)
179 FORWARD_VALUE_QUERY1 (FloatComplexMatrix, float_complex_matrix_value)
181 FORWARD_VALUE_QUERY1 (FloatComplexNDArray, float_complex_array_value)
186 FORWARD_VALUE_QUERY1 (SparseMatrix, sparse_matrix_value)
187 FORWARD_VALUE_QUERY1 (SparseComplexMatrix, sparse_complex_matrix_value)
188
189 // We don't need to override both forms of the diag method. The using
190 // declaration will avoid warnings about partially-overloaded virtual
191 // functions.
192 using octave_base_value::diag;
193
194 octave_value diag (octave_idx_type k = 0) const
195 {
196 return make_value ().diag (k);
197 }
198
199 octave_value convert_to_str_internal (bool pad, bool force, char type) const
200 {
201 return make_value ().convert_to_str_internal (pad, force, type);
202 }
203
204 octave_value as_double (void) const;
205 octave_value as_single (void) const;
206
207 octave_value as_int8 (void) const;
208 octave_value as_int16 (void) const;
209 octave_value as_int32 (void) const;
210 octave_value as_int64 (void) const;
211
212 octave_value as_uint8 (void) const;
213 octave_value as_uint16 (void) const;
214 octave_value as_uint32 (void) const;
215 octave_value as_uint64 (void) const;
216
217 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
218 {
219 return make_value ().print_raw (os, pr_as_read_syntax);
220 }
221
222 bool save_ascii (std::ostream& os);
223
224 bool load_ascii (std::istream& is);
225
226 bool save_binary (std::ostream& os, bool save_as_floats);
227
228 bool load_binary (std::istream& is, bool swap,
230
231 int write (octave::stream& os, int block_size,
232 oct_data_conv::data_type output_type, int skip,
234 {
235 return make_value ().write (os, block_size, output_type, skip, flt_fmt);
236 }
237
238 // This function exists to support the MEX interface.
239 // You should not use it anywhere else.
240 const void * mex_get_data (void) const
241 {
242 return make_value ().mex_get_data ();
243 }
244
245 mxArray * as_mxArray (bool interleaved) const
246 {
247 return make_value ().as_mxArray (interleaved);
248 }
249
251 {
252 return make_value ().map (umap);
253 }
254
255private:
256
257 const octave_value& make_value (void) const
258 {
259 if (m_value.is_undefined ())
260 m_value = octave_value (m_index, false);
261
262 return m_value;
263 }
264
266 {
267 if (m_value.is_undefined ())
268 m_value = octave_value (m_index, false);
269
270 return m_value;
271 }
272
275
276 static octave_base_value *
278
280};
281
282#endif
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:201
bool print_as_scalar(void) const
Definition: ov-lazy-idx.h:141
octave_value full_value(void) const
Definition: ov-lazy-idx.h:67
octave_idx_type nnz(void) const
Definition: ov-lazy-idx.h:103
mxArray * as_mxArray(bool interleaved) const
Definition: ov-lazy-idx.h:245
bool isnumeric(void) const
Definition: ov-lazy-idx.h:132
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-lazy-idx.h:109
bool is_real_matrix(void) const
Definition: ov-lazy-idx.h:74
bool is_defined(void) const
Definition: ov-lazy-idx.h:134
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-lazy-idx.h:95
octave_lazy_index(void)
Definition: ov-lazy-idx.h:42
bool is_double_type(void) const
Definition: ov-lazy-idx.h:78
static octave_base_value * numeric_conversion_function(const octave_base_value &)
octave_lazy_index(const octave::idx_vector &idx)
Definition: ov-lazy-idx.h:45
dim_vector dims(void) const
Definition: ov-lazy-idx.h:99
const void * mex_get_data(void) const
Definition: ov-lazy-idx.h:240
bool isfloat(void) const
Definition: ov-lazy-idx.h:80
builtin_type_t builtin_type(void) const
Definition: ov-lazy-idx.h:72
octave_base_value * empty_clone(void) const
Definition: ov-lazy-idx.h:55
std::size_t byte_size(void) const
Definition: ov-lazy-idx.h:63
void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition: ov-lazy-idx.h:144
bool is_true(void) const
Definition: ov-lazy-idx.h:138
octave_value m_value
Definition: ov-lazy-idx.h:274
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov-lazy-idx.h:199
bool is_matrix_type(void) const
Definition: ov-lazy-idx.h:130
octave_value all(int dim=0) const
Definition: ov-lazy-idx.h:112
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-lazy-idx.h:91
octave_lazy_index(const octave_lazy_index &i)
Definition: ov-lazy-idx.h:48
octave::idx_vector m_index
Definition: ov-lazy-idx.h:273
octave_idx_type numel(void) const
Definition: ov-lazy-idx.h:101
MatrixType matrix_type(void) const
Definition: ov-lazy-idx.h:115
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-lazy-idx.h:87
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-lazy-idx.h:217
bool isreal(void) const
Definition: ov-lazy-idx.h:76
bool is_constant(void) const
Definition: ov-lazy-idx.h:136
octave_value map(unary_mapper_t umap) const
Definition: ov-lazy-idx.h:250
MatrixType matrix_type(const MatrixType &_typ) const
Definition: ov-lazy-idx.h:116
octave_base_value * clone(void) const
Definition: ov-lazy-idx.h:53
octave_value any(int dim=0) const
Definition: ov-lazy-idx.h:113
void print_info(std::ostream &os, const std::string &prefix) const
Definition: ov-lazy-idx.h:147
octave::idx_vector index_vector(bool=false) const
Definition: ov-lazy-idx.h:69
octave_value & make_value(void)
Definition: ov-lazy-idx.h:265
const octave_value & make_value(void) const
Definition: ov-lazy-idx.h:257
~octave_lazy_index(void)=default
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:231
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov.h:1416
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:525
octave_value index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov.h:550
octave_value any(int dim=0) const
Definition: ov.h:732
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1634
octave_value all(int dim=0) const
Definition: ov.h:729
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:625
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1531
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
sortmode
Definition: oct-sort.h:97
@ UNSORTED
Definition: oct-sort.h:97
@ ASCENDING
Definition: oct-sort.h:97
T::size_type numel(const T &str)
Definition: oct-string.cc:71
static double as_double(OCTAVE_TIME_T sec, long usec)
Definition: oct-time.h:35
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:173
builtin_type_t
Definition: ov-base.h:75
@ btyp_double
Definition: ov-base.h:76
#define FORWARD_VALUE_QUERY(TYPE, NAME)
Definition: ov-lazy-idx.h:150
#define FORWARD_VALUE_QUERY1(TYPE, NAME)
Definition: ov-lazy-idx.h:165