4513
|
1 // N-D Array manipulations. |
4511
|
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 |
4513
|
32 #include "dNDArray.h" |
4511
|
33 #include "mx-base.h" |
4513
|
34 #include "lo-error.h" |
4511
|
35 #include "lo-ieee.h" |
|
36 |
4513
|
37 // XXX FIXME XXX -- this is not quite the right thing. |
|
38 |
|
39 boolMatrix |
|
40 NDArray::all (int dim) const |
|
41 { |
|
42 boolMatrix retval; |
|
43 |
|
44 if (dimensions.length () == 2) |
|
45 { |
|
46 Matrix tmp = matrix_value (); |
|
47 retval = tmp.all (dim); |
|
48 } |
|
49 else |
|
50 (*current_liboctave_error_handler) |
|
51 ("all is not yet implemented for N-d Arrays"); |
|
52 |
|
53 return retval; |
|
54 } |
|
55 |
|
56 boolMatrix |
|
57 NDArray::any (int dim) const |
|
58 { |
|
59 boolMatrix retval; |
|
60 |
|
61 if (dimensions.length () == 2) |
|
62 { |
|
63 Matrix tmp = matrix_value (); |
|
64 retval = tmp.any (dim); |
|
65 } |
|
66 else |
|
67 (*current_liboctave_error_handler) |
|
68 ("any is not yet implemented for N-d Arrays"); |
|
69 |
|
70 return retval; |
|
71 } |
|
72 |
4511
|
73 bool |
|
74 NDArray::any_element_is_negative (bool neg_zero) const |
|
75 { |
|
76 int n = length (); |
|
77 if (neg_zero) |
|
78 { |
|
79 for (int i = 0; i < n; i++) |
|
80 if (lo_ieee_signbit (Array<double>::elem (i))) |
|
81 return true; |
|
82 } |
|
83 else |
|
84 { |
|
85 for (int i = 0; i < n; i++) |
|
86 if (Array<double>::elem (i) < 0) |
|
87 return true; |
|
88 } |
|
89 |
|
90 return false; |
|
91 } |
|
92 |
|
93 bool |
|
94 NDArray::all_integers (double& max_val, double& min_val) const |
|
95 { |
|
96 int n = length (); |
|
97 |
|
98 if (n > 0) |
|
99 { |
|
100 max_val = Array<double>::elem (0); |
|
101 min_val = Array<double>::elem (0); |
|
102 } |
|
103 else |
|
104 return false; |
|
105 |
|
106 for (int i = 0; i < n; i++) |
|
107 { |
|
108 double val = Array<double>::elem (0); |
|
109 |
|
110 if (val > max_val) |
|
111 max_val = val; |
|
112 |
|
113 if (val < min_val) |
|
114 min_val = val; |
|
115 |
|
116 if (D_NINT (val) != val) |
|
117 return false; |
|
118 } |
|
119 |
|
120 return true; |
|
121 } |
4513
|
122 |
|
123 Matrix |
|
124 NDArray::matrix_value (void) const |
|
125 { |
|
126 Matrix retval; |
|
127 |
|
128 int nd = ndims (); |
|
129 |
|
130 switch (nd) |
|
131 { |
|
132 case 1: |
|
133 retval = Matrix (Array2<double> (*this, dimensions(0), 1)); |
|
134 break; |
|
135 |
|
136 case 2: |
|
137 retval = Matrix (Array2<double> (*this, dimensions(0), dimensions(1))); |
|
138 break; |
|
139 |
|
140 default: |
|
141 (*current_liboctave_error_handler) |
|
142 ("invalid converstion of NDArray to Matrix"); |
|
143 break; |
|
144 } |
|
145 |
|
146 return retval; |
|
147 } |
|
148 |
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |