Mercurial > octave
annotate liboctave/array/idx-vector.h @ 23592:80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
* Array.h (is_vector): Use OCTAVE_DEPRECATED macro around function.
* Array.h (isvector): New function.
* dim-vector.h (is_vector): Use OCTAVE_DEPRECATED macro around function.
* dim-vector.h (isvector): New function.
* idx-vector.h (is_vector): Use OCTAVE_DEPRECATED macro around function.
* idx-vector.h (isvector): New function.
* cellfun.cc, data.cc, dot.cc, filter.cc, utils.cc, ov-class.cc, ov-java.cc,
Array-util.cc, Array-util.h, Array.cc, Range.cc, Sparse.cc, idx-vector.cc,
oct-string.cc: Replace instances of is_vector with isvector.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 13 Jun 2017 20:51:14 -0700 |
parents | b6498c088fca |
children | be7b884ac589 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1993-2017 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
11 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 (at your option) any later version. |
1 | 13 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
17 GNU General Public License for more details. |
1 | 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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
25 #if ! defined (octave_idx_vector_h) |
383 | 26 #define octave_idx_vector_h 1 |
1 | 27 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
28 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
29 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
30 #include <cassert> |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
31 #include <cstring> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
32 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
33 #include <algorithm> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
34 #include <iosfwd> |
13735
2cd903770748
Fix broken gcc compilation due to changeset d13b6086aea9.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13729
diff
changeset
|
35 #include <memory> |
3503 | 36 |
4653 | 37 #include "dim-vector.h" |
21785
c9f8a7f7915e
use forward declarations instead of including oct-inttypes.h where possible
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
38 #include "oct-inttypes-fwd.h" |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
39 #include "oct-refcount.h" |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
40 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
41 template <typename T> class Array; |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
42 template <typename T> class Sparse; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
43 class Range; |
4504 | 44 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
45 // Design rationale: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
46 // 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
|
47 // 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
|
48 // Polymorphic methods for single element access are provided, as well as |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
49 // templates implementing "early dispatch", i.e., hoisting the checks for index |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
50 // type out of loops. |
164 | 51 |
453 | 52 class |
6108 | 53 OCTAVE_API |
453 | 54 idx_vector |
1 | 55 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
56 public: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
58 enum idx_class_type |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 class_invalid = -1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 class_colon = 0, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 class_range, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 class_scalar, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 class_vector, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 class_mask |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 }; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
67 |
21326
9a49c83cb360
Fix declaration of template friend class std::unique_ptr
Mike Miller <mtmiller@octave.org>
parents:
21307
diff
changeset
|
68 template <typename T, typename D> friend class std::unique_ptr; |
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
|
69 |
1560 | 70 private: |
71 | |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
72 class OCTAVE_API idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
73 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
74 public: |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
75 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
76 idx_base_rep (void) : count (1), err (false) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
77 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
78 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
79 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
80 idx_base_rep (const idx_base_rep&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
81 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
82 idx_base_rep& operator = (const idx_base_rep&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
83 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
84 virtual ~idx_base_rep (void) = default; |
8290
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 // Non-range-checking element query. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
87 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
|
88 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
89 // Range-checking element query. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
90 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
|
91 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
92 // Length of the index vector. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
93 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
|
94 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
95 // The maximum index + 1. The actual dimension is passed in. |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
96 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
|
97 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
98 // Index class. |
8333 | 99 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
|
100 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
101 // Sorts, maybe uniqifies, and returns a clone object pointer. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
102 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
|
103 // Sorts, and returns a sorting permutation (aka Array::sort). |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
104 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
|
105 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
106 // Checks whether the index is colon or a range equivalent to colon. |
10487 | 107 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
|
108 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 // The original dimensions of object (used when subscribing by matrices). |
10487 | 110 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
|
111 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
112 // i/o |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
113 virtual std::ostream& print (std::ostream& os) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
114 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
115 virtual Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
116 |
23012
27e4ec3b0b49
move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
117 octave::refcount<int> count; |
8290
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 bool err; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
120 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
121 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
122 // The magic colon index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
123 class OCTAVE_API idx_colon_rep : public idx_base_rep |
1879 | 124 { |
125 public: | |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
126 |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
127 idx_colon_rep (void) = default; |
1879 | 128 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
129 idx_colon_rep (char c); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
130 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
131 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
132 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
133 idx_colon_rep (const idx_colon_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
134 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
135 idx_colon_rep& operator = (const idx_colon_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
136 |
10487 | 137 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
|
138 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
139 octave_idx_type checkelem (octave_idx_type i) const; |
1560 | 140 |
10487 | 141 octave_idx_type length (octave_idx_type n) const { return n; } |
1560 | 142 |
10487 | 143 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
|
144 |
8333 | 145 idx_class_type idx_class (void) const { return class_colon; } |
1879 | 146 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
147 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
|
148 { count++; return this; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
149 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
150 OCTAVE_NORETURN idx_base_rep * sort_idx (Array<octave_idx_type>&); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
151 |
10487 | 152 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
|
153 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
154 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
155 }; |
2386 | 156 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
157 // To distinguish the "direct" constructors that blindly trust the data. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
158 enum direct { DIRECT }; |
2828 | 159 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
160 // The integer range index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
161 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
|
162 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
163 public: |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
164 |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
165 idx_range_rep (void) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
166 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
167 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
|
168 octave_idx_type _step, direct) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
169 : idx_base_rep (), start(_start), len(_len), step(_step) { } |
4938 | 170 |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
171 // Zero-based constructor. |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
172 idx_range_rep (octave_idx_type _start, octave_idx_type _limit, |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
173 octave_idx_type _step); |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
174 |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
175 idx_range_rep (const Range&); |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
176 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
177 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
178 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
179 idx_range_rep (const idx_range_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
180 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
181 idx_range_rep& operator = (const idx_range_rep& idx) = delete; |
1560 | 182 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
183 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
|
184 { return start + i * step; } |
1560 | 185 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
186 octave_idx_type checkelem (octave_idx_type i) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
187 |
10487 | 188 octave_idx_type length (octave_idx_type) const { return len; } |
1560 | 189 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
190 octave_idx_type extent (octave_idx_type n) const |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
191 { |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
192 return len ? std::max (n, start + 1 + (step < 0 ? 0 : step * (len - 1))) |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
193 : n; |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
194 } |
1560 | 195 |
8333 | 196 idx_class_type idx_class (void) const { return class_range; } |
1879 | 197 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
198 idx_base_rep * sort_uniq_clone (bool uniq = false); |
1560 | 199 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
200 idx_base_rep * sort_idx (Array<octave_idx_type>&); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
201 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
202 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
|
203 { return start == 0 && step == 1 && len == n; } |
1560 | 204 |
8333 | 205 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
|
206 { return dim_vector (1, len); } |
1560 | 207 |
8333 | 208 octave_idx_type get_start (void) const { return start; } |
1560 | 209 |
8333 | 210 octave_idx_type get_step (void) const { return step; } |
1560 | 211 |
3504 | 212 std::ostream& print (std::ostream& os) const; |
1560 | 213 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
214 Range unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
215 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
216 Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
217 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
218 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
219 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
220 octave_idx_type start, len, step; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
221 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
222 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
223 // The integer scalar index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
224 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
|
225 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
226 public: |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
227 |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
228 idx_scalar_rep (void) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
229 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
230 idx_scalar_rep (octave_idx_type i, direct) |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
231 : idx_base_rep (), data (i) { } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
232 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
233 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
234 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
235 idx_scalar_rep (const idx_scalar_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
236 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
237 idx_scalar_rep& operator = (const idx_scalar_rep& idx) = delete; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
238 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
239 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
240 idx_scalar_rep (octave_idx_type i); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
241 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
242 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
243 idx_scalar_rep (T x); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
244 |
10487 | 245 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
|
246 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
247 octave_idx_type checkelem (octave_idx_type i) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
248 |
10487 | 249 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
|
250 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
251 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
|
252 { return std::max (n, data + 1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
253 |
8333 | 254 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
|
255 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
256 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
|
257 { count++; return this; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
258 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
259 idx_base_rep * sort_idx (Array<octave_idx_type>&); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
260 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
261 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
|
262 { return n == 1 && data == 0; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
263 |
10487 | 264 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
|
265 |
8333 | 266 octave_idx_type get_data (void) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
267 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
268 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
269 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
270 double unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
271 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
272 Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
273 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
274 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
275 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
276 octave_idx_type data; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
277 }; |
4504 | 278 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
279 // The integer vector index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
280 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
|
281 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
282 public: |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
283 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
284 idx_vector_rep (void) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
285 : data (0), len (0), ext (0), aowner (0), orig_dims () |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
286 { } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
287 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
288 // Direct constructor. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
289 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
|
290 octave_idx_type _ext, const dim_vector& od, direct) |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
291 : idx_base_rep (), data (_data), len (_len), ext (_ext), |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
292 aowner (0), orig_dims (od) |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
293 { } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
294 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
295 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
296 idx_vector_rep (const Array<octave_idx_type>& inda); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
297 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
298 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
|
299 octave_idx_type _ext, direct); |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
300 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
301 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
302 idx_vector_rep (const Array<T>&); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
303 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
304 idx_vector_rep (bool); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
305 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
306 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
|
307 |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
308 idx_vector_rep (const Sparse<bool>&); |
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
309 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
310 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
311 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
312 idx_vector_rep (const idx_vector_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
313 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
314 idx_vector_rep& operator = (const idx_vector_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
315 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
316 ~idx_vector_rep (void); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
317 |
10487 | 318 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
|
319 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
320 octave_idx_type checkelem (octave_idx_type i) const; |
4653 | 321 |
10487 | 322 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
|
323 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
324 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
|
325 { return std::max (n, ext); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
326 |
8333 | 327 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
|
328 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
329 idx_base_rep * sort_uniq_clone (bool uniq = false); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
330 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
331 idx_base_rep * sort_idx (Array<octave_idx_type>&); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
332 |
10487 | 333 dim_vector orig_dimensions (void) const { return orig_dims; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
334 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
335 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
|
336 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
337 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
338 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
339 Array<double> unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
340 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
341 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
|
342 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
343 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
344 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
345 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
|
346 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
|
347 octave_idx_type ext; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
348 |
10487 | 349 // This is a trick to allow user-given zero-based arrays to be used |
350 // as indices without copying. If the following pointer is nonzero, | |
351 // we do not own the data, but rather have an Array<octave_idx_type> | |
352 // object that provides us the data. Note that we need a pointer | |
353 // because we deferred the Array<T> declaration and we do not want | |
354 // it yet to be defined. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
355 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
356 Array<octave_idx_type> *aowner; |
1560 | 357 |
4653 | 358 dim_vector orig_dims; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
359 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
360 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
361 // The logical mask index. |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
362 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
|
363 { |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
364 public: |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
365 |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
366 idx_mask_rep (void) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
367 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
368 // Direct constructor. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
369 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
|
370 octave_idx_type _ext, const dim_vector& od, direct) |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
371 : idx_base_rep (), data (_data), len (_len), ext (_ext), |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
372 lsti (-1), lste (-1), aowner (0), orig_dims (od) |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
373 { } |
9879
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 idx_mask_rep (bool); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
376 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
377 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
|
378 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
379 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
380 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
381 idx_mask_rep (const idx_mask_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
382 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
383 idx_mask_rep& operator = (const idx_mask_rep& idx) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
384 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
385 ~idx_mask_rep (void); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
386 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
387 octave_idx_type xelem (octave_idx_type i) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
388 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
389 octave_idx_type checkelem (octave_idx_type i) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
390 |
10487 | 391 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
|
392 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
393 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
|
394 { return std::max (n, ext); } |
9879
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 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
|
397 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
398 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
|
399 { count++; return this; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
400 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
401 idx_base_rep * sort_idx (Array<octave_idx_type>&); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
402 |
10487 | 403 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
|
404 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
405 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
|
406 { return len == n && ext == n; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
407 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
408 const bool * get_data (void) const { return data; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
409 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
410 std::ostream& print (std::ostream& os) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
411 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
412 Array<bool> unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
413 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10339
diff
changeset
|
414 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
|
415 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
416 private: |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
417 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
418 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
|
419 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
|
420 octave_idx_type ext; |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
421 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
422 // FIXME: I'm not sure if this is a good design. Maybe it would be |
10487 | 423 // 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
|
424 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
|
425 mutable octave_idx_type lste; |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
426 |
10487 | 427 // This is a trick to allow user-given mask arrays to be used as |
428 // indices without copying. If the following pointer is nonzero, we | |
429 // do not own the data, but rather have an Array<bool> object that | |
430 // provides us the data. Note that we need a pointer because we | |
431 // deferred the Array<T> declaration and we do not want it yet to be | |
432 // defined. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
433 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
434 Array<bool> *aowner; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
435 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
436 dim_vector orig_dims; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
437 }; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
438 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
439 idx_vector (idx_base_rep *r) : rep (r) { } |
1560 | 440 |
10487 | 441 // The shared empty vector representation (for fast default |
442 // constructor). | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
443 static idx_vector_rep *nil_rep (void); |
4938 | 444 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
445 // The shared empty vector representation with the error flag set. |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
446 static idx_vector_rep *err_rep (void); |
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 |
23015
198fbbf6934a
new idx_vector (F77_INT) constructor
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
470 #if OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_IDX_TYPE |
198fbbf6934a
new idx_vector (F77_INT) constructor
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
471 idx_vector (octave_f77_int_type i) |
198fbbf6934a
new idx_vector (F77_INT) constructor
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
472 : rep (new idx_scalar_rep (static_cast<octave_idx_type> (i))) |
198fbbf6934a
new idx_vector (F77_INT) constructor
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
473 { chkerr (); } |
198fbbf6934a
new idx_vector (F77_INT) constructor
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
474 #endif |
198fbbf6934a
new idx_vector (F77_INT) constructor
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
475 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
476 idx_vector (octave_idx_type start, octave_idx_type limit, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
477 octave_idx_type step = 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
478 : 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
|
479 { chkerr (); } |
1560 | 480 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
481 static idx_vector |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
482 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
|
483 octave_idx_type len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 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
|
486 } |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
487 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
488 idx_vector (const Array<octave_idx_type>& inda) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
489 : 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
|
490 { chkerr (); } |
1560 | 491 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
492 // Directly pass extent, no checking. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
493 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
|
494 : 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
|
495 { } |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
496 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
497 // 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
|
498 static const idx_vector colon; |
4938 | 499 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
500 // or passing ':' here |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
501 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
|
502 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
503 // Conversion constructors (used by interpreter). |
1560 | 504 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
505 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
506 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
|
507 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
508 idx_vector (double x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
2386 | 509 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
510 idx_vector (float x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
3928 | 511 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
512 // 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
|
513 idx_vector (bool x) : rep (new idx_mask_rep (x)) { chkerr (); } |
1560 | 514 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
515 template <typename T> |
23534
b6498c088fca
maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents:
23496
diff
changeset
|
516 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
|
517 { chkerr (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
518 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
519 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
|
520 { chkerr (); } |
2828 | 521 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
522 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
|
523 { chkerr (); } |
4938 | 524 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
525 idx_vector (const Array<bool>& nda); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
526 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
527 idx_vector (const Range& r) |
10489
d47802f0e557
Back out changeset 4e64fbbd5c58
Jaroslav Hajek <highegg@gmail.com>
parents:
10487
diff
changeset
|
528 : 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
|
529 { chkerr (); } |
2828 | 530 |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
531 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
|
532 { chkerr (); } |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
533 |
4979 | 534 idx_vector (const idx_vector& a) : rep (a.rep) { rep->count++; } |
1551 | 535 |
2802 | 536 ~idx_vector (void) |
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 (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 delete rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
540 } |
1 | 541 |
1560 | 542 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
|
543 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
544 if (this != &a) |
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 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
547 delete rep; |
1 | 548 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
549 rep = a.rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
550 rep->count++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
551 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
552 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
553 } |
1551 | 554 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
555 idx_class_type idx_class (void) const { return rep->idx_class (); } |
1560 | 556 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
557 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
|
558 { return rep->length (n); } |
191 | 559 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
560 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
|
561 { return rep->extent (n); } |
1 | 562 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
563 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
|
564 { return rep->xelem (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
565 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
566 octave_idx_type checkelem (octave_idx_type n) const |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
567 { return rep->xelem (n); } |
1551 | 568 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
569 octave_idx_type operator () (octave_idx_type n) const |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
570 { return rep->xelem (n); } |
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
611 // Slice with specializations. No checking of bounds! |
8290
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 // |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
619 template <typename T> |
8290
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: |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23401
diff
changeset
|
628 std::copy_n (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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
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) |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23401
diff
changeset
|
638 std::copy_n (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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
653 idx_scalar_rep *r = dynamic_cast<idx_scalar_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
660 idx_vector_rep *r = dynamic_cast<idx_vector_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
669 idx_mask_rep *r = dynamic_cast<idx_mask_rep *> (rep); |
17769
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
685 // Slice assignment with specializations. No checking of bounds! |
8290
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 // |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
693 template <typename T> |
8290
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: |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23401
diff
changeset
|
702 std::copy_n (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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
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) |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23401
diff
changeset
|
712 std::copy_n (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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
725 idx_scalar_rep *r = dynamic_cast<idx_scalar_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
732 idx_vector_rep *r = dynamic_cast<idx_vector_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
741 idx_mask_rep *r = dynamic_cast<idx_mask_rep *> (rep); |
17769
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
757 // Slice fill with specializations. No checking of bounds! |
8290
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 // |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
765 template <typename T> |
8290
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: |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23401
diff
changeset
|
774 std::fill_n (dest, len, val); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
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) |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23401
diff
changeset
|
784 std::fill_n (sdest, len, val); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
797 idx_scalar_rep *r = dynamic_cast<idx_scalar_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
804 idx_vector_rep *r = dynamic_cast<idx_vector_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
813 idx_mask_rep *r = dynamic_cast<idx_mask_rep *> (rep); |
17769
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
829 // Generic non-breakable indexed loop. The loop body should be |
10487 | 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 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
835 template <typename Functor> |
8934
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
864 idx_scalar_rep *r = dynamic_cast<idx_scalar_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
871 idx_vector_rep *r = dynamic_cast<idx_vector_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
879 idx_mask_rep *r = dynamic_cast<idx_mask_rep *> (rep); |
17769
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
894 // Generic breakable indexed loop. The loop body should be |
10487 | 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 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
903 template <typename Functor> |
8290
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
937 idx_scalar_rep *r = dynamic_cast<idx_scalar_rep *> (rep); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
938 ret = (body (r->get_data ()) ? 1 : 0); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
944 idx_vector_rep *r = dynamic_cast<idx_vector_rep *> (rep); |
17769
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 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
954 idx_mask_rep *r = dynamic_cast<idx_mask_rep *> (rep); |
17769
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: |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
1003 // Returns the inverse permutation. If this is not a permutation on 1:n, the |
10512
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 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
1007 // Copies all the indices to a given array. Not allowed for colons. |
9479
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. | |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23432
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 |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
1024 bool isvector (void) const; |
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
1025 |
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
1026 OCTAVE_DEPRECATED ("use 'isvector' instead") |
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
1027 bool is_vector (void) const |
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
1028 { return isvector (); } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1029 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1030 // FIXME: these are here for compatibility. They should be removed |
8333 | 1031 // when no longer in use. |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1032 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1033 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
|
1034 { return (*this) (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1035 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1036 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
|
1037 { return is_colon_equiv (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1038 |
8333 | 1039 octave_idx_type |
1040 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
|
1041 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1042 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
|
1043 { *this = sorted (uniq); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1044 |
8333 | 1045 octave_idx_type ones_count (void) const; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1046 |
8333 | 1047 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
|
1048 |
1 | 1049 private: |
1050 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1051 idx_base_rep *rep; |
1 | 1052 |
1053 }; | |
1054 | |
1055 #endif |