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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2828
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2828
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
2828
|
29 |
4669
|
30 #include "Array-util.h" |
2828
|
31 #include "lo-error.h" |
|
32 #include "str-vec.h" |
|
33 #include "mx-base.h" |
|
34 #include "mx-inlines.cc" |
|
35 |
|
36 // boolMatrix class. |
|
37 |
|
38 bool |
|
39 boolMatrix::operator == (const boolMatrix& a) const |
|
40 { |
|
41 if (rows () != a.rows () || cols () != a.cols ()) |
|
42 return 0; |
|
43 |
3769
|
44 return mx_inline_equal (data (), a.data (), length ()); |
2828
|
45 } |
|
46 |
|
47 bool |
|
48 boolMatrix::operator != (const boolMatrix& a) const |
|
49 { |
|
50 return !(*this == a); |
|
51 } |
|
52 |
|
53 boolMatrix& |
5275
|
54 boolMatrix::insert (const boolMatrix& a, octave_idx_type r, octave_idx_type c) |
2828
|
55 { |
|
56 Array2<bool>::insert (a, r, c); |
|
57 return *this; |
|
58 } |
|
59 |
3203
|
60 // unary operations |
|
61 |
|
62 boolMatrix |
|
63 boolMatrix::operator ! (void) const |
|
64 { |
5275
|
65 octave_idx_type nr = rows (); |
|
66 octave_idx_type nc = cols (); |
3203
|
67 |
|
68 boolMatrix b (nr, nc); |
|
69 |
5275
|
70 for (octave_idx_type j = 0; j < nc; j++) |
|
71 for (octave_idx_type i = 0; i < nr; i++) |
3203
|
72 b.elem (i, j) = ! elem (i, j); |
|
73 |
|
74 return b; |
|
75 } |
|
76 |
|
77 // other operations |
|
78 |
6979
|
79 boolMatrix |
|
80 boolMatrix::diag (void) const |
|
81 { |
|
82 return diag (0); |
|
83 } |
|
84 |
|
85 boolMatrix |
|
86 boolMatrix::diag (octave_idx_type k) const |
|
87 { |
|
88 octave_idx_type nnr = rows (); |
|
89 octave_idx_type nnc = cols (); |
|
90 if (k > 0) |
|
91 nnc -= k; |
|
92 else if (k < 0) |
|
93 nnr += k; |
|
94 |
|
95 boolMatrix d; |
|
96 |
|
97 if (nnr > 0 && nnc > 0) |
|
98 { |
|
99 octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc; |
|
100 |
|
101 d.resize (ndiag, 1); |
|
102 |
|
103 if (k > 0) |
|
104 { |
|
105 for (octave_idx_type i = 0; i < ndiag; i++) |
|
106 d.xelem (i) = elem (i, i+k); |
|
107 } |
|
108 else if (k < 0) |
|
109 { |
|
110 for (octave_idx_type i = 0; i < ndiag; i++) |
|
111 d.xelem (i) = elem (i-k, i); |
|
112 } |
|
113 else |
|
114 { |
|
115 for (octave_idx_type i = 0; i < ndiag; i++) |
|
116 d.xelem (i) = elem (i, i); |
|
117 } |
|
118 } |
|
119 else |
|
120 (*current_liboctave_error_handler) |
|
121 ("diag: requested diagonal out of range"); |
|
122 |
|
123 return d; |
|
124 } |
|
125 |
5775
|
126 // FIXME Do these really belong here? Maybe they should be |
4015
|
127 // in a base class? |
|
128 |
2832
|
129 boolMatrix |
4015
|
130 boolMatrix::all (int dim) const |
2832
|
131 { |
4015
|
132 MX_ALL_OP (dim); |
2832
|
133 } |
|
134 |
|
135 boolMatrix |
4015
|
136 boolMatrix::any (int dim) const |
2832
|
137 { |
4015
|
138 MX_ANY_OP (dim); |
2832
|
139 } |
|
140 |
4543
|
141 MM_CMP_OPS (boolMatrix, , boolMatrix, ) |
3685
|
142 |
2828
|
143 /* |
|
144 ;;; Local Variables: *** |
|
145 ;;; mode: C++ *** |
|
146 ;;; End: *** |
|
147 */ |