GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
boolMatrix.cc
Go to the documentation of this file.
1 // Matrix manipulations.
2 /*
3 
4 Copyright (C) 1996-2013 John W. Eaton
5 Copyright (C) 2009-2010 VZLU Prague, a.s.
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
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
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
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include <iostream>
30 
31 #include "Array-util.h"
32 #include "lo-error.h"
33 #include "str-vec.h"
34 #include "mx-base.h"
35 #include "mx-inlines.cc"
36 #include "mx-op-defs.h"
37 
38 // boolMatrix class.
39 
40 bool
42 {
43  if (rows () != a.rows () || cols () != a.cols ())
44  return 0;
45 
46  return mx_inline_equal (length (), data (), a.data ());
47 }
48 
49 bool
51 {
52  return !(*this == a);
53 }
54 
57 {
58  Array<bool>::insert (a, r, c);
59  return *this;
60 }
61 
62 // unary operations
63 
66 {
67  octave_idx_type nr = rows ();
68  octave_idx_type nc = cols ();
69 
70  boolMatrix b (nr, nc);
71 
72  for (octave_idx_type j = 0; j < nc; j++)
73  for (octave_idx_type i = 0; i < nr; i++)
74  b.elem (i, j) = ! elem (i, j);
75 
76  return b;
77 }
78 
79 // other operations
80 
83 {
84  return Array<bool>::diag (k);
85 }
86 
87 // FIXME: Do these really belong here? Maybe they should be in a base class?
88 
90 boolMatrix::all (int dim) const
91 {
92  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_all);
93 }
94 
96 boolMatrix::any (int dim) const
97 {
98  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_any);
99 }
100 
102 MS_BOOL_OPS (boolMatrix, bool)
103 SM_BOOL_OPS (bool, boolMatrix)
104 MM_CMP_OPS (boolMatrix, boolMatrix)