4514
|
1 // N-D Array manipulations. |
|
2 /* |
|
3 |
|
4 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
21 02110-1301, USA. |
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" |
|
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 { |
4569
|
52 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR), true); |
4514
|
53 } |
|
54 |
4556
|
55 boolNDArray |
4514
|
56 boolNDArray::any (int dim) const |
|
57 { |
4569
|
58 MX_ND_ANY_ALL_REDUCTION (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR), false); |
4514
|
59 } |
|
60 |
4964
|
61 boolNDArray |
5275
|
62 boolNDArray::concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4964
|
63 { |
|
64 if (rb.numel () > 0) |
5073
|
65 insert (rb, ra_idx); |
|
66 return *this; |
4964
|
67 } |
|
68 |
|
69 boolNDArray& |
5275
|
70 boolNDArray::insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c) |
4964
|
71 { |
|
72 Array<bool>::insert (a, r, c); |
|
73 return *this; |
|
74 } |
|
75 |
|
76 boolNDArray& |
5275
|
77 boolNDArray::insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx) |
4964
|
78 { |
|
79 Array<bool>::insert (a, ra_idx); |
|
80 return *this; |
|
81 } |
|
82 |
|
83 |
|
84 |
4514
|
85 boolMatrix |
|
86 boolNDArray::matrix_value (void) const |
|
87 { |
|
88 boolMatrix retval; |
|
89 |
|
90 int nd = ndims (); |
|
91 |
|
92 switch (nd) |
|
93 { |
|
94 case 1: |
|
95 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); |
|
96 break; |
|
97 |
|
98 case 2: |
|
99 retval = boolMatrix (Array2<bool> (*this, dimensions(0), |
|
100 dimensions(1))); |
|
101 break; |
|
102 |
|
103 default: |
|
104 (*current_liboctave_error_handler) |
4770
|
105 ("invalid conversion of boolNDArray to boolMatrix"); |
4514
|
106 break; |
|
107 } |
|
108 |
|
109 return retval; |
|
110 } |
|
111 |
4532
|
112 void |
5275
|
113 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532
|
114 const dim_vector& dimensions, |
|
115 int start_dimension) |
|
116 { |
|
117 ::increment_index (ra_idx, dimensions, start_dimension); |
|
118 } |
|
119 |
5275
|
120 octave_idx_type |
|
121 boolNDArray::compute_index (Array<octave_idx_type>& ra_idx, |
4556
|
122 const dim_vector& dimensions) |
|
123 { |
|
124 return ::compute_index (ra_idx, dimensions); |
|
125 } |
|
126 |
4669
|
127 NDND_BOOL_OPS (boolNDArray, boolNDArray, false) |
4543
|
128 NDND_CMP_OPS (boolNDArray, , boolNDArray, ) |
|
129 |
4669
|
130 NDS_BOOL_OPS (boolNDArray, bool, false) |
|
131 NDS_CMP_OPS (boolNDArray, , bool, ) |
|
132 |
|
133 SND_BOOL_OPS (bool, boolNDArray, false) |
|
134 SND_CMP_OPS (bool, , boolNDArray, ) |
|
135 |
4514
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |