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 |
|
32 #include <iostream.h> |
|
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 |
|
63 boolMatrix |
|
64 boolMatrix::transpose (void) const |
|
65 { |
|
66 int nr = rows (); |
|
67 int nc = cols (); |
|
68 boolMatrix result (nc, nr); |
|
69 if (length () > 0) |
|
70 { |
|
71 for (int j = 0; j < nc; j++) |
|
72 for (int i = 0; i < nr; i++) |
|
73 result.elem (j, i) = elem (i, j); |
|
74 } |
|
75 return result; |
|
76 } |
|
77 |
2832
|
78 boolMatrix |
2833
|
79 boolMatrix::all (void) const |
2832
|
80 { |
|
81 int nr = rows (); |
|
82 int nc = cols (); |
|
83 boolMatrix retval; |
|
84 if (nr > 0 && nc > 0) |
|
85 { |
|
86 if (nr == 1) |
|
87 { |
|
88 retval.resize (1, 1); |
|
89 retval.elem (0, 0) = true; |
|
90 for (int j = 0; j < nc; j++) |
|
91 { |
|
92 if (! elem (0, j)) |
|
93 { |
|
94 retval.elem (0, 0) = false; |
|
95 break; |
|
96 } |
|
97 } |
|
98 } |
|
99 else if (nc == 1) |
|
100 { |
|
101 retval.resize (1, 1); |
|
102 retval.elem (0, 0) = true; |
|
103 for (int i = 0; i < nr; i++) |
|
104 { |
|
105 if (! elem (i, 0)) |
|
106 { |
|
107 retval.elem (0, 0) = false; |
|
108 break; |
|
109 } |
|
110 } |
|
111 } |
|
112 else |
|
113 { |
|
114 retval.resize (1, nc); |
|
115 for (int j = 0; j < nc; j++) |
|
116 { |
|
117 retval.elem (0, j) = true; |
|
118 for (int i = 0; i < nr; i++) |
|
119 { |
|
120 if (! elem (i, j)) |
|
121 { |
|
122 retval.elem (0, j) = false; |
|
123 break; |
|
124 } |
|
125 } |
|
126 } |
|
127 } |
|
128 } |
|
129 return retval; |
|
130 } |
|
131 |
|
132 boolMatrix |
2833
|
133 boolMatrix::any (void) const |
2832
|
134 { |
|
135 int nr = rows (); |
|
136 int nc = cols (); |
|
137 boolMatrix retval; |
|
138 if (nr > 0 && nc > 0) |
|
139 { |
|
140 if (nr == 1) |
|
141 { |
|
142 retval.resize (1, 1); |
|
143 retval.elem (0, 0) = false; |
|
144 for (int j = 0; j < nc; j++) |
|
145 { |
|
146 if (elem (0, j)) |
|
147 { |
|
148 retval.elem (0, 0) = true; |
|
149 break; |
|
150 } |
|
151 } |
|
152 } |
|
153 else if (nc == 1) |
|
154 { |
|
155 retval.resize (1, 1); |
|
156 retval.elem (0, 0) = false; |
|
157 for (int i = 0; i < nr; i++) |
|
158 { |
|
159 if (elem (i, 0)) |
|
160 { |
|
161 retval.elem (0, 0) = true; |
|
162 break; |
|
163 } |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 retval.resize (1, nc); |
|
169 for (int j = 0; j < nc; j++) |
|
170 { |
|
171 retval.elem (0, j) = false; |
|
172 for (int i = 0; i < nr; i++) |
|
173 { |
|
174 if (elem (i, j)) |
|
175 { |
|
176 retval.elem (0, j) = true; |
|
177 break; |
|
178 } |
|
179 } |
|
180 } |
|
181 } |
|
182 } |
|
183 return retval; |
|
184 } |
|
185 |
2828
|
186 /* |
|
187 ;;; Local Variables: *** |
|
188 ;;; mode: C++ *** |
|
189 ;;; End: *** |
|
190 */ |