Mercurial > octave
annotate libinterp/octave-value/ov-lazy-idx.cc @ 25287:f692728de113 stable
enable lazy index to numeric conversion (bug #53681)
* ov-lazy-idx.h, ov-lazy-idx.h (octave_lazy_index::as_double,
octave_lazy_index::as_single, octave_lazy_index::as_int8,
octave_lazy_index::as_int16, octave_lazy_index::as_int32,
octave_lazy_index::as_int64, octave_lazy_index::as_uint8,
octave_lazy_index::as_uint16, octave_lazy_index::as_uint32,
octave_lazy_index::as_uint64): New functions.
New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 Apr 2018 14:32:37 -0400 |
parents | 6652d3823428 |
children | 00f796120a6d |
rev | line source |
---|---|
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 /* |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 2010-2018 VZLU Prague |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23588
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23588
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23588
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 */ |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 #endif |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 #include "ov-lazy-idx.h" |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 #include "ops.h" |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 #include "ov-scalar.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20218
diff
changeset
|
30 #include "ls-oct-text.h" |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 #include "ls-oct-binary.h" |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_lazy_index, "lazy_index", "double"); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 static octave_base_value * |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 default_numeric_conversion_function (const octave_base_value& a) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 { |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
38 const octave_lazy_index& v = dynamic_cast<const octave_lazy_index&> (a); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 return v.full_value ().clone (); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 octave_base_value::type_conv_info |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 octave_lazy_index::numeric_conversion_function (void) const |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 { |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 octave_matrix::static_type_id ()); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 octave_base_value * |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 octave_lazy_index::try_narrowing_conversion (void) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
53 octave_base_value *retval = nullptr; |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 switch (index.length (0)) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 { |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 case 1: |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 retval = new octave_scalar (static_cast<double> (index(0) + 1)); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 break; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 case 0: |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 retval = new octave_matrix (NDArray (index.orig_dimensions ())); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 break; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 default: |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 break; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 return retval; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
72 octave_value |
20131
0d56160e346d
make printf of lazy-index object work again (bug #44864)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
73 octave_lazy_index::fast_elem_extract (octave_idx_type n) const |
0d56160e346d
make printf of lazy-index object work again (bug #44864)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
74 { |
0d56160e346d
make printf of lazy-index object work again (bug #44864)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
75 return double (index.checkelem (n) + 1); |
0d56160e346d
make printf of lazy-index object work again (bug #44864)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
76 } |
0d56160e346d
make printf of lazy-index object work again (bug #44864)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
77 |
0d56160e346d
make printf of lazy-index object work again (bug #44864)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
78 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
79 octave_lazy_index::reshape (const dim_vector& new_dims) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
80 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
81 return idx_vector (index.as_array ().reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
82 index.extent (0)); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
83 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
84 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
85 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
86 octave_lazy_index::permute (const Array<int>& vec, bool inv) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
87 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
88 // If the conversion has already been made, forward the operation. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
89 if (value.is_defined ()) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
90 return value.permute (vec, inv); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
91 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
92 return idx_vector (index.as_array ().permute (vec, inv), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
93 index.extent (0)); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
94 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
95 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
96 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
97 octave_lazy_index::squeeze (void) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
98 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
99 return idx_vector (index.as_array ().squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
100 index.extent (0)); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
101 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
102 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
103 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
104 octave_lazy_index::sort (octave_idx_type dim, sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
105 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
106 const dim_vector odims = index.orig_dimensions (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
107 // index_vector can employ a more efficient sorting algorithm. |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
108 if (mode == ASCENDING && odims.ndims () == 2 |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20131
diff
changeset
|
109 && (dim >= 0 && dim <= 1) && odims(1-dim) == 1) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
110 return index_vector ().sorted (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
111 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
112 return idx_vector (index.as_array ().sort (dim, mode), |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
113 index.extent (0)); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
114 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
115 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
116 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
117 octave_lazy_index::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
118 sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
119 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
120 const dim_vector odims = index.orig_dimensions (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
121 // index_vector can employ a more efficient sorting algorithm. |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21647
diff
changeset
|
122 if (mode == ASCENDING && odims.ndims () == 2 |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20131
diff
changeset
|
123 && (dim >= 0 && dim <= 1) && odims(1-dim) == 1) |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
124 return index_vector ().sorted (sidx); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
125 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
126 return idx_vector (index.as_array ().sort (sidx, dim, mode), |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
127 index.extent (0)); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
128 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
129 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
130 sortmode |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
131 octave_lazy_index::issorted (sortmode mode) const |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
132 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
133 if (index.is_range ()) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
134 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
135 // Avoid the array conversion. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
136 octave_idx_type inc = index.increment (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
137 if (inc == 0) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
138 return (mode == UNSORTED ? ASCENDING : mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
139 else if (inc > 0) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
140 return (mode == DESCENDING ? UNSORTED : ASCENDING); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
141 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
142 return (mode == ASCENDING ? UNSORTED : DESCENDING); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
143 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
144 else |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
145 return index.as_array ().issorted (mode); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
146 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
147 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
148 Array<octave_idx_type> |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
149 octave_lazy_index::sort_rows_idx (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
150 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
151 return index.as_array ().sort_rows_idx (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
152 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
153 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
154 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
155 octave_lazy_index::is_sorted_rows (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
156 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
157 return index.as_array ().is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
158 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
159 |
25287
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
160 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
161 octave_lazy_index::as_double (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
162 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
163 return array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
164 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
165 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
166 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
167 octave_lazy_index::as_single (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
168 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
169 return float_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
170 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
171 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
172 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
173 octave_lazy_index::as_int8 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
174 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
175 return int8_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
176 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
177 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
178 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
179 octave_lazy_index::as_int16 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
180 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
181 return int16_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
182 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
183 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
184 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
185 octave_lazy_index::as_int32 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
186 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
187 return int32_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
188 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
189 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
190 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
191 octave_lazy_index::as_int64 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
192 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
193 return int64_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
194 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
195 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
196 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
197 octave_lazy_index::as_uint8 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
198 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
199 return uint8_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
200 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
201 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
202 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
203 octave_lazy_index::as_uint16 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
204 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
205 return uint16_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
206 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
207 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
208 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
209 octave_lazy_index::as_uint32 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
210 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
211 return uint32_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
212 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
213 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
214 octave_value |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
215 octave_lazy_index::as_uint64 (void) const |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
216 { |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
217 return uint64_array_value (); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
218 } |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
219 |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
220 static const std::string value_save_tag ("index_value"); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
221 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
222 bool octave_lazy_index::save_ascii (std::ostream& os) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
223 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20218
diff
changeset
|
224 return save_text_data (os, make_value (), value_save_tag, false, 0); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
225 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
226 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
227 bool octave_lazy_index::load_ascii (std::istream& is) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
228 { |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
229 bool dummy; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
230 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
231 std::string nm = read_text_data (is, "", dummy, value, 0); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
232 if (nm != value_save_tag) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
233 error ("lazy_index: corrupted data on load"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
234 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
235 index = value.index_vector (); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
236 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
237 return true; |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
238 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
239 |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
240 bool octave_lazy_index::save_binary (std::ostream& os, bool& save_as_floats) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
241 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
242 return save_binary_data (os, make_value (), value_save_tag, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
243 "", false, save_as_floats); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
244 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
245 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
246 bool octave_lazy_index::load_binary (std::istream& is, bool swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
247 octave::mach_info::float_format fmt) |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
248 { |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
249 bool dummy; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
250 std::string doc; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
251 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
252 std::string nm = read_binary_data (is, swap, fmt, "", dummy, value, doc); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
253 if (nm != value_save_tag) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
254 error ("lazy_index: corrupted data on load"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
255 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
256 index = value.index_vector (); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
257 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
258 return true; |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
259 } |
25287
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
260 |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
261 /* |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
262 %!shared x, y |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
263 %! x = find ([-1, 0, -2, 1, 3, -4] < 0); |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
264 %! y = [1, 3, 6]; |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
265 %!assert (typeinfo (x), "lazy_index") |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
266 %!assert (double (x), y) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
267 %!assert (single (x), single (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
268 %!assert (int8 (x), int8 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
269 %!assert (int16 (x), int16 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
270 %!assert (int32 (x), int32 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
271 %!assert (int64 (x), int64 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
272 %!assert (uint8 (x), uint8 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
273 %!assert (uint16 (x), uint16 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
274 %!assert (uint32 (x), uint32 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
275 %!assert (uint64 (x), uint64 (y)) |
f692728de113
enable lazy index to numeric conversion (bug #53681)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
276 */ |