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