2828
|
1 // Matrix manipulations. |
|
2 /* |
|
3 |
2847
|
4 Copyright (C) 1996, 1997 John W. Eaton |
2828
|
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__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #ifdef HAVE_CONFIG_H |
|
29 #include <config.h> |
|
30 #endif |
|
31 |
3503
|
32 #include <iostream> |
2828
|
33 |
|
34 #include "lo-error.h" |
|
35 #include "str-vec.h" |
|
36 #include "mx-base.h" |
|
37 #include "mx-inlines.cc" |
|
38 |
|
39 // boolMatrix class. |
|
40 |
|
41 bool |
|
42 boolMatrix::operator == (const boolMatrix& a) const |
|
43 { |
|
44 if (rows () != a.rows () || cols () != a.cols ()) |
|
45 return 0; |
|
46 |
|
47 return equal (data (), a.data (), length ()); |
|
48 } |
|
49 |
|
50 bool |
|
51 boolMatrix::operator != (const boolMatrix& a) const |
|
52 { |
|
53 return !(*this == a); |
|
54 } |
|
55 |
|
56 boolMatrix& |
|
57 boolMatrix::insert (const boolMatrix& a, int r, int c) |
|
58 { |
|
59 Array2<bool>::insert (a, r, c); |
|
60 return *this; |
|
61 } |
|
62 |
3203
|
63 // unary operations |
|
64 |
|
65 boolMatrix |
|
66 boolMatrix::operator ! (void) const |
|
67 { |
|
68 int nr = rows (); |
|
69 int nc = cols (); |
|
70 |
|
71 boolMatrix b (nr, nc); |
|
72 |
|
73 for (int j = 0; j < nc; j++) |
|
74 for (int i = 0; i < nr; i++) |
|
75 b.elem (i, j) = ! elem (i, j); |
|
76 |
|
77 return b; |
|
78 } |
|
79 |
|
80 // other operations |
|
81 |
2832
|
82 boolMatrix |
2833
|
83 boolMatrix::all (void) const |
2832
|
84 { |
|
85 int nr = rows (); |
|
86 int nc = cols (); |
|
87 boolMatrix retval; |
|
88 if (nr > 0 && nc > 0) |
|
89 { |
|
90 if (nr == 1) |
|
91 { |
|
92 retval.resize (1, 1); |
|
93 retval.elem (0, 0) = true; |
|
94 for (int j = 0; j < nc; j++) |
|
95 { |
|
96 if (! elem (0, j)) |
|
97 { |
|
98 retval.elem (0, 0) = false; |
|
99 break; |
|
100 } |
|
101 } |
|
102 } |
|
103 else if (nc == 1) |
|
104 { |
|
105 retval.resize (1, 1); |
|
106 retval.elem (0, 0) = true; |
|
107 for (int i = 0; i < nr; i++) |
|
108 { |
|
109 if (! elem (i, 0)) |
|
110 { |
|
111 retval.elem (0, 0) = false; |
|
112 break; |
|
113 } |
|
114 } |
|
115 } |
|
116 else |
|
117 { |
|
118 retval.resize (1, nc); |
|
119 for (int j = 0; j < nc; j++) |
|
120 { |
|
121 retval.elem (0, j) = true; |
|
122 for (int i = 0; i < nr; i++) |
|
123 { |
|
124 if (! elem (i, j)) |
|
125 { |
|
126 retval.elem (0, j) = false; |
|
127 break; |
|
128 } |
|
129 } |
|
130 } |
|
131 } |
|
132 } |
|
133 return retval; |
|
134 } |
|
135 |
|
136 boolMatrix |
2833
|
137 boolMatrix::any (void) const |
2832
|
138 { |
|
139 int nr = rows (); |
|
140 int nc = cols (); |
|
141 boolMatrix retval; |
|
142 if (nr > 0 && nc > 0) |
|
143 { |
|
144 if (nr == 1) |
|
145 { |
|
146 retval.resize (1, 1); |
|
147 retval.elem (0, 0) = false; |
|
148 for (int j = 0; j < nc; j++) |
|
149 { |
|
150 if (elem (0, j)) |
|
151 { |
|
152 retval.elem (0, 0) = true; |
|
153 break; |
|
154 } |
|
155 } |
|
156 } |
|
157 else if (nc == 1) |
|
158 { |
|
159 retval.resize (1, 1); |
|
160 retval.elem (0, 0) = false; |
|
161 for (int i = 0; i < nr; i++) |
|
162 { |
|
163 if (elem (i, 0)) |
|
164 { |
|
165 retval.elem (0, 0) = true; |
|
166 break; |
|
167 } |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 retval.resize (1, nc); |
|
173 for (int j = 0; j < nc; j++) |
|
174 { |
|
175 retval.elem (0, j) = false; |
|
176 for (int i = 0; i < nr; i++) |
|
177 { |
|
178 if (elem (i, j)) |
|
179 { |
|
180 retval.elem (0, j) = true; |
|
181 break; |
|
182 } |
|
183 } |
|
184 } |
|
185 } |
|
186 } |
|
187 return retval; |
|
188 } |
|
189 |
3685
|
190 MM_CMP_OPS(boolMatrix, , boolMatrix, ) |
|
191 |
2828
|
192 /* |
|
193 ;;; Local Variables: *** |
|
194 ;;; mode: C++ *** |
|
195 ;;; End: *** |
|
196 */ |