GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
boolMatrix.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2024 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
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
52 {
53  return !(*this == a);
54 }
55 
58 {
59  Array<bool>::insert (a, r, c);
60  return *this;
61 }
62 
63 // unary operations
64 
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 
84 {
85  return Array<bool>::diag (k);
86 }
87 
T & elem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:562
octave_idx_type rows() const
Definition: Array.h:459
Array< T, Alloc > & insert(const Array< T, Alloc > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
Definition: Array-base.cc:1608
const bool * data() const
Definition: Array.h:663
octave_idx_type cols() const
Definition: Array.h:469
Array< T, Alloc > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array-base.cc:2541
octave_idx_type numel() const
Number of elements in the array.
Definition: Array.h:414
boolMatrix & insert(const boolMatrix &a, octave_idx_type r, octave_idx_type c)
Definition: boolMatrix.cc:57
boolMatrix diag(octave_idx_type k=0) const
Definition: boolMatrix.cc:83
bool operator==(const boolMatrix &a) const
Definition: boolMatrix.cc:42
bool operator!=(const boolMatrix &a) const
Definition: boolMatrix.cc:51
boolMatrix operator!() const
Definition: boolMatrix.cc:66
bool mx_inline_equal(std::size_t n, const T1 *x, const T2 *y)
Definition: mx-inlines.cc:577
T * r
Definition: mx-inlines.cc:781
#define MM_BOOL_OPS(M1, M2)
Definition: mx-op-defs.h:213
#define MM_CMP_OPS(M1, M2)
Definition: mx-op-defs.h:196
#define SM_BOOL_OPS(S, M)
Definition: mx-op-defs.h:170
#define MS_BOOL_OPS(M, S)
Definition: mx-op-defs.h:127