Mercurial > hg > octave-nkf
annotate liboctave/boolNDArray.cc @ 9578:7dafdb8b062f
refactor comparison ops implementations
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 27 Aug 2009 11:19:33 +0200 |
parents | 3d6a9aea2aea |
children | a9b37bae1802 |
rev | line source |
---|---|
4514 | 1 // N-D Array manipulations. |
2 /* | |
3 | |
8920 | 4 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007, 2008, |
5 2009 John W. Eaton | |
4514 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
4514 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
4514 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
4588 | 29 #include "Array-util.h" |
4514 | 30 #include "CNDArray.h" |
31 #include "mx-base.h" | |
32 #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
|
33 #include "mx-op-defs.h" |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
34 #include "MArray-defs.h" |
4514 | 35 |
4543 | 36 // unary operations |
37 | |
38 boolNDArray | |
39 boolNDArray::operator ! (void) const | |
40 { | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
41 return do_mx_unary_op<boolNDArray> (*this, mx_inline_not); |
4543 | 42 } |
43 | |
5775 | 44 // FIXME -- this is not quite the right thing. |
4514 | 45 |
4556 | 46 boolNDArray |
4514 | 47 boolNDArray::all (int dim) const |
48 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
49 return do_mx_red_op<boolNDArray, bool> (*this, dim, mx_inline_all); |
4514 | 50 } |
51 | |
4556 | 52 boolNDArray |
4514 | 53 boolNDArray::any (int dim) const |
54 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
55 return do_mx_red_op<boolNDArray, bool> (*this, dim, mx_inline_any); |
4514 | 56 } |
57 | |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
58 NDArray |
7113 | 59 boolNDArray::sum (int dim) const |
60 { | |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
61 // NOTE: going via octave_idx_type is faster even though it requires a conversion. |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
62 return do_mx_red_op<Array<octave_idx_type> , bool> (*this, dim, mx_inline_count); |
7113 | 63 } |
64 | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
65 NDArray |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
66 boolNDArray::cumsum (int dim) const |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
67 { |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
68 // NOTE: going via octave_idx_type is faster even though it requires a conversion. |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
69 return do_mx_cum_op<Array<octave_idx_type> , bool> (*this, dim, mx_inline_cumcount); |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
70 } |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
71 |
4964 | 72 boolNDArray |
5275 | 73 boolNDArray::concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4964 | 74 { |
75 if (rb.numel () > 0) | |
5073 | 76 insert (rb, ra_idx); |
77 return *this; | |
4964 | 78 } |
79 | |
80 boolNDArray& | |
5275 | 81 boolNDArray::insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c) |
4964 | 82 { |
83 Array<bool>::insert (a, r, c); | |
84 return *this; | |
85 } | |
86 | |
87 boolNDArray& | |
5275 | 88 boolNDArray::insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx) |
4964 | 89 { |
90 Array<bool>::insert (a, ra_idx); | |
91 return *this; | |
92 } | |
93 | |
94 | |
95 | |
4514 | 96 boolMatrix |
97 boolNDArray::matrix_value (void) const | |
98 { | |
99 boolMatrix retval; | |
100 | |
101 int nd = ndims (); | |
102 | |
103 switch (nd) | |
104 { | |
105 case 1: | |
106 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); | |
107 break; | |
108 | |
109 case 2: | |
110 retval = boolMatrix (Array2<bool> (*this, dimensions(0), | |
111 dimensions(1))); | |
112 break; | |
113 | |
114 default: | |
115 (*current_liboctave_error_handler) | |
4770 | 116 ("invalid conversion of boolNDArray to boolMatrix"); |
4514 | 117 break; |
118 } | |
119 | |
120 return retval; | |
121 } | |
122 | |
4532 | 123 void |
5275 | 124 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 125 const dim_vector& dimensions, |
126 int start_dimension) | |
127 { | |
128 ::increment_index (ra_idx, dimensions, start_dimension); | |
129 } | |
130 | |
5275 | 131 octave_idx_type |
132 boolNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
4556 | 133 const dim_vector& dimensions) |
134 { | |
135 return ::compute_index (ra_idx, dimensions); | |
136 } | |
137 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
138 boolNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
139 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
|
140 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
141 return ArrayN<bool>::diag (k); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
142 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
143 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
144 NDND_BOOL_OPS (boolNDArray, boolNDArray) |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
145 NDND_CMP_OPS (boolNDArray, boolNDArray) |
4543 | 146 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
147 NDS_BOOL_OPS (boolNDArray, bool) |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
148 NDS_CMP_OPS (boolNDArray, bool) |
4669 | 149 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9548
diff
changeset
|
150 SND_BOOL_OPS (bool, boolNDArray) |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
151 SND_CMP_OPS (bool, boolNDArray) |
4669 | 152 |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
153 boolNDArray& |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
154 mx_el_and_assign (boolNDArray& a, const boolNDArray& b) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
155 { |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
156 if (a.is_shared ()) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
157 return a = mx_el_and (a, b); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
158 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
159 dim_vector a_dims = a.dims (); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
160 dim_vector b_dims = b.dims (); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
161 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
162 if (a_dims != b_dims) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
163 gripe_nonconformant ("operator &=", a_dims, b_dims); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
164 else |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
165 { |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
166 octave_idx_type l = a.length (); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
167 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
168 if (l > 0) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
169 DO_VV_OP2 (bool, a, &=, b); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
170 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
171 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
172 return a; |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
173 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
174 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
175 boolNDArray& |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
176 mx_el_or_assign (boolNDArray& a, const boolNDArray& b) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
177 { |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
178 if (a.is_shared ()) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
179 return a = mx_el_and (a, b); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
180 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
181 dim_vector a_dims = a.dims (); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
182 dim_vector b_dims = b.dims (); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
183 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
184 if (a_dims != b_dims) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
185 gripe_nonconformant ("operator |=", a_dims, b_dims); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
186 else |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
187 { |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
188 octave_idx_type l = a.length (); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
189 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
190 if (l > 0) |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
191 DO_VV_OP2 (bool, a, |=, b); |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
192 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
193 |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
194 return a; |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
195 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
196 |
4514 | 197 /* |
198 ;;; Local Variables: *** | |
199 ;;; mode: C++ *** | |
200 ;;; End: *** | |
201 */ |