Mercurial > octave-nkf
annotate liboctave/array/idx-vector.h @ 19632:76478d2da117
unconditionally disable the octave_allocator class
* configure.ac: Delete the --enable-octave-allocator option.
* oct-alloc.h: Delete octave_allocator class. Warn if file is
included. Unconditionally define macros to be empty.
* NEWS: Make note of these changes.
* oct-alloc.cc: Delete.
* liboctave/util/module.mk (UTIL_SRC): Remove it from the list.
* make_int.cc, Cell.h, oct-obj.cc, oct-obj.h, audiodevinfo.cc,
ov-base-int.h, ov-base-scalar.h, ov-bool-mat.cc, ov-bool-mat.h,
ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h,
ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.h,
ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc,
ov-complex.h, ov-cs-list.cc, ov-cs-list.h, ov-cx-diag.cc,
ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc,
ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc,
ov-fcn-handle.h, ov-fcn-inline.cc, ov-fcn-inline.h, ov-fcn.cc,
ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc,
ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h,
ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc,
ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-java.cc,
ov-java.h, ov-mex-fcn.cc, ov-mex-fcn.h, ov-perm.cc, ov-perm.h,
ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc,
ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc,
ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc, ov-struct.h,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc,
ov-usr-fcn.h, ov.cc, ov.h, pt-const.cc, pt-const.h, idx-vector.cc,
idx-vector.h: Delete uses of oct-alloc.h and OCTAVE_ALLOCATOR macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 13:43:29 -0500 |
parents | af41e41ad28e |
children | 4197fc428c7d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
3 Copyright (C) 1993-2013 John W. Eaton |
11523 | 4 Copyright (C) 2008-2009 Jaroslav Hajek |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague |
1 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1 | 22 |
23 */ | |
24 | |
383 | 25 #if !defined (octave_idx_vector_h) |
26 #define octave_idx_vector_h 1 | |
1 | 27 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
28 #include <cassert> |
19415
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
29 #include <cstring> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
30 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
31 #include <algorithm> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
32 #include <iosfwd> |
13735
2cd903770748
Fix broken gcc compilation due to changeset d13b6086aea9.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13729
diff
changeset
|
33 #include <memory> |
3503 | 34 |
4653 | 35 #include "dim-vector.h" |
4938 | 36 #include "oct-inttypes.h" |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
37 #include "oct-refcount.h" |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
38 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
39 template<class T> class Array; |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
40 template<class T> class Sparse; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
41 class Range; |
4504 | 42 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
43 // Design rationale: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
44 // idx_vector is a reference-counting, polymorphic pointer, that can contain |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
45 // 4 types of index objects: a magic colon, a range, a scalar, or an index vector. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
46 // Polymorphic methods for single element access are provided, as well as |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
47 // templates implementing "early dispatch", i.e. hoisting the checks for index |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
48 // type out of loops. |
164 | 49 |
453 | 50 class |
6108 | 51 OCTAVE_API |
453 | 52 idx_vector |
1 | 53 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
54 public: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
55 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
56 enum idx_class_type |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 class_invalid = -1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 class_colon = 0, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 class_range, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 class_scalar, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 class_vector, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 class_mask |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 }; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
65 |
13729
d13b6086aea9
Make std::auto_ptr friend of idx_vector to allow access to private class idx_vector_rep.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
66 template<class T> friend class std::auto_ptr; |
d13b6086aea9
Make std::auto_ptr friend of idx_vector to allow access to private class idx_vector_rep.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
67 |
1560 | 68 private: |
69 | |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
70 class OCTAVE_API idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
71 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
72 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
73 idx_base_rep (void) : count (1), err (false) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
74 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
75 virtual ~idx_base_rep (void) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
76 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
77 // Non-range-checking element query. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
78 virtual octave_idx_type xelem (octave_idx_type i) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
79 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
80 // Range-checking element query. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
81 virtual octave_idx_type checkelem (octave_idx_type i) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
82 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
83 // Length of the index vector. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
84 virtual octave_idx_type length (octave_idx_type n) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
85 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
86 // The maximum index + 1. The actual dimension is passed in. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
87 virtual octave_idx_type extent (octave_idx_type n) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
88 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
89 // Index class. |
8333 | 90 virtual idx_class_type idx_class (void) const { return class_invalid; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
91 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
92 // Sorts, maybe uniqifies, and returns a clone object pointer. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
93 virtual idx_base_rep *sort_uniq_clone (bool uniq = false) = 0; |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
94 // Sorts, and returns a sorting permutation (aka Array::sort). |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
95 virtual idx_base_rep *sort_idx (Array<octave_idx_type>&) = 0; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
96 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
97 // Checks whether the index is colon or a range equivalent to colon. |
10487 | 98 virtual bool is_colon_equiv (octave_idx_type) const { return false; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
99 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 // The original dimensions of object (used when subscribing by matrices). |
10487 | 101 virtual dim_vector orig_dimensions (void) const { return dim_vector (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
102 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
103 // i/o |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
104 virtual std::ostream& print (std::ostream& os) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
105 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
106 virtual Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
107 |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
108 octave_refcount<int> count; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
109 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
110 bool err; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
111 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
112 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
113 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
114 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
115 idx_base_rep (const idx_base_rep&); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
116 idx_base_rep& operator = (const idx_base_rep&); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
117 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
118 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
119 // The magic colon index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
120 class OCTAVE_API idx_colon_rep : public idx_base_rep |
1879 | 121 { |
122 public: | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
123 idx_colon_rep (void) { } |
1879 | 124 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
125 idx_colon_rep (char c); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
126 |
10487 | 127 octave_idx_type xelem (octave_idx_type i) const { return i; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
128 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
129 octave_idx_type checkelem (octave_idx_type i) const; |
1560 | 130 |
10487 | 131 octave_idx_type length (octave_idx_type n) const { return n; } |
1560 | 132 |
10487 | 133 octave_idx_type extent (octave_idx_type n) const { return n; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
134 |
8333 | 135 idx_class_type idx_class (void) const { return class_colon; } |
1879 | 136 |
10487 | 137 idx_base_rep *sort_uniq_clone (bool = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 { count++; return this; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
139 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
140 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
141 |
10487 | 142 bool is_colon_equiv (octave_idx_type) const { return true; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
143 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
144 std::ostream& print (std::ostream& os) const; |
4938 | 145 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
146 private: |
4938 | 147 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
148 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
149 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
150 idx_colon_rep (const idx_colon_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
151 idx_colon_rep& operator = (const idx_colon_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
152 }; |
2386 | 153 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
154 // To distinguish the "direct" constructors that blindly trust the data. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
155 enum direct { DIRECT }; |
2828 | 156 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
157 // The integer range index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
158 class OCTAVE_API idx_range_rep : public idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
159 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
160 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
161 idx_range_rep (octave_idx_type _start, octave_idx_type _len, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
162 octave_idx_type _step, direct) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
163 : idx_base_rep (), start(_start), len(_len), step(_step) { } |
4938 | 164 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
165 idx_range_rep (void) |
8298
7e87d3d76a56
fix extent query for empty ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
166 : start(0), len(0), step(1) { } |
1560 | 167 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
168 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
169 idx_range_rep (octave_idx_type _start, octave_idx_type _limit, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
170 octave_idx_type _step); |
1560 | 171 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
172 idx_range_rep (const Range&); |
1560 | 173 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
174 octave_idx_type xelem (octave_idx_type i) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
175 { return start + i * step; } |
1560 | 176 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
177 octave_idx_type checkelem (octave_idx_type i) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
178 |
10487 | 179 octave_idx_type length (octave_idx_type) const { return len; } |
1560 | 180 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
181 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
182 { return len ? std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1)))) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
183 : n; } |
1560 | 184 |
8333 | 185 idx_class_type idx_class (void) const { return class_range; } |
1879 | 186 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
187 idx_base_rep *sort_uniq_clone (bool uniq = false); |
1560 | 188 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
189 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
190 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
191 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
192 { return start == 0 && step == 1 && len == n; } |
1560 | 193 |
8333 | 194 dim_vector orig_dimensions (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
195 { return dim_vector (1, len); } |
1560 | 196 |
8333 | 197 octave_idx_type get_start (void) const { return start; } |
1560 | 198 |
8333 | 199 octave_idx_type get_step (void) const { return step; } |
1560 | 200 |
3504 | 201 std::ostream& print (std::ostream& os) const; |
1560 | 202 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
203 Range unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
204 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
205 Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
206 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
207 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
208 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
209 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
210 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
211 idx_range_rep (const idx_range_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
212 idx_range_rep& operator = (const idx_range_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
213 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
214 octave_idx_type start, len, step; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
215 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
216 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
217 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
218 // The integer scalar index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
219 class OCTAVE_API idx_scalar_rep : public idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
220 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
221 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
222 idx_scalar_rep (octave_idx_type i, direct) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
223 : data (i) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
224 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
225 idx_scalar_rep (void) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
226 : data (0) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
227 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
228 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
229 idx_scalar_rep (octave_idx_type i); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
230 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
231 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
232 idx_scalar_rep (T x); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
233 |
10487 | 234 octave_idx_type xelem (octave_idx_type) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
235 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
236 octave_idx_type checkelem (octave_idx_type i) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
237 |
10487 | 238 octave_idx_type length (octave_idx_type) const { return 1; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
239 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
240 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
241 { return std::max (n, data + 1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
242 |
8333 | 243 idx_class_type idx_class (void) const { return class_scalar; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
244 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
245 idx_base_rep *sort_uniq_clone (bool = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
246 { count++; return this; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
247 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
248 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
249 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
250 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
251 { return n == 1 && data == 0; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
252 |
10487 | 253 dim_vector orig_dimensions (void) const { return dim_vector (1, 1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
254 |
8333 | 255 octave_idx_type get_data (void) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
256 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
257 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
258 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
259 double unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
260 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
261 Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
262 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
263 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
264 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
265 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
266 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
267 idx_scalar_rep (const idx_scalar_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
268 idx_scalar_rep& operator = (const idx_scalar_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
269 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
270 octave_idx_type data; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
271 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
272 }; |
4504 | 273 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
274 // The integer vector index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
275 class OCTAVE_API idx_vector_rep : public idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
276 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
277 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
278 // Direct constructor. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
279 idx_vector_rep (octave_idx_type *_data, octave_idx_type _len, |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
280 octave_idx_type _ext, const dim_vector& od, direct) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
281 : data (_data), len (_len), ext (_ext), aowner (0), orig_dims (od) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
282 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
283 idx_vector_rep (void) |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
284 : data (0), len (0), ext (0), aowner (0), orig_dims () |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
285 { } |
5275 | 286 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
287 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
288 idx_vector_rep (const Array<octave_idx_type>& inda); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
289 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
290 idx_vector_rep (const Array<octave_idx_type>& inda, |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
291 octave_idx_type _ext, direct); |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
292 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
293 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
294 idx_vector_rep (const Array<T>&); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
295 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
296 idx_vector_rep (bool); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
297 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
298 idx_vector_rep (const Array<bool>&, octave_idx_type = -1); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
299 |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
300 idx_vector_rep (const Sparse<bool>&); |
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
301 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
302 ~idx_vector_rep (void); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
303 |
10487 | 304 octave_idx_type xelem (octave_idx_type i) const { return data[i]; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
305 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
306 octave_idx_type checkelem (octave_idx_type i) const; |
4653 | 307 |
10487 | 308 octave_idx_type length (octave_idx_type) const { return len; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
309 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
310 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
311 { return std::max (n, ext); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
312 |
8333 | 313 idx_class_type idx_class (void) const { return class_vector; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
314 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
315 idx_base_rep *sort_uniq_clone (bool uniq = false); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
316 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
317 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
318 |
10487 | 319 dim_vector orig_dimensions (void) const { return orig_dims; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
320 |
8333 | 321 const octave_idx_type *get_data (void) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
322 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
323 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
324 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
325 Array<double> unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
326 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
327 Array<octave_idx_type> as_array (void); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
328 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
329 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
330 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
331 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
332 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
333 idx_vector_rep (const idx_vector_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
334 idx_vector_rep& operator = (const idx_vector_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
335 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
336 const octave_idx_type *data; |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
337 octave_idx_type len; |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
338 octave_idx_type ext; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
339 |
10487 | 340 // This is a trick to allow user-given zero-based arrays to be used |
341 // as indices without copying. If the following pointer is nonzero, | |
342 // we do not own the data, but rather have an Array<octave_idx_type> | |
343 // object that provides us the data. Note that we need a pointer | |
344 // because we deferred the Array<T> declaration and we do not want | |
345 // it yet to be defined. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
346 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
347 Array<octave_idx_type> *aowner; |
1560 | 348 |
4653 | 349 dim_vector orig_dims; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
350 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
351 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
352 // The logical mask index. |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
353 class OCTAVE_API idx_mask_rep : public idx_base_rep |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
354 { |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
355 public: |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
356 // Direct constructor. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
357 idx_mask_rep (bool *_data, octave_idx_type _len, |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
358 octave_idx_type _ext, const dim_vector& od, direct) |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
359 : data (_data), len (_len), ext (_ext), lsti (-1), lste (-1), |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
360 aowner (0), orig_dims (od) { } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
361 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
362 idx_mask_rep (void) |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
363 : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0), |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
364 orig_dims () |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
365 { } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
366 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
367 idx_mask_rep (bool); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
368 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
369 idx_mask_rep (const Array<bool>&, octave_idx_type = -1); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
370 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
371 ~idx_mask_rep (void); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
372 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
373 octave_idx_type xelem (octave_idx_type i) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
374 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
375 octave_idx_type checkelem (octave_idx_type i) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
376 |
10487 | 377 octave_idx_type length (octave_idx_type) const { return len; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
378 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
379 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
380 { return std::max (n, ext); } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
381 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
382 idx_class_type idx_class (void) const { return class_mask; } |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
383 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
384 idx_base_rep *sort_uniq_clone (bool = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
385 { count++; return this; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
386 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
387 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
388 |
10487 | 389 dim_vector orig_dimensions (void) const { return orig_dims; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
390 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
391 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 { return len == n && ext == n; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
393 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
394 const bool *get_data (void) const { return data; } |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
395 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
396 std::ostream& print (std::ostream& os) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
397 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
398 Array<bool> unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
399 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10339
diff
changeset
|
400 Array<octave_idx_type> as_array (void); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
401 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
402 private: |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
403 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
404 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
405 // No copying! |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
406 idx_mask_rep (const idx_mask_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
407 idx_mask_rep& operator = (const idx_mask_rep& idx); |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
408 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
409 const bool *data; |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
410 octave_idx_type len; |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
411 octave_idx_type ext; |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
412 |
10487 | 413 // FIXME: I'm not sure if this is a good design. Maybe it would be |
414 // better to employ some sort of generalized iteration scheme. | |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
415 mutable octave_idx_type lsti; |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
416 mutable octave_idx_type lste; |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
417 |
10487 | 418 // This is a trick to allow user-given mask arrays to be used as |
419 // indices without copying. If the following pointer is nonzero, we | |
420 // do not own the data, but rather have an Array<bool> object that | |
421 // provides us the data. Note that we need a pointer because we | |
422 // deferred the Array<T> declaration and we do not want it yet to be | |
423 // defined. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
424 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
425 Array<bool> *aowner; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
426 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
427 dim_vector orig_dims; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
428 }; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
429 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
430 idx_vector (idx_base_rep *r) : rep (r) { } |
1560 | 431 |
10487 | 432 // The shared empty vector representation (for fast default |
433 // constructor). | |
8333 | 434 static idx_vector_rep *nil_rep (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
435 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
436 static idx_vector_rep ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
437 return &ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
438 } |
4938 | 439 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
440 // The shared empty vector representation with the error flag set. |
8333 | 441 static idx_vector_rep *err_rep (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
442 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
443 static idx_vector_rep ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
444 ivr.err = true; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
445 return &ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
446 } |
4938 | 447 |
10487 | 448 // If there was an error in constructing the rep, replace it with |
449 // empty vector for safety. | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
450 void chkerr (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
451 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
452 if (rep->err) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
453 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
454 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
455 delete rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
456 rep = err_rep (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
457 rep->count++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
458 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
459 } |
1560 | 460 |
1 | 461 public: |
1551 | 462 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
463 // Fast empty constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
464 idx_vector (void) : rep (nil_rep ()) { rep->count++; } |
1560 | 465 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
466 // Zero-based constructors (for use from C++). |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
467 idx_vector (octave_idx_type i) : rep (new idx_scalar_rep (i)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
468 { chkerr (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
469 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
470 idx_vector (octave_idx_type start, octave_idx_type limit, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
471 octave_idx_type step = 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
472 : rep (new idx_range_rep (start, limit, step)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
473 { chkerr (); } |
1560 | 474 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
475 static idx_vector |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
476 make_range (octave_idx_type start, octave_idx_type step, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
477 octave_idx_type len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
478 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 return idx_vector (new idx_range_rep (start, len, step, DIRECT)); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 } |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
481 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
482 idx_vector (const Array<octave_idx_type>& inda) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
483 : rep (new idx_vector_rep (inda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 { chkerr (); } |
1560 | 485 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
486 // Directly pass extent, no checking. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
487 idx_vector (const Array<octave_idx_type>& inda, octave_idx_type ext) |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
488 : rep (new idx_vector_rep (inda, ext, DIRECT)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
489 { } |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
490 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
491 // Colon is best constructed by simply copying (or referencing) this member. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
492 static const idx_vector colon; |
4938 | 493 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
494 // or passing ':' here |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
495 idx_vector (char c) : rep (new idx_colon_rep (c)) { chkerr (); } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
496 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
497 // Conversion constructors (used by interpreter). |
1560 | 498 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
499 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
500 idx_vector (octave_int<T> x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
501 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
502 idx_vector (double x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
2386 | 503 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
504 idx_vector (float x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
3928 | 505 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
506 // A scalar bool does not necessarily map to scalar index. |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
507 idx_vector (bool x) : rep (new idx_mask_rep (x)) { chkerr (); } |
1560 | 508 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
509 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
510 idx_vector (const Array<octave_int<T> >& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
511 { chkerr (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
512 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
513 idx_vector (const Array<double>& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
514 { chkerr (); } |
2828 | 515 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
516 idx_vector (const Array<float>& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
517 { chkerr (); } |
4938 | 518 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
519 idx_vector (const Array<bool>& nda); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
520 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
521 idx_vector (const Range& r) |
10489
d47802f0e557
Back out changeset 4e64fbbd5c58
Jaroslav Hajek <highegg@gmail.com>
parents:
10487
diff
changeset
|
522 : rep (new idx_range_rep (r)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
523 { chkerr (); } |
2828 | 524 |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
525 idx_vector (const Sparse<bool>& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
526 { chkerr (); } |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
527 |
4979 | 528 idx_vector (const idx_vector& a) : rep (a.rep) { rep->count++; } |
1551 | 529 |
2802 | 530 ~idx_vector (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
531 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
532 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
533 delete rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
534 } |
1 | 535 |
1560 | 536 idx_vector& operator = (const idx_vector& a) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
537 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
538 if (this != &a) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
540 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
541 delete rep; |
1 | 542 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
543 rep = a.rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
544 rep->count++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
545 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
546 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
547 } |
1551 | 548 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
549 idx_class_type idx_class (void) const { return rep->idx_class (); } |
1560 | 550 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
551 octave_idx_type length (octave_idx_type n = 0) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
552 { return rep->length (n); } |
191 | 553 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
554 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
555 { return rep->extent (n); } |
1 | 556 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
557 octave_idx_type xelem (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
558 { return rep->xelem (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
559 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
560 octave_idx_type checkelem (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
561 { return rep->checkelem (n); } |
1551 | 562 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
563 octave_idx_type operator () (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
564 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
565 #if defined (BOUNDS_CHECKING) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
566 return rep->checkelem (n); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
567 #else |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
568 return rep->xelem (n); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
569 #endif |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
570 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
571 |
8333 | 572 operator bool (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
573 { return ! rep->err; } |
1 | 574 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
575 bool is_colon (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
576 { return rep->idx_class () == class_colon; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
577 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
578 bool is_scalar (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
579 { return rep->idx_class () == class_scalar; } |
1 | 580 |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
581 bool is_range (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
582 { return rep->idx_class () == class_range; } |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
583 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
584 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
585 { return rep->is_colon_equiv (n); } |
3079 | 586 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
587 idx_vector sorted (bool uniq = false) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
588 { return idx_vector (rep->sort_uniq_clone (uniq)); } |
208 | 589 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
590 idx_vector sorted (Array<octave_idx_type>& sidx) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
591 { return idx_vector (rep->sort_idx (sidx)); } |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
592 |
4653 | 593 dim_vector orig_dimensions (void) const { return rep->orig_dimensions (); } |
4504 | 594 |
8333 | 595 octave_idx_type orig_rows (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
596 { return orig_dimensions () (0); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
597 |
8333 | 598 octave_idx_type orig_columns (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
599 { return orig_dimensions () (1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
600 |
2663 | 601 int orig_empty (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
602 { return (! is_colon () && orig_dimensions ().any_zero ()); } |
2663 | 603 |
4653 | 604 // i/o |
1 | 605 |
3504 | 606 std::ostream& print (std::ostream& os) const { return rep->print (os); } |
1560 | 607 |
3504 | 608 friend std::ostream& operator << (std::ostream& os, const idx_vector& a) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
609 { return a.print (os); } |
1560 | 610 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
611 // Slice with specializations. No checking of bounds! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
612 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
613 // This is equivalent to the following loop (but much faster): |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
614 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
615 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
616 // dest[i] = src[idx(i)]; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
617 // return i; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
618 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
619 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
620 octave_idx_type |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
621 index (const T *src, octave_idx_type n, T *dest) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
622 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
623 octave_idx_type len = rep->length (n); |
10487 | 624 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
625 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
626 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
627 case class_colon: |
19415
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
628 std::copy (src, src + len, dest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
629 break; |
10487 | 630 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
631 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
632 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
633 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
634 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
635 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
636 const T *ssrc = src + start; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
637 if (step == 1) |
19415
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
638 std::copy (ssrc, ssrc + len, dest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
639 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
640 std::reverse_copy (ssrc - len + 1, ssrc + 1, dest); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
641 else if (step == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
642 std::fill_n (dest, len, *ssrc); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
643 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
644 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
645 for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
646 dest[i] = ssrc[j]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
647 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
648 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
649 break; |
10487 | 650 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
653 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
654 dest[0] = src[r->get_data ()]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
655 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
656 break; |
10487 | 657 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
658 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
659 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
660 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
661 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
662 for (octave_idx_type i = 0; i < len; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
663 dest[i] = src[data[i]]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
664 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 break; |
10487 | 666 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
667 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
668 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
669 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
670 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
671 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
672 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
673 if (data[i]) *dest++ = src[i]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
674 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
675 break; |
10487 | 676 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
677 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
678 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
679 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
680 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
681 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
682 return len; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
683 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
684 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
685 // Slice assignment with specializations. No checking of bounds! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
686 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
687 // This is equivalent to the following loop (but much faster): |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
688 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
689 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
690 // dest[idx(i)] = src[i]; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
691 // return i; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
692 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
693 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
694 octave_idx_type |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
695 assign (const T *src, octave_idx_type n, T *dest) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
696 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
697 octave_idx_type len = rep->length (n); |
10487 | 698 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
699 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
700 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
701 case class_colon: |
19415
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
702 std::copy (src, src + len, dest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
703 break; |
10487 | 704 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
705 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
706 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
707 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
708 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
709 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
710 T *sdest = dest + start; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
711 if (step == 1) |
19415
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
712 std::copy (src, src + len, sdest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
713 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
714 std::reverse_copy (src, src + len, sdest - len + 1); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
715 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
716 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
717 for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
718 sdest[j] = src[i]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
719 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
720 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
721 break; |
10487 | 722 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
723 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
724 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
725 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
726 dest[r->get_data ()] = src[0]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
727 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
728 break; |
10487 | 729 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
730 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
731 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
732 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
733 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
734 for (octave_idx_type i = 0; i < len; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
735 dest[data[i]] = src[i]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
736 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
737 break; |
10487 | 738 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
739 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
740 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
741 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
742 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
743 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
744 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
745 if (data[i]) dest[i] = *src++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
746 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
747 break; |
10487 | 748 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
749 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
750 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
751 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
752 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
753 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
754 return len; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
755 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
756 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
757 // Slice fill with specializations. No checking of bounds! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
758 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
759 // This is equivalent to the following loop (but much faster): |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
760 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
761 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
762 // dest[idx(i)] = val; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
763 // return i; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
764 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
765 template <class T> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
766 octave_idx_type |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
767 fill (const T& val, octave_idx_type n, T *dest) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
768 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
769 octave_idx_type len = rep->length (n); |
10487 | 770 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
771 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
772 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
773 case class_colon: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
774 std::fill (dest, dest + len, val); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
775 break; |
10487 | 776 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
777 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
778 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
779 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
780 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
781 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
782 T *sdest = dest + start; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
783 if (step == 1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
784 std::fill (sdest, sdest + len, val); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
785 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
786 std::fill (sdest - len + 1, sdest + 1, val); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
787 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
788 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
789 for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
790 sdest[j] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
791 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
792 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
793 break; |
10487 | 794 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
795 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
796 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
797 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
798 dest[r->get_data ()] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
799 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
800 break; |
10487 | 801 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
802 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
803 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
804 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
805 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
806 for (octave_idx_type i = 0; i < len; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
807 dest[data[i]] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
808 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
809 break; |
10487 | 810 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
811 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
812 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
813 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
814 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
815 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
816 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
817 if (data[i]) dest[i] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
818 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
819 break; |
10487 | 820 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
821 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
822 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
823 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
824 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
825 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
826 return len; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
827 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
828 |
10487 | 829 // Generic non-breakable indexed loop. The loop body should be |
830 // encapsulated in a single functor body. This is equivalent to the | |
831 // following loop (but faster, at least for simple inlined bodies): | |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
832 // |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
833 // for (octave_idx_type i = 0; i < idx->length (n); i++) body (idx(i)); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
834 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
835 template <class Functor> |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
836 void |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
837 loop (octave_idx_type n, Functor body) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
838 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
839 octave_idx_type len = rep->length (n); |
10487 | 840 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
841 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
842 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
843 case class_colon: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
844 for (octave_idx_type i = 0; i < len; i++) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
845 break; |
10487 | 846 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
847 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
848 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
849 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
850 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
851 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
852 octave_idx_type i, j; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
853 if (step == 1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
854 for (i = start, j = start + len; i < j; i++) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
855 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
856 for (i = start, j = start - len; i > j; i--) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
857 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
858 for (i = 0, j = start; i < len; i++, j += step) body (j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
859 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
860 break; |
10487 | 861 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
862 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
863 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
864 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
865 body (r->get_data ()); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
866 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
867 break; |
10487 | 868 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
869 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
870 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
871 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
872 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
873 for (octave_idx_type i = 0; i < len; i++) body (data[i]); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
874 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
875 break; |
10487 | 876 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
877 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
878 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
879 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
880 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
881 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
882 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
883 if (data[i]) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
884 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
885 break; |
10487 | 886 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
887 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
888 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
889 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
890 } |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
891 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
892 } |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
893 |
10487 | 894 // Generic breakable indexed loop. The loop body should be |
895 // encapsulated in a single functor body. This is equivalent to the | |
896 // following loop (but faster, at least for simple inlined bodies): | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
897 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
898 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
899 // if (body (idx(i))) break; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
900 // return i; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
901 // |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
902 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
903 template <class Functor> |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
904 octave_idx_type |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
905 bloop (octave_idx_type n, Functor body) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
906 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
907 octave_idx_type len = rep->length (n), ret; |
10487 | 908 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
909 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
910 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
911 case class_colon: |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
912 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
913 octave_idx_type i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
914 for (i = 0; i < len && body (i); i++) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
915 ret = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
916 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
917 break; |
10487 | 918 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
919 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
920 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
921 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
922 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
923 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
924 octave_idx_type i, j; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
925 if (step == 1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
926 for (i = start, j = start + len; i < j && body (i); i++) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
927 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
928 for (i = start, j = start - len; i > j && body (i); i--) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
929 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
930 for (i = 0, j = start; i < len && body (j); i++, j += step) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
931 ret = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
932 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
933 break; |
10487 | 934 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
935 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
936 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
937 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
938 ret = body (r->get_data ()) ? 1 : 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
939 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
940 break; |
10487 | 941 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
942 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
943 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
944 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
945 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
946 octave_idx_type i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
947 for (i = 0; i < len && body (data[i]); i++) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
948 ret = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
949 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
950 break; |
10487 | 951 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
952 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
953 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
954 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
955 const bool *data = r->get_data (); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
956 octave_idx_type ext = r->extent (0); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
957 octave_idx_type j = 0; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
958 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
959 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
960 if (data[i]) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
961 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
962 if (body (i)) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
963 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
964 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
965 j++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
966 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
967 } |
9985
43a29eeda994
fix idx_vector::loop for masks
Jaroslav Hajek <highegg@gmail.com>
parents:
9894
diff
changeset
|
968 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
969 ret = j; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
970 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
971 break; |
10487 | 972 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
973 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
974 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
975 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
976 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
977 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
978 return ret; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
979 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
980 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
981 // Rationale: |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
982 // This method is the key to "smart indexing". When indexing cartesian |
10487 | 983 // arrays, sometimes consecutive index vectors can be reduced into a |
984 // single index. If rows (A) = k and i.maybe_reduce (j) gives k, then | |
985 // A(i,j)(:) is equal to A(k)(:). | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
986 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
987 // If the next index can be reduced, returns true and updates this. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
988 bool maybe_reduce (octave_idx_type n, const idx_vector& j, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
989 octave_idx_type nj); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
990 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
991 bool is_cont_range (octave_idx_type n, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
992 octave_idx_type& l, octave_idx_type& u) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
993 |
9725 | 994 // Returns the increment for ranges and colon, 0 for scalars and empty |
995 // vectors, 1st difference otherwise. | |
996 octave_idx_type increment (void) const; | |
997 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
998 idx_vector |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
999 complement (octave_idx_type n) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1000 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1001 bool is_permutation (octave_idx_type n) const; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1002 |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1003 // Returns the inverse permutation. If this is not a permutation on 1:n, the |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1004 // result is undefined (but no error unless extent () != n). |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1005 idx_vector inverse_permutation (octave_idx_type n) const; |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1006 |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1007 // Copies all the indices to a given array. Not allowed for colons. |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1008 void copy_data (octave_idx_type *data) const; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1009 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
1010 // If the index is a mask, convert it to index vector. |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
1011 idx_vector unmask (void) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
1012 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
1013 // Unconverts the index to a scalar, Range, double array or a mask. |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1014 void unconvert (idx_class_type& iclass, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1015 double& scalar, Range& range, |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
1016 Array<double>& array, Array<bool>& mask) const; |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1017 |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1018 Array<octave_idx_type> as_array (void) const; |
10475
739109ef88ee
helper idx_vector methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1019 |
10487 | 1020 // Raw pointer to index array. This is non-const because it may be |
1021 // necessary to mutate the index. | |
10475
739109ef88ee
helper idx_vector methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1022 const octave_idx_type *raw (void); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1023 |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1024 bool is_vector (void) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1025 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1026 // FIXME: these are here for compatibility. They should be removed |
8333 | 1027 // when no longer in use. |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1028 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1029 octave_idx_type elem (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1030 { return (*this) (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1031 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1032 bool is_colon_equiv (octave_idx_type n, int) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1033 { return is_colon_equiv (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1034 |
8333 | 1035 octave_idx_type |
1036 freeze (octave_idx_type z_len, const char *tag, bool resize_ok = false); | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1037 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1038 void sort (bool uniq = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1039 { *this = sorted (uniq); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1040 |
8333 | 1041 octave_idx_type ones_count (void) const; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1042 |
8333 | 1043 octave_idx_type max (void) const { return extent (1) - 1; } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1044 |
1 | 1045 private: |
1046 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1047 idx_base_rep *rep; |
1 | 1048 |
1049 }; | |
1050 | |
1051 #endif |