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