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 |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #ifdef HAVE_CONFIG_H |
|
29 #include <config.h> |
|
30 #endif |
|
31 |
|
32 #include "CNDArray.h" |
|
33 #include "mx-base.h" |
|
34 #include "lo-ieee.h" |
|
35 |
4532
|
36 #include "ArrayN-inline.h" |
|
37 |
4543
|
38 // unary operations |
|
39 |
|
40 boolNDArray |
|
41 boolNDArray::operator ! (void) const |
|
42 { |
|
43 boolNDArray b (dims ()); |
|
44 |
|
45 for (int i = 0; i < length (); i++) |
|
46 b.elem (i) = ! elem (i); |
|
47 |
|
48 return b; |
|
49 } |
|
50 |
4514
|
51 // XXX FIXME XXX -- this is not quite the right thing. |
|
52 |
|
53 boolMatrix |
|
54 boolNDArray::all (int dim) const |
|
55 { |
|
56 boolMatrix retval; |
|
57 |
|
58 if (dimensions.length () == 2) |
|
59 { |
|
60 boolMatrix tmp = matrix_value (); |
|
61 retval = tmp.all (dim); |
|
62 } |
|
63 else |
|
64 (*current_liboctave_error_handler) |
|
65 ("all is not yet implemented for N-d Arrays"); |
|
66 |
|
67 return retval; |
|
68 } |
|
69 |
|
70 boolMatrix |
|
71 boolNDArray::any (int dim) const |
|
72 { |
|
73 boolMatrix retval; |
|
74 |
|
75 if (dimensions.length () == 2) |
|
76 { |
|
77 boolMatrix tmp = matrix_value (); |
|
78 retval = tmp.any (dim); |
|
79 } |
|
80 else |
|
81 (*current_liboctave_error_handler) |
|
82 ("any is not yet implemented for N-d Arrays"); |
|
83 |
|
84 return retval; |
|
85 } |
|
86 |
|
87 boolMatrix |
|
88 boolNDArray::matrix_value (void) const |
|
89 { |
|
90 boolMatrix retval; |
|
91 |
|
92 int nd = ndims (); |
|
93 |
|
94 switch (nd) |
|
95 { |
|
96 case 1: |
|
97 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); |
|
98 break; |
|
99 |
|
100 case 2: |
|
101 retval = boolMatrix (Array2<bool> (*this, dimensions(0), |
|
102 dimensions(1))); |
|
103 break; |
|
104 |
|
105 default: |
|
106 (*current_liboctave_error_handler) |
|
107 ("invalid converstion of boolNDArray to boolMatrix"); |
|
108 break; |
|
109 } |
|
110 |
|
111 return retval; |
|
112 } |
|
113 |
4532
|
114 void |
|
115 boolNDArray::increment_index (Array<int>& ra_idx, |
|
116 const dim_vector& dimensions, |
|
117 int start_dimension) |
|
118 { |
|
119 ::increment_index (ra_idx, dimensions, start_dimension); |
|
120 } |
|
121 |
4543
|
122 NDND_CMP_OPS (boolNDArray, , boolNDArray, ) |
|
123 |
4514
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; End: *** |
|
128 */ |