Mercurial > hg > octave-nkf
annotate liboctave/boolMatrix.cc @ 8743:1bd918cfb6e2
reimplement any & all using the new reduction code
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 14 Feb 2009 19:50:43 +0100 |
parents | 36594d5bbe13 |
children | b756ce0002db |
rev | line source |
---|---|
2828 | 1 // Matrix manipulations. |
2 /* | |
3 | |
7017 | 4 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, |
5 2006, 2007 John W. Eaton | |
2828 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
2828 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
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 (octave_idx_type k) const | |
82 { | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
83 return Array2<bool>::diag (k); |
6979 | 84 } |
85 | |
5775 | 86 // FIXME Do these really belong here? Maybe they should be |
4015 | 87 // in a base class? |
88 | |
2832 | 89 boolMatrix |
4015 | 90 boolMatrix::all (int dim) const |
2832 | 91 { |
8743
1bd918cfb6e2
reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
92 return do_mx_red_op<boolMatrix> (*this, dim, mx_inline_all); |
2832 | 93 } |
94 | |
95 boolMatrix | |
4015 | 96 boolMatrix::any (int dim) const |
2832 | 97 { |
8743
1bd918cfb6e2
reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
98 return do_mx_red_op<boolMatrix> (*this, dim, mx_inline_any); |
2832 | 99 } |
100 | |
4543 | 101 MM_CMP_OPS (boolMatrix, , boolMatrix, ) |
3685 | 102 |
2828 | 103 /* |
104 ;;; Local Variables: *** | |
105 ;;; mode: C++ *** | |
106 ;;; End: *** | |
107 */ |