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