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