Mercurial > hg > octave-lyh
annotate liboctave/boolNDArray.cc @ 8756:d0755c9db5ed
implement fast logical sum (counting)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 16 Feb 2009 12:41:55 +0100 |
parents | 1bd918cfb6e2 |
children | b756ce0002db |
rev | line source |
---|---|
4514 | 1 // N-D Array manipulations. |
2 /* | |
3 | |
7017 | 4 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4514 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
4514 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
4514 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
4588 | 28 #include "Array-util.h" |
4514 | 29 #include "CNDArray.h" |
30 #include "mx-base.h" | |
31 #include "lo-ieee.h" | |
32 | |
4543 | 33 // unary operations |
34 | |
35 boolNDArray | |
36 boolNDArray::operator ! (void) const | |
37 { | |
38 boolNDArray b (dims ()); | |
39 | |
5275 | 40 for (octave_idx_type i = 0; i < length (); i++) |
4543 | 41 b.elem (i) = ! elem (i); |
42 | |
43 return b; | |
44 } | |
45 | |
5775 | 46 // FIXME -- this is not quite the right thing. |
4514 | 47 |
4556 | 48 boolNDArray |
4514 | 49 boolNDArray::all (int dim) const |
50 { | |
8743
1bd918cfb6e2
reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
51 return do_mx_red_op<boolNDArray> (*this, dim, mx_inline_all); |
4514 | 52 } |
53 | |
4556 | 54 boolNDArray |
4514 | 55 boolNDArray::any (int dim) const |
56 { | |
8743
1bd918cfb6e2
reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
57 return do_mx_red_op<boolNDArray> (*this, dim, mx_inline_any); |
4514 | 58 } |
59 | |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
60 NDArray |
7113 | 61 boolNDArray::sum (int dim) const |
62 { | |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
63 // NOTE: going via octave_idx_type is faster even though it requires a conversion. |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
64 return do_mx_red_op<Array<octave_idx_type> > (*this, dim, mx_inline_count); |
7113 | 65 } |
66 | |
4964 | 67 boolNDArray |
5275 | 68 boolNDArray::concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4964 | 69 { |
70 if (rb.numel () > 0) | |
5073 | 71 insert (rb, ra_idx); |
72 return *this; | |
4964 | 73 } |
74 | |
75 boolNDArray& | |
5275 | 76 boolNDArray::insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c) |
4964 | 77 { |
78 Array<bool>::insert (a, r, c); | |
79 return *this; | |
80 } | |
81 | |
82 boolNDArray& | |
5275 | 83 boolNDArray::insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx) |
4964 | 84 { |
85 Array<bool>::insert (a, ra_idx); | |
86 return *this; | |
87 } | |
88 | |
89 | |
90 | |
4514 | 91 boolMatrix |
92 boolNDArray::matrix_value (void) const | |
93 { | |
94 boolMatrix retval; | |
95 | |
96 int nd = ndims (); | |
97 | |
98 switch (nd) | |
99 { | |
100 case 1: | |
101 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); | |
102 break; | |
103 | |
104 case 2: | |
105 retval = boolMatrix (Array2<bool> (*this, dimensions(0), | |
106 dimensions(1))); | |
107 break; | |
108 | |
109 default: | |
110 (*current_liboctave_error_handler) | |
4770 | 111 ("invalid conversion of boolNDArray to boolMatrix"); |
4514 | 112 break; |
113 } | |
114 | |
115 return retval; | |
116 } | |
117 | |
4532 | 118 void |
5275 | 119 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 120 const dim_vector& dimensions, |
121 int start_dimension) | |
122 { | |
123 ::increment_index (ra_idx, dimensions, start_dimension); | |
124 } | |
125 | |
5275 | 126 octave_idx_type |
127 boolNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
4556 | 128 const dim_vector& dimensions) |
129 { | |
130 return ::compute_index (ra_idx, dimensions); | |
131 } | |
132 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
133 boolNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
134 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
|
135 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
136 return ArrayN<bool>::diag (k); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
137 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
138 |
4669 | 139 NDND_BOOL_OPS (boolNDArray, boolNDArray, false) |
4543 | 140 NDND_CMP_OPS (boolNDArray, , boolNDArray, ) |
141 | |
4669 | 142 NDS_BOOL_OPS (boolNDArray, bool, false) |
143 NDS_CMP_OPS (boolNDArray, , bool, ) | |
144 | |
145 SND_BOOL_OPS (bool, boolNDArray, false) | |
146 SND_CMP_OPS (bool, , boolNDArray, ) | |
147 | |
4514 | 148 /* |
149 ;;; Local Variables: *** | |
150 ;;; mode: C++ *** | |
151 ;;; End: *** | |
152 */ |