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 { |
4569
|
51 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR), true); |
4514
|
52 } |
|
53 |
4556
|
54 boolNDArray |
4514
|
55 boolNDArray::any (int dim) const |
|
56 { |
4569
|
57 MX_ND_ANY_ALL_REDUCTION (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR), false); |
4514
|
58 } |
|
59 |
7113
|
60 boolNDArray |
|
61 boolNDArray::sum (int dim) const |
|
62 { |
|
63 MX_ND_REDUCTION (retval(result_idx) |= elem (iter_idx), true, boolNDArray); |
|
64 } |
|
65 |
4964
|
66 boolNDArray |
5275
|
67 boolNDArray::concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4964
|
68 { |
|
69 if (rb.numel () > 0) |
5073
|
70 insert (rb, ra_idx); |
|
71 return *this; |
4964
|
72 } |
|
73 |
|
74 boolNDArray& |
5275
|
75 boolNDArray::insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c) |
4964
|
76 { |
|
77 Array<bool>::insert (a, r, c); |
|
78 return *this; |
|
79 } |
|
80 |
|
81 boolNDArray& |
5275
|
82 boolNDArray::insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx) |
4964
|
83 { |
|
84 Array<bool>::insert (a, ra_idx); |
|
85 return *this; |
|
86 } |
|
87 |
|
88 |
|
89 |
4514
|
90 boolMatrix |
|
91 boolNDArray::matrix_value (void) const |
|
92 { |
|
93 boolMatrix retval; |
|
94 |
|
95 int nd = ndims (); |
|
96 |
|
97 switch (nd) |
|
98 { |
|
99 case 1: |
|
100 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); |
|
101 break; |
|
102 |
|
103 case 2: |
|
104 retval = boolMatrix (Array2<bool> (*this, dimensions(0), |
|
105 dimensions(1))); |
|
106 break; |
|
107 |
|
108 default: |
|
109 (*current_liboctave_error_handler) |
4770
|
110 ("invalid conversion of boolNDArray to boolMatrix"); |
4514
|
111 break; |
|
112 } |
|
113 |
|
114 return retval; |
|
115 } |
|
116 |
4532
|
117 void |
5275
|
118 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532
|
119 const dim_vector& dimensions, |
|
120 int start_dimension) |
|
121 { |
|
122 ::increment_index (ra_idx, dimensions, start_dimension); |
|
123 } |
|
124 |
5275
|
125 octave_idx_type |
|
126 boolNDArray::compute_index (Array<octave_idx_type>& ra_idx, |
4556
|
127 const dim_vector& dimensions) |
|
128 { |
|
129 return ::compute_index (ra_idx, dimensions); |
|
130 } |
|
131 |
4669
|
132 NDND_BOOL_OPS (boolNDArray, boolNDArray, false) |
4543
|
133 NDND_CMP_OPS (boolNDArray, , boolNDArray, ) |
|
134 |
4669
|
135 NDS_BOOL_OPS (boolNDArray, bool, false) |
|
136 NDS_CMP_OPS (boolNDArray, , bool, ) |
|
137 |
|
138 SND_BOOL_OPS (bool, boolNDArray, false) |
|
139 SND_CMP_OPS (bool, , boolNDArray, ) |
|
140 |
4514
|
141 /* |
|
142 ;;; Local Variables: *** |
|
143 ;;; mode: C++ *** |
|
144 ;;; End: *** |
|
145 */ |