1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 #  include "config.h"
28 #endif
29 
30 #include <ostream>
31 
32 #include "Array-util.h"
33 #include "boolMatrix.h"
34 #include "lo-error.h"
35 #include "str-vec.h"
36 #include "mx-inlines.cc"
37 #include "mx-op-defs.h"
38 
39 // boolMatrix class.
40 
41 bool
operator ==(const boolMatrix & a) const42 boolMatrix::operator == (const boolMatrix& a) const
43 {
44   if (rows () != a.rows () || cols () != a.cols ())
45     return 0;
46 
47   return mx_inline_equal (numel (), data (), a.data ());
48 }
49 
50 bool
operator !=(const boolMatrix & a) const51 boolMatrix::operator != (const boolMatrix& a) const
52 {
53   return !(*this == a);
54 }
55 
56 boolMatrix&
insert(const boolMatrix & a,octave_idx_type r,octave_idx_type c)57 boolMatrix::insert (const boolMatrix& a, octave_idx_type r, octave_idx_type c)
58 {
59   Array<bool>::insert (a, r, c);
60   return *this;
61 }
62 
63 // unary operations
64 
65 boolMatrix
operator !(void) const66 boolMatrix::operator ! (void) const
67 {
68   octave_idx_type nr = rows ();
69   octave_idx_type nc = cols ();
70 
71   boolMatrix b (nr, nc);
72 
73   for (octave_idx_type j = 0; j < nc; j++)
74     for (octave_idx_type i = 0; i < nr; i++)
75       b.elem (i, j) = ! elem (i, j);
76 
77   return b;
78 }
79 
80 // other operations
81 
82 boolMatrix
diag(octave_idx_type k) const83 boolMatrix::diag (octave_idx_type k) const
84 {
85   return Array<bool>::diag (k);
86 }
87 
88 MM_BOOL_OPS (boolMatrix, boolMatrix)
89 MS_BOOL_OPS (boolMatrix, bool)
90 SM_BOOL_OPS (bool, boolMatrix)
91 MM_CMP_OPS (boolMatrix, boolMatrix)
92