Mercurial > hg > octave-lyh
annotate liboctave/boolNDArray.cc @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | ea76466605ba |
children | 8145f2255276 |
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" |
4514 | 34 |
4543 | 35 // unary operations |
36 | |
37 boolNDArray | |
38 boolNDArray::operator ! (void) const | |
39 { | |
40 boolNDArray b (dims ()); | |
41 | |
5275 | 42 for (octave_idx_type i = 0; i < length (); i++) |
4543 | 43 b.elem (i) = ! elem (i); |
44 | |
45 return b; | |
46 } | |
47 | |
5775 | 48 // FIXME -- this is not quite the right thing. |
4514 | 49 |
4556 | 50 boolNDArray |
4514 | 51 boolNDArray::all (int dim) const |
52 { | |
8743
1bd918cfb6e2
reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
53 return do_mx_red_op<boolNDArray> (*this, dim, mx_inline_all); |
4514 | 54 } |
55 | |
4556 | 56 boolNDArray |
4514 | 57 boolNDArray::any (int dim) const |
58 { | |
8743
1bd918cfb6e2
reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
59 return do_mx_red_op<boolNDArray> (*this, dim, mx_inline_any); |
4514 | 60 } |
61 | |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
62 NDArray |
7113 | 63 boolNDArray::sum (int dim) const |
64 { | |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
65 // 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
|
66 return do_mx_red_op<Array<octave_idx_type> > (*this, dim, mx_inline_count); |
7113 | 67 } |
68 | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
69 NDArray |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
70 boolNDArray::cumsum (int dim) const |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
71 { |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
72 // NOTE: going via octave_idx_type is faster even though it requires a conversion. |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
73 return do_mx_cum_op<Array<octave_idx_type> > (*this, dim, mx_inline_cumcount); |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
74 } |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
75 |
4964 | 76 boolNDArray |
5275 | 77 boolNDArray::concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4964 | 78 { |
79 if (rb.numel () > 0) | |
5073 | 80 insert (rb, ra_idx); |
81 return *this; | |
4964 | 82 } |
83 | |
84 boolNDArray& | |
5275 | 85 boolNDArray::insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c) |
4964 | 86 { |
87 Array<bool>::insert (a, r, c); | |
88 return *this; | |
89 } | |
90 | |
91 boolNDArray& | |
5275 | 92 boolNDArray::insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx) |
4964 | 93 { |
94 Array<bool>::insert (a, ra_idx); | |
95 return *this; | |
96 } | |
97 | |
98 | |
99 | |
4514 | 100 boolMatrix |
101 boolNDArray::matrix_value (void) const | |
102 { | |
103 boolMatrix retval; | |
104 | |
105 int nd = ndims (); | |
106 | |
107 switch (nd) | |
108 { | |
109 case 1: | |
110 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); | |
111 break; | |
112 | |
113 case 2: | |
114 retval = boolMatrix (Array2<bool> (*this, dimensions(0), | |
115 dimensions(1))); | |
116 break; | |
117 | |
118 default: | |
119 (*current_liboctave_error_handler) | |
4770 | 120 ("invalid conversion of boolNDArray to boolMatrix"); |
4514 | 121 break; |
122 } | |
123 | |
124 return retval; | |
125 } | |
126 | |
4532 | 127 void |
5275 | 128 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 129 const dim_vector& dimensions, |
130 int start_dimension) | |
131 { | |
132 ::increment_index (ra_idx, dimensions, start_dimension); | |
133 } | |
134 | |
5275 | 135 octave_idx_type |
136 boolNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
4556 | 137 const dim_vector& dimensions) |
138 { | |
139 return ::compute_index (ra_idx, dimensions); | |
140 } | |
141 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
142 boolNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
143 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
|
144 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
145 return ArrayN<bool>::diag (k); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
146 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7113
diff
changeset
|
147 |
4669 | 148 NDND_BOOL_OPS (boolNDArray, boolNDArray, false) |
4543 | 149 NDND_CMP_OPS (boolNDArray, , boolNDArray, ) |
150 | |
4669 | 151 NDS_BOOL_OPS (boolNDArray, bool, false) |
152 NDS_CMP_OPS (boolNDArray, , bool, ) | |
153 | |
154 SND_BOOL_OPS (bool, boolNDArray, false) | |
155 SND_CMP_OPS (bool, , boolNDArray, ) | |
156 | |
4514 | 157 /* |
158 ;;; Local Variables: *** | |
159 ;;; mode: C++ *** | |
160 ;;; End: *** | |
161 */ |