Mercurial > octave
annotate liboctave/array/Array-b.cc @ 29569:29a1f8fd8ee6
move idx_vector classes inside octave namespace
* idx-vector.h, idx-vector.cc:
Move idx_vector classes inside octave namespace. Update all uses
outside of octave namespace to use octave:: tag.
* Sparse.h: Eliminate forward declaration of idx_vector.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 28 Apr 2021 13:46:02 -0400 |
parents | 7854d5752dd2 |
children | 796f54d4ddbf |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 1996-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2493 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21574
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21213
diff
changeset
|
27 # include "config.h" |
2493 | 28 #endif |
29 | |
30 // Instantiate Arrays of bool values. | |
31 | |
32 #include "Array.h" | |
33 #include "Array.cc" | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
34 |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
35 #define INLINE_ASCENDING_SORT 1 |
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
36 #define INLINE_DESCENDING_SORT 1 |
7433 | 37 #include "oct-sort.cc" |
38 | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
39 // Prevent implicit instantiations on some systems (Windows, others?) |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
40 // that can lead to duplicate definitions of static data members. |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
41 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
42 extern template class Array<octave::idx_vector>; |
29225
a65ff1d4f75b
Remove API tag when instantiating Array template class (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
43 extern template class Array<octave_idx_type>; |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
44 |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
45 // Specialize bool sorting (aka stable partitioning). |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
46 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
47 template <bool desc> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
48 static void do_bool_partition (bool *data, octave_idx_type nel) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
49 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
50 octave_idx_type k = 0; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
51 for (octave_idx_type i = 0; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
52 if (data[i] == desc) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
53 data[k++] = desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
54 for (octave_idx_type i = k; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
55 data[i] = ! desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
56 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
57 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
58 template <bool desc> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 static void do_bool_partition (bool *data, octave_idx_type *idx, |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
60 octave_idx_type nel) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
61 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
62 // FIXME: This is essentially a simple bucket sort. |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
63 // Can it be efficiently done by std::partition? |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
64 OCTAVE_LOCAL_BUFFER (octave_idx_type, jdx, nel); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
65 octave_idx_type k = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
66 octave_idx_type l = 0; |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
67 for (octave_idx_type i = 0; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
68 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
69 if (data[i] == desc) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
70 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
71 data[k] = desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
72 idx[k++] = idx[i]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
73 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
74 else |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
75 jdx[l++] = idx[i]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
76 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
77 |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
78 for (octave_idx_type i = k; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
79 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
80 data[i] = ! desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
81 idx[i] = jdx[i-k]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
82 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
83 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
84 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
85 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
86 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
87 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
88 octave_sort<bool>::sort (bool *data, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
89 std::less<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
90 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
91 do_bool_partition<false> (data, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
92 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
93 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
94 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
95 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
96 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
97 octave_sort<bool>::sort (bool *data, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
98 std::greater<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
99 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
100 do_bool_partition<true> (data, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
101 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
102 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
103 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
104 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
105 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
106 octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
107 std::less<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
108 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
109 do_bool_partition<false> (data, idx, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
110 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
111 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
112 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
113 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
114 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
115 octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
116 std::greater<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
117 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
118 do_bool_partition<true> (data, idx, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
119 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
120 |
29225
a65ff1d4f75b
Remove API tag when instantiating Array template class (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
121 template class octave_sort<bool>; |
2493 | 122 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
123 INSTANTIATE_ARRAY (bool, OCTAVE_API); |
3836 | 124 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 template OCTAVE_API std::ostream& operator << (std::ostream&, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
126 const Array<bool>&); |
4513 | 127 |
2826 | 128 #include "DiagArray2.h" |
129 #include "DiagArray2.cc" | |
130 | |
29225
a65ff1d4f75b
Remove API tag when instantiating Array template class (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
131 template class DiagArray2<bool>; |