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 |
4588
|
32 #include "Array-util.h" |
4514
|
33 #include "CNDArray.h" |
|
34 #include "mx-base.h" |
|
35 #include "lo-ieee.h" |
|
36 |
4543
|
37 // unary operations |
|
38 |
|
39 boolNDArray |
|
40 boolNDArray::operator ! (void) const |
|
41 { |
|
42 boolNDArray b (dims ()); |
|
43 |
|
44 for (int i = 0; i < length (); i++) |
|
45 b.elem (i) = ! elem (i); |
|
46 |
|
47 return b; |
|
48 } |
|
49 |
4514
|
50 // XXX FIXME XXX -- this is not quite the right thing. |
|
51 |
4556
|
52 boolNDArray |
4514
|
53 boolNDArray::all (int dim) const |
|
54 { |
4569
|
55 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR), true); |
4514
|
56 } |
|
57 |
4556
|
58 boolNDArray |
4514
|
59 boolNDArray::any (int dim) const |
|
60 { |
4569
|
61 MX_ND_ANY_ALL_REDUCTION (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR), false); |
4514
|
62 } |
|
63 |
|
64 boolMatrix |
|
65 boolNDArray::matrix_value (void) const |
|
66 { |
|
67 boolMatrix retval; |
|
68 |
|
69 int nd = ndims (); |
|
70 |
|
71 switch (nd) |
|
72 { |
|
73 case 1: |
|
74 retval = boolMatrix (Array2<bool> (*this, dimensions(0), 1)); |
|
75 break; |
|
76 |
|
77 case 2: |
|
78 retval = boolMatrix (Array2<bool> (*this, dimensions(0), |
|
79 dimensions(1))); |
|
80 break; |
|
81 |
|
82 default: |
|
83 (*current_liboctave_error_handler) |
|
84 ("invalid converstion of boolNDArray to boolMatrix"); |
|
85 break; |
|
86 } |
|
87 |
|
88 return retval; |
|
89 } |
|
90 |
4532
|
91 void |
|
92 boolNDArray::increment_index (Array<int>& ra_idx, |
|
93 const dim_vector& dimensions, |
|
94 int start_dimension) |
|
95 { |
|
96 ::increment_index (ra_idx, dimensions, start_dimension); |
|
97 } |
|
98 |
4556
|
99 int |
|
100 boolNDArray::compute_index (Array<int>& ra_idx, |
|
101 const dim_vector& dimensions) |
|
102 { |
|
103 return ::compute_index (ra_idx, dimensions); |
|
104 } |
|
105 |
4543
|
106 NDND_CMP_OPS (boolNDArray, , boolNDArray, ) |
|
107 |
4514
|
108 /* |
|
109 ;;; Local Variables: *** |
|
110 ;;; mode: C++ *** |
|
111 ;;; End: *** |
|
112 */ |