Mercurial > octave
comparison libinterp/octave-value/ov-range.h @ 28646:e26201931ea3
new template class for octave_range objects
* ov-range.h, ov-range.cc (class octave_range): Convert to template.
For now, use specializations to preserve existing behavior for
double-precision ranges. Change all uses.
* ov.h, ov.cc: Update range constructors to create range objects for
integer and float ranges. Provide value extractor functions for
range<T> types that forward to virtual functions in the
octave_base_value class.
* ov-base.cc: Provide virtual value extractor functions for range<T>
types.
* ov-range-traits.h: New file.
* libinterp/octave-value/module.mk: Update.
* Range.h, Range.cc (Range::Range): Deprecate public constructors.
* pt-eval.h, pt-eval.cc (tree_evaluator::execute_range_loop):
New template function.
(tree_evaluator::visit_simple_for_command): Use it to handle looping
when the loop variable expression is a range.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 12 Aug 2020 12:14:17 -0400 |
parents | 7ebe185e3818 |
children | 853e60367cb6 |
comparison
equal
deleted
inserted
replaced
28645:175eedccc085 | 28646:e26201931ea3 |
---|---|
41 #include "str-vec.h" | 41 #include "str-vec.h" |
42 | 42 |
43 #include "error.h" | 43 #include "error.h" |
44 #include "oct-stream.h" | 44 #include "oct-stream.h" |
45 #include "ov-base.h" | 45 #include "ov-base.h" |
46 #include "ov-range-traits.h" | |
46 #include "ov-re-mat.h" | 47 #include "ov-re-mat.h" |
47 #include "ov-typeinfo.h" | 48 #include "ov-typeinfo.h" |
48 | 49 |
49 class octave_value_list; | 50 class octave_value_list; |
50 | 51 |
51 // Range values. | 52 // Range values. |
52 | 53 |
53 template <typename T> | 54 template <typename T> |
54 octave::range<double> | |
55 make_double_range (const octave::range<T>& r) | |
56 { | |
57 return octave::range<double> (static_cast<double> (r.base ()), | |
58 static_cast<double> (r.increment ()), | |
59 static_cast<double> (r.limit ()), | |
60 static_cast<double> (r.final_value ()), | |
61 r.numel ()); | |
62 } | |
63 | |
64 class | 55 class |
65 octave_range : public octave_base_value | 56 ov_range : public octave_base_value |
66 { | 57 { |
67 public: | 58 public: |
68 | 59 |
69 octave_range (void) | 60 ov_range (void) |
70 : octave_base_value (), m_range (), m_idx_cache () { } | 61 : octave_base_value (), m_range (), m_idx_cache () { } |
71 | 62 |
72 octave_range (const octave::range<float>& r) | 63 ov_range (const octave::range<T>& r) |
73 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | 64 : octave_base_value (), m_range (r), m_idx_cache () |
74 { | 65 { |
75 if (numel () < 0 && numel () != -2) | 66 if (numel () < 0 && numel () != -2) |
76 error ("invalid range"); | 67 error ("invalid range"); |
77 } | 68 } |
78 | 69 |
79 octave_range (const octave::range<double>& r) | 70 ov_range (const ov_range<T>& r) |
80 : octave_base_value (), m_range (r), m_idx_cache () | |
81 { | |
82 if (numel () < 0 && numel () != -2) | |
83 error ("invalid range"); | |
84 } | |
85 | |
86 octave_range (const octave::range<octave_int8>& r) | |
87 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
88 { | |
89 if (numel () < 0 && numel () != -2) | |
90 error ("invalid range"); | |
91 } | |
92 | |
93 octave_range (const octave::range<octave_int16>& r) | |
94 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
95 { | |
96 if (numel () < 0 && numel () != -2) | |
97 error ("invalid range"); | |
98 } | |
99 | |
100 octave_range (const octave::range<octave_int32>& r) | |
101 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
102 { | |
103 if (numel () < 0 && numel () != -2) | |
104 error ("invalid range"); | |
105 } | |
106 | |
107 octave_range (const octave::range<octave_int64>& r) | |
108 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
109 { | |
110 if (numel () < 0 && numel () != -2) | |
111 error ("invalid range"); | |
112 } | |
113 | |
114 octave_range (const octave::range<octave_uint8>& r) | |
115 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
116 { | |
117 if (numel () < 0 && numel () != -2) | |
118 error ("invalid range"); | |
119 } | |
120 | |
121 octave_range (const octave::range<octave_uint16>& r) | |
122 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
123 { | |
124 if (numel () < 0 && numel () != -2) | |
125 error ("invalid range"); | |
126 } | |
127 | |
128 octave_range (const octave::range<octave_uint32>& r) | |
129 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
130 { | |
131 if (numel () < 0 && numel () != -2) | |
132 error ("invalid range"); | |
133 } | |
134 | |
135 octave_range (const octave::range<octave_uint64>& r) | |
136 : octave_base_value (), m_range (make_double_range (r)), m_idx_cache () | |
137 { | |
138 if (numel () < 0 && numel () != -2) | |
139 error ("invalid range"); | |
140 } | |
141 | |
142 octave_range (double base, double limit, double increment) | |
143 : octave_base_value (), m_range (base, limit, increment), m_idx_cache () | |
144 { | |
145 if (numel () < 0) | |
146 error ("invalid range"); | |
147 } | |
148 | |
149 octave_range (const Range& r) | |
150 : octave_base_value (), | |
151 m_range (r.base (), r.increment (), r.limit (), r.numel ()), | |
152 m_idx_cache () | |
153 { | |
154 if (numel () < 0 && numel () != -2) | |
155 error ("invalid range"); | |
156 } | |
157 | |
158 octave_range (const octave_range& r) | |
159 : octave_base_value (), m_range (r.m_range), | 71 : octave_base_value (), m_range (r.m_range), |
160 m_idx_cache (r.m_idx_cache ? new idx_vector (*r.m_idx_cache) : nullptr) | 72 m_idx_cache (r.m_idx_cache ? new idx_vector (*r.m_idx_cache) : nullptr) |
161 { } | 73 { } |
162 | 74 |
163 octave_range (const Range& r, const idx_vector& cache) | 75 ov_range (const octave::range<T>& r, const idx_vector& cache) |
164 : octave_base_value (), | 76 : octave_base_value (), m_range (r), m_idx_cache () |
165 m_range (r.base (), r.increment (), r.limit (), r.numel ()), | |
166 m_idx_cache () | |
167 { | 77 { |
168 set_idx_cache (cache); | 78 set_idx_cache (cache); |
169 } | 79 } |
170 | 80 |
171 ~octave_range (void) { clear_cached_info (); } | 81 // No assignment. |
172 | 82 ov_range& operator = (const ov_range&) = delete; |
173 octave_base_value * clone (void) const { return new octave_range (*this); } | 83 |
84 ~ov_range (void) { clear_cached_info (); } | |
85 | |
86 octave_base_value * clone (void) const | |
87 { | |
88 return new ov_range (*this); | |
89 } | |
174 | 90 |
175 // A range is really just a special kind of real matrix object. In | 91 // A range is really just a special kind of real matrix object. In |
176 // the places where we need to call empty_clone, it makes more sense | 92 // the places where we need to call empty_clone, it makes more sense |
177 // to create an empty matrix (0x0) instead of an empty range (1x0). | 93 // to create an empty matrix (0x0) instead of an empty range (1x0). |
178 octave_base_value * empty_clone (void) const { return new octave_matrix (); } | 94 |
95 octave_base_value * empty_clone (void) const | |
96 { | |
97 return new typename octave_value_range_traits<T>::matrix_type (); | |
98 } | |
179 | 99 |
180 type_conv_info numeric_conversion_function (void) const; | 100 type_conv_info numeric_conversion_function (void) const; |
181 | 101 |
182 octave_base_value * try_narrowing_conversion (void); | 102 octave_base_value * try_narrowing_conversion (void); |
103 | |
104 builtin_type_t builtin_type (void) const { return class_to_btyp<T>::btyp; } | |
183 | 105 |
184 // We don't need to override all three forms of subsref. The using | 106 // We don't need to override all three forms of subsref. The using |
185 // declaration will avoid warnings about partially-overloaded virtual | 107 // declaration will avoid warnings about partially-overloaded virtual |
186 // functions. | 108 // functions. |
187 using octave_base_value::subsref; | 109 using octave_base_value::subsref; |
204 return dim_vector (n > 0, n); | 126 return dim_vector (n > 0, n); |
205 } | 127 } |
206 | 128 |
207 octave_idx_type numel (void) const { return m_range.numel (); } | 129 octave_idx_type numel (void) const { return m_range.numel (); } |
208 | 130 |
209 octave_idx_type nnz (void) const { return m_range.nnz (); } | 131 octave_idx_type nnz (void) const |
132 { | |
133 // FIXME: this is a potential waste of memory. | |
134 | |
135 octave_value tmp (raw_array_value ()); | |
136 return tmp.nnz (); | |
137 } | |
210 | 138 |
211 octave_value resize (const dim_vector& dv, bool fill = false) const; | 139 octave_value resize (const dim_vector& dv, bool fill = false) const; |
212 | 140 |
213 size_t byte_size (void) const { return 3 * sizeof (double); } | 141 size_t byte_size (void) const { return 3 * sizeof (T); } |
214 | 142 |
215 octave_value reshape (const dim_vector& new_dims) const | 143 octave_value reshape (const dim_vector& new_dims) const |
216 { return NDArray (array_value ().reshape (new_dims)); } | 144 { |
145 return raw_array_value ().reshape (new_dims); | |
146 } | |
217 | 147 |
218 octave_value permute (const Array<int>& vec, bool inv = false) const | 148 octave_value permute (const Array<int>& vec, bool inv = false) const |
219 { return NDArray (array_value ().permute (vec, inv)); } | 149 { |
150 return raw_array_value ().permute (vec, inv); | |
151 } | |
220 | 152 |
221 octave_value squeeze (void) const { return m_range; } | 153 octave_value squeeze (void) const { return m_range; } |
222 | 154 |
223 octave_value full_value (void) const { return matrix_value (); } | 155 octave_value full_value (void) const { return raw_array_value (); } |
224 | 156 |
225 bool is_defined (void) const { return true; } | 157 bool is_defined (void) const { return true; } |
226 | 158 |
227 bool is_constant (void) const { return true; } | 159 bool is_constant (void) const { return true; } |
228 | 160 |
229 bool is_range (void) const { return true; } | 161 bool is_range (void) const { return true; } |
230 | 162 |
231 octave_value all (int dim = 0) const; | 163 bool is_double_type (void) const { return builtin_type () == btyp_double; } |
232 | 164 |
233 octave_value any (int dim = 0) const; | 165 bool is_single_type (void) const { return builtin_type () == btyp_float; } |
234 | 166 |
235 octave_value diag (octave_idx_type k = 0) const; | 167 bool isfloat (void) const { return btyp_isfloat (builtin_type ()); } |
236 | 168 |
237 octave_value diag (octave_idx_type m, octave_idx_type n) const; | 169 bool is_int8_type (void) const { return builtin_type () == btyp_int8; } |
170 | |
171 bool is_int16_type (void) const { return builtin_type () == btyp_int16; } | |
172 | |
173 bool is_int32_type (void) const { return builtin_type () == btyp_int32; } | |
174 | |
175 bool is_int64_type (void) const { return builtin_type () == btyp_int64; } | |
176 | |
177 bool is_uint8_type (void) const { return builtin_type () == btyp_uint8; } | |
178 | |
179 bool is_uint16_type (void) const { return builtin_type () == btyp_uint16; } | |
180 | |
181 bool is_uint32_type (void) const { return builtin_type () == btyp_uint32; } | |
182 | |
183 bool is_uint64_type (void) const { return builtin_type () == btyp_uint64; } | |
184 | |
185 bool isinteger (void) const | |
186 { | |
187 return btyp_isinteger (builtin_type ()); | |
188 } | |
189 | |
190 bool isreal (void) const { return isfloat (); } | |
191 | |
192 bool isnumeric (void) const | |
193 { | |
194 return btyp_isnumeric (builtin_type ()); | |
195 } | |
196 | |
197 bool is_true (void) const { return nnz () == numel (); } | |
198 | |
199 octave_value all (int dim = 0) const | |
200 { | |
201 // FIXME: this is a potential waste of memory. | |
202 | |
203 typedef typename octave_value_range_traits<T>::matrix_type ov_mx_type; | |
204 typename ov_mx_type::object_type m (raw_array_value ()); | |
205 | |
206 return m.all (dim); | |
207 } | |
208 | |
209 octave_value any (int dim = 0) const | |
210 { | |
211 // FIXME: this is a potential waste of memory. | |
212 | |
213 typedef typename octave_value_range_traits<T>::matrix_type ov_mx_type; | |
214 typename ov_mx_type::object_type m (raw_array_value ()); | |
215 | |
216 return m.any (dim); | |
217 } | |
218 | |
219 octave_value diag (octave_idx_type k = 0) const | |
220 { | |
221 // FIXME: this is a potential waste of memory. | |
222 | |
223 return m_range.diag (k); | |
224 } | |
225 | |
226 octave_value diag (octave_idx_type nr, octave_idx_type nc) const | |
227 { | |
228 // FIXME: this is a potential waste of memory. | |
229 | |
230 typedef typename octave_value_range_traits<T>::matrix_type ov_mx_type; | |
231 typename ov_mx_type::object_type m (raw_array_value ()); | |
232 | |
233 return m.diag (nr, nc); | |
234 } | |
238 | 235 |
239 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const | 236 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
240 { | 237 { |
241 Matrix tmp = matrix_value (); | 238 Array<T> tmp = raw_array_value (); |
242 return tmp.sort (dim, mode); | 239 return tmp.sort (dim, mode); |
243 } | 240 } |
244 | 241 |
245 octave_value sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, | 242 octave_value sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, |
246 sortmode mode = ASCENDING) const | 243 sortmode mode = ASCENDING) const |
247 { | 244 { |
248 Matrix tmp = matrix_value (); | 245 Array<T> tmp = raw_array_value (); |
249 return tmp.sort (sidx, dim, mode); | 246 return tmp.sort (sidx, dim, mode); |
250 } | 247 } |
251 | 248 |
252 sortmode issorted (sortmode mode = UNSORTED) const | 249 sortmode issorted (sortmode mode = UNSORTED) const |
253 { return m_range.issorted (mode); } | 250 { |
251 return m_range.issorted (mode); | |
252 } | |
254 | 253 |
255 Array<octave_idx_type> sort_rows_idx (sortmode) const | 254 Array<octave_idx_type> sort_rows_idx (sortmode) const |
256 { return Array<octave_idx_type> (dim_vector (1, 0)); } | 255 { |
256 return Array<octave_idx_type> (dim_vector (1, 0)); | |
257 } | |
257 | 258 |
258 sortmode is_sorted_rows (sortmode mode = UNSORTED) const | 259 sortmode is_sorted_rows (sortmode mode = UNSORTED) const |
259 { return (mode == UNSORTED) ? ASCENDING : mode; } | 260 { |
260 | 261 return (mode == UNSORTED) ? ASCENDING : mode; |
261 builtin_type_t builtin_type (void) const { return btyp_double; } | 262 } |
262 | 263 |
263 bool isreal (void) const { return true; } | 264 Array<T> raw_array_value (void) const { return m_range.array_value (); } |
264 | |
265 bool is_double_type (void) const { return true; } | |
266 | |
267 bool isfloat (void) const { return true; } | |
268 | |
269 bool isnumeric (void) const { return true; } | |
270 | |
271 bool is_true (void) const; | |
272 | 265 |
273 double double_value (bool = false) const; | 266 double double_value (bool = false) const; |
274 | 267 |
275 float float_value (bool = false) const; | 268 float float_value (bool = false) const; |
276 | 269 |
277 double scalar_value (bool frc_str_conv = false) const | 270 double scalar_value (bool frc_str_conv = false) const |
278 { return double_value (frc_str_conv); } | 271 { |
272 return double_value (frc_str_conv); | |
273 } | |
279 | 274 |
280 float float_scalar_value (bool frc_str_conv = false) const | 275 float float_scalar_value (bool frc_str_conv = false) const |
281 { return float_value (frc_str_conv); } | 276 { |
277 return float_value (frc_str_conv); | |
278 } | |
282 | 279 |
283 Matrix matrix_value (bool = false) const | 280 Matrix matrix_value (bool = false) const |
284 { return m_range.array_value (); } | 281 { |
282 return raw_array_value (); | |
283 } | |
285 | 284 |
286 FloatMatrix float_matrix_value (bool = false) const | 285 FloatMatrix float_matrix_value (bool = false) const |
287 { return matrix_value (); } | 286 { |
287 return raw_array_value (); | |
288 } | |
288 | 289 |
289 NDArray array_value (bool = false) const | 290 NDArray array_value (bool = false) const |
290 { return matrix_value (); } | 291 { |
292 return raw_array_value (); | |
293 } | |
291 | 294 |
292 FloatNDArray float_array_value (bool = false) const | 295 FloatNDArray float_array_value (bool = false) const |
293 { return FloatMatrix (matrix_value ()); } | 296 { |
297 return raw_array_value (); | |
298 } | |
294 | 299 |
295 charNDArray char_array_value (bool = false) const; | 300 charNDArray char_array_value (bool = false) const; |
296 | 301 |
297 // FIXME: it would be better to have Range::intXNDArray_value | 302 // FIXME: it would be better to have Range::intXNDArray_value |
298 // functions to avoid the intermediate conversion to a matrix | 303 // functions to avoid the intermediate conversion to a matrix |
299 // object. | 304 // object. |
300 | 305 |
301 int8NDArray | 306 int8NDArray int8_array_value (void) const |
302 int8_array_value (void) const { return int8NDArray (array_value ()); } | 307 { |
303 | 308 return raw_array_value (); |
304 int16NDArray | 309 } |
305 int16_array_value (void) const { return int16NDArray (array_value ()); } | 310 |
306 | 311 int16NDArray int16_array_value (void) const |
307 int32NDArray | 312 { |
308 int32_array_value (void) const { return int32NDArray (array_value ()); } | 313 return raw_array_value (); |
309 | 314 } |
310 int64NDArray | 315 |
311 int64_array_value (void) const { return int64NDArray (array_value ()); } | 316 int32NDArray int32_array_value (void) const |
312 | 317 { |
313 uint8NDArray | 318 return raw_array_value (); |
314 uint8_array_value (void) const { return uint8NDArray (array_value ()); } | 319 } |
315 | 320 |
316 uint16NDArray | 321 int64NDArray int64_array_value (void) const |
317 uint16_array_value (void) const { return uint16NDArray (array_value ()); } | 322 { |
318 | 323 return raw_array_value (); |
319 uint32NDArray | 324 } |
320 uint32_array_value (void) const { return uint32NDArray (array_value ()); } | 325 |
321 | 326 uint8NDArray uint8_array_value (void) const |
322 uint64NDArray | 327 { |
323 uint64_array_value (void) const { return uint64NDArray (array_value ()); } | 328 return raw_array_value (); |
329 } | |
330 | |
331 uint16NDArray uint16_array_value (void) const | |
332 { | |
333 return raw_array_value (); | |
334 } | |
335 | |
336 uint32NDArray uint32_array_value (void) const | |
337 { | |
338 return raw_array_value (); | |
339 } | |
340 | |
341 uint64NDArray uint64_array_value (void) const | |
342 { | |
343 return raw_array_value (); | |
344 } | |
324 | 345 |
325 SparseMatrix sparse_matrix_value (bool = false) const | 346 SparseMatrix sparse_matrix_value (bool = false) const |
326 { return SparseMatrix (matrix_value ()); } | 347 { |
348 return SparseMatrix (matrix_value ()); | |
349 } | |
327 | 350 |
328 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const | 351 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
329 { return SparseComplexMatrix (sparse_matrix_value ()); } | 352 { |
353 return SparseComplexMatrix (complex_matrix_value ()); | |
354 } | |
330 | 355 |
331 Complex complex_value (bool = false) const; | 356 Complex complex_value (bool = false) const; |
332 | 357 |
333 FloatComplex float_complex_value (bool = false) const; | 358 FloatComplex float_complex_value (bool = false) const; |
334 | 359 |
335 boolNDArray bool_array_value (bool warn = false) const; | 360 boolNDArray bool_array_value (bool warn = false) const; |
336 | 361 |
337 ComplexMatrix complex_matrix_value (bool = false) const | 362 ComplexMatrix complex_matrix_value (bool = false) const |
338 { return ComplexMatrix (matrix_value ()); } | 363 { |
364 return raw_array_value (); | |
365 } | |
339 | 366 |
340 FloatComplexMatrix float_complex_matrix_value (bool = false) const | 367 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
341 { return FloatComplexMatrix (matrix_value ()); } | 368 { |
369 return raw_array_value (); | |
370 } | |
342 | 371 |
343 ComplexNDArray complex_array_value (bool = false) const | 372 ComplexNDArray complex_array_value (bool = false) const |
344 { return ComplexMatrix (matrix_value ()); } | 373 { |
374 return raw_array_value (); | |
375 } | |
345 | 376 |
346 FloatComplexNDArray float_complex_array_value (bool = false) const | 377 FloatComplexNDArray float_complex_array_value (bool = false) const |
347 { return FloatComplexMatrix (matrix_value ()); } | 378 { |
348 | 379 return raw_array_value (); |
349 octave::range<double> range_value (void) const { return m_range; } | 380 } |
381 | |
382 octave::range<float> float_range_value (void) const; | |
383 | |
384 octave::range<double> range_value (void) const; | |
385 | |
386 octave::range<octave_int8> int8_range_value (void) const; | |
387 | |
388 octave::range<octave_int16> int16_range_value (void) const; | |
389 | |
390 octave::range<octave_int32> int32_range_value (void) const; | |
391 | |
392 octave::range<octave_int64> int64_range_value (void) const; | |
393 | |
394 octave::range<octave_uint8> uint8_range_value (void) const; | |
395 | |
396 octave::range<octave_uint16> uint16_range_value (void) const; | |
397 | |
398 octave::range<octave_uint32> uint32_range_value (void) const; | |
399 | |
400 octave::range<octave_uint64> uint64_range_value (void) const; | |
350 | 401 |
351 octave_value convert_to_str_internal (bool pad, bool force, char type) const; | 402 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
352 | 403 |
353 octave_value as_double (void) const; | 404 octave_value as_double (void) const; |
354 octave_value as_single (void) const; | 405 octave_value as_single (void) const; |
383 bool save_binary (std::ostream& os, bool save_as_floats); | 434 bool save_binary (std::ostream& os, bool save_as_floats); |
384 | 435 |
385 bool load_binary (std::istream& is, bool swap, | 436 bool load_binary (std::istream& is, bool swap, |
386 octave::mach_info::float_format fmt); | 437 octave::mach_info::float_format fmt); |
387 | 438 |
388 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); | 439 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool flag); |
389 | 440 |
390 bool load_hdf5 (octave_hdf5_id loc_id, const char *name); | 441 bool load_hdf5 (octave_hdf5_id loc_id, const char *name); |
391 | 442 |
392 int write (octave::stream& os, int block_size, | 443 int write (octave::stream& os, int block_size, |
393 oct_data_conv::data_type output_type, int skip, | 444 oct_data_conv::data_type output_type, int skip, |
401 | 452 |
402 mxArray * as_mxArray (bool interleaved) const; | 453 mxArray * as_mxArray (bool interleaved) const; |
403 | 454 |
404 octave_value map (unary_mapper_t umap) const | 455 octave_value map (unary_mapper_t umap) const |
405 { | 456 { |
406 octave_matrix m (matrix_value ()); | 457 octave_value tmp (raw_array_value ()); |
407 return m.map (umap); | 458 return tmp.map (umap); |
408 } | 459 } |
409 | 460 |
410 octave_value fast_elem_extract (octave_idx_type n) const; | 461 octave_value fast_elem_extract (octave_idx_type n) const; |
411 | 462 |
412 private: | 463 protected: |
413 | 464 |
414 octave::range<double> m_range; | 465 octave::range<T> m_range; |
415 | 466 |
416 idx_vector set_idx_cache (const idx_vector& idx) const | 467 idx_vector set_idx_cache (const idx_vector& idx) const |
417 { | 468 { |
418 delete m_idx_cache; | 469 delete m_idx_cache; |
419 m_idx_cache = (idx ? new idx_vector (idx) : nullptr); | 470 m_idx_cache = (idx ? new idx_vector (idx) : nullptr); |
425 delete m_idx_cache; m_idx_cache = nullptr; | 476 delete m_idx_cache; m_idx_cache = nullptr; |
426 } | 477 } |
427 | 478 |
428 mutable idx_vector *m_idx_cache; | 479 mutable idx_vector *m_idx_cache; |
429 | 480 |
430 // No assignment. | 481 static octave_hdf5_id hdf5_save_type; |
431 | |
432 octave_range& operator = (const octave_range&); | |
433 | 482 |
434 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | 483 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
435 }; | 484 }; |
436 | 485 |
437 typedef octave_range octave_float_range; | 486 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, float) |
438 typedef octave_range octave_double_range; | 487 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, double) |
439 | 488 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_int8) |
440 typedef octave_range octave_int8_range; | 489 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_int16) |
441 typedef octave_range octave_int16_range; | 490 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_int32) |
442 typedef octave_range octave_int32_range; | 491 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_int64) |
443 typedef octave_range octave_int64_range; | 492 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_uint8) |
444 | 493 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_uint16) |
445 typedef octave_range octave_uint8_range; | 494 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_uint32) |
446 typedef octave_range octave_uint16_range; | 495 DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS (ov_range, octave_uint64) |
447 typedef octave_range octave_uint32_range; | 496 |
448 typedef octave_range octave_uint64_range; | 497 // Specializations. |
449 | 498 |
499 template <> | |
500 octave::range<float> | |
501 ov_range<float>::float_range_value (void) const; | |
502 | |
503 template <> | |
504 octave::range<double> | |
505 ov_range<double>::range_value (void) const; | |
506 | |
507 template <> | |
508 octave::range<octave_int8> | |
509 ov_range<octave_int8>::int8_range_value (void) const; | |
510 | |
511 template <> | |
512 octave::range<octave_int16> | |
513 ov_range<octave_int16>::int16_range_value (void) const; | |
514 | |
515 template <> | |
516 octave::range<octave_int32> | |
517 ov_range<octave_int32>::int32_range_value (void) const; | |
518 | |
519 template <> | |
520 octave::range<octave_int64> | |
521 ov_range<octave_int64>::int64_range_value (void) const; | |
522 | |
523 template <> | |
524 octave::range<octave_uint8> | |
525 ov_range<octave_uint8>::uint8_range_value (void) const; | |
526 | |
527 template <> | |
528 octave::range<octave_uint16> | |
529 ov_range<octave_uint16>::uint16_range_value (void) const; | |
530 | |
531 template <> | |
532 octave::range<octave_uint32> | |
533 ov_range<octave_uint32>::uint32_range_value (void) const; | |
534 | |
535 template <> | |
536 octave::range<octave_uint64> | |
537 ov_range<octave_uint64>::uint64_range_value (void) const; | |
538 | |
539 // The following specializations are here to preserve previous Range | |
540 // performance until solutions can be generalized for other types. | |
541 | |
542 template <> | |
543 idx_vector | |
544 ov_range<double>::index_vector (bool require_integers) const; | |
545 | |
546 template <> | |
547 octave_idx_type | |
548 ov_range<double>::nnz (void) const; | |
549 | |
550 // The following specialization is also historical baggage. For double | |
551 // ranges, we can produce special double-valued diagnoal matrix objects | |
552 // but Octave currently provides only double and Complex diagonal matrix | |
553 // objects. | |
554 | |
555 template <> | |
556 octave_value | |
557 ov_range<double>::diag (octave_idx_type k) const; | |
558 | |
559 template <> | |
560 octave_value | |
561 ov_range<double>::diag (octave_idx_type nr, octave_idx_type nc) const; | |
562 | |
563 template <> | |
564 void | |
565 ov_range<double>::print_raw (std::ostream& os, bool pr_as_read_syntax) const; | |
566 | |
567 | |
568 typedef ov_range<float> octave_float_range; | |
569 typedef ov_range<double> octave_double_range; | |
570 | |
571 typedef ov_range<octave_int8> octave_int8_range; | |
572 typedef ov_range<octave_int16> octave_int16_range; | |
573 typedef ov_range<octave_int32> octave_int32_range; | |
574 typedef ov_range<octave_int64> octave_int64_range; | |
575 | |
576 typedef ov_range<octave_uint8> octave_uint8_range; | |
577 typedef ov_range<octave_uint16> octave_uint16_range; | |
578 typedef ov_range<octave_uint32> octave_uint32_range; | |
579 typedef ov_range<octave_uint64> octave_uint64_range; | |
580 | |
581 typedef octave_double_range octave_range; | |
450 | 582 |
451 #endif | 583 #endif |