Mercurial > octave
annotate liboctave/array/boolNDArray.cc @ 32632:2e484f9f1f18 stable
maint: update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 Dec 2023 12:08:17 -0500 |
parents | 21f9b34eb893 |
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:
31771
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 //////////////////////////////////////////////////////////////////////// |
4514 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
4514 | 28 #endif |
29 | |
4588 | 30 #include "Array-util.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
31 #include "boolNDArray.h" |
4514 | 32 #include "CNDArray.h" |
33 #include "mx-base.h" | |
34 #include "lo-ieee.h" | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
35 #include "mx-op-defs.h" |
4514 | 36 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
37 #include "bsxfun-defs.cc" |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
38 |
4543 | 39 // unary operations |
40 | |
41 boolNDArray | |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
42 boolNDArray::operator ! () const |
4543 | 43 { |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13139
diff
changeset
|
44 return do_mx_unary_op<bool, bool> (*this, mx_inline_not); |
4543 | 45 } |
46 | |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
47 boolNDArray& |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
48 boolNDArray::invert () |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
49 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
50 if (is_shared ()) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
51 *this = ! *this; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
52 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
53 do_mx_inplace_op<bool> (*this, mx_inline_not2); |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
54 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
55 return *this; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
56 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
57 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 // FIXME: this is not quite the right thing. |
4514 | 59 |
4556 | 60 boolNDArray |
4514 | 61 boolNDArray::all (int dim) const |
62 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
63 return do_mx_red_op<bool, bool> (*this, dim, mx_inline_all); |
4514 | 64 } |
65 | |
4556 | 66 boolNDArray |
4514 | 67 boolNDArray::any (int dim) const |
68 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
69 return do_mx_red_op<bool, bool> (*this, dim, mx_inline_any); |
4514 | 70 } |
71 | |
4964 | 72 boolNDArray |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 boolNDArray::concat (const boolNDArray& rb, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 const Array<octave_idx_type>& ra_idx) |
4964 | 75 { |
76 if (rb.numel () > 0) | |
5073 | 77 insert (rb, ra_idx); |
78 return *this; | |
4964 | 79 } |
80 | |
81 boolNDArray& | |
5275 | 82 boolNDArray::insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c) |
4964 | 83 { |
84 Array<bool>::insert (a, r, c); | |
85 return *this; | |
86 } | |
87 | |
88 boolNDArray& | |
5275 | 89 boolNDArray::insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx) |
4964 | 90 { |
91 Array<bool>::insert (a, ra_idx); | |
92 return *this; | |
93 } | |
94 | |
4532 | 95 void |
5275 | 96 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 const dim_vector& dimensions, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 int start_dimension) |
4532 | 99 { |
100 ::increment_index (ra_idx, dimensions, start_dimension); | |
101 } | |
102 | |
5275 | 103 octave_idx_type |
104 boolNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
105 const dim_vector& dimensions) |
4556 | 106 { |
107 return ::compute_index (ra_idx, dimensions); | |
108 } | |
109 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
110 boolNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
111 boolNDArray::diag (octave_idx_type k) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
112 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
113 return Array<bool>::diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
114 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
115 |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
116 boolNDArray |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
117 boolNDArray::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
118 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
119 return Array<bool>::diag (m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
120 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
121 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
122 NDND_BOOL_OPS (boolNDArray, boolNDArray) |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
123 NDND_CMP_OPS (boolNDArray, boolNDArray) |
4543 | 124 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
125 NDS_BOOL_OPS (boolNDArray, bool) |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
126 NDS_CMP_OPS (boolNDArray, bool) |
4669 | 127 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
128 SND_BOOL_OPS (bool, boolNDArray) |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
129 SND_CMP_OPS (bool, boolNDArray) |
4669 | 130 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
131 boolNDArray& |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
132 mx_el_and_assign (boolNDArray& a, const boolNDArray& b) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
133 { |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
134 if (a.is_shared ()) |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9607
diff
changeset
|
135 a = mx_el_and (a, b); |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
136 else |
13139
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
137 do_mm_inplace_op<bool, bool> (a, b, mx_inline_and2, mx_inline_and2, |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
138 "operator &="); |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
139 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
140 return a; |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
141 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
142 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
143 boolNDArray& |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
144 mx_el_or_assign (boolNDArray& a, const boolNDArray& b) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
145 { |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
146 if (a.is_shared ()) |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9607
diff
changeset
|
147 a = mx_el_or (a, b); |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
148 else |
13139
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
149 do_mm_inplace_op<bool, bool> (a, b, mx_inline_or2, mx_inline_or2, |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
150 "operator |="); |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
151 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
152 return a; |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
153 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
154 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
155 BSXFUN_OP_DEF_MXLOOP (and, boolNDArray, mx_inline_and) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
156 BSXFUN_OP_DEF_MXLOOP (or, boolNDArray, mx_inline_or) |