Mercurial > octave
annotate liboctave/array/Array-b.cc @ 33639:65b1cf6aa60a bytecode-interpreter tip
maint: Merge default to bytecode-interpreter
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Mon, 03 Jun 2024 14:38:47 -0400 |
parents | 2e484f9f1f18 |
children |
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 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
32590
diff
changeset
|
3 // Copyright (C) 1996-2024 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" | |
31400
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
33 |
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
34 // Prevent implicit instantiations on some systems (Windows, others?) |
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
35 // that can lead to duplicate definitions of static data members. |
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
36 |
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
37 extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>; |
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
38 extern template class Array<octave_idx_type>; |
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
39 |
31396
7e60506a5428
Prevent implicit instantiations of the Array class template (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
40 #include "Array-base.cc" |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
41 |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
42 #define INLINE_ASCENDING_SORT 1 |
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
43 #define INLINE_DESCENDING_SORT 1 |
7433 | 44 #include "oct-sort.cc" |
45 | |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
46 // Specialize bool sorting (aka stable partitioning). |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
47 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
48 template <bool desc> |
32590
3c2c585965cc
maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
49 static void |
3c2c585965cc
maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
50 do_bool_partition (bool *data, octave_idx_type nel) |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
51 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
52 octave_idx_type k = 0; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
53 for (octave_idx_type i = 0; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
54 if (data[i] == desc) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
55 data[k++] = desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
56 for (octave_idx_type i = k; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
57 data[i] = ! desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
58 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
59 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
60 template <bool desc> |
32590
3c2c585965cc
maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
61 static void |
3c2c585965cc
maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
62 do_bool_partition (bool *data, octave_idx_type *idx, |
3c2c585965cc
maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
63 octave_idx_type nel) |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
64 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
65 // FIXME: This is essentially a simple bucket sort. |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
66 // Can it be efficiently done by std::partition? |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
67 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
|
68 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
|
69 octave_idx_type l = 0; |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
70 for (octave_idx_type i = 0; i < nel; i++) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
71 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
72 if (data[i] == desc) |
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 data[k] = desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
75 idx[k++] = 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 else |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
78 jdx[l++] = idx[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 |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
81 for (octave_idx_type i = k; i < nel; i++) |
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 data[i] = ! desc; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
84 idx[i] = jdx[i-k]; |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
85 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
86 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
87 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
88 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
89 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
90 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
91 octave_sort<bool>::sort (bool *data, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
92 std::less<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
93 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
94 do_bool_partition<false> (data, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
95 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
96 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
97 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
98 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
99 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
100 octave_sort<bool>::sort (bool *data, octave_idx_type nel, |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
101 std::greater<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
102 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
103 do_bool_partition<true> (data, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
104 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
105 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
106 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
107 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
108 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
109 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
|
110 std::less<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
111 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
112 do_bool_partition<false> (data, idx, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
113 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
114 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
115 template <> |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
116 template <> |
10114
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
117 void |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
118 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
|
119 std::greater<bool>) |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
120 { |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
121 do_bool_partition<true> (data, idx, nel); |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
122 } |
e4936c129cbd
optimize sorting of bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
123 |
29225
a65ff1d4f75b
Remove API tag when instantiating Array template class (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
124 template class octave_sort<bool>; |
2493 | 125 |
31400
e7fc6251b698
Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31396
diff
changeset
|
126 INSTANTIATE_ARRAY (bool, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API); |
3836 | 127 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
128 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
|
129 const Array<bool>&); |
4513 | 130 |
2826 | 131 #include "DiagArray2.h" |
132 #include "DiagArray2.cc" | |
133 | |
29225
a65ff1d4f75b
Remove API tag when instantiating Array template class (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
134 template class DiagArray2<bool>; |