GNU Octave  4.0.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-2015 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 "boolMatrix.h"
33 #include "lo-error.h"
34 #include "str-vec.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 
89 SM_BOOL_OPS (bool, boolMatrix)
90 MM_CMP_OPS (boolMatrix, boolMatrix)
#define MM_BOOL_OPS(M1, M2)
Definition: mx-op-defs.h:210
boolMatrix diag(octave_idx_type k=0) const
Definition: boolMatrix.cc:82
bool operator==(const boolMatrix &a) const
Definition: boolMatrix.cc:41
#define SM_BOOL_OPS(S, M)
Definition: mx-op-defs.h:167
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2526
T & elem(octave_idx_type n)
Definition: Array.h:380
octave_idx_type rows(void) const
Definition: Array.h:313
Array< T > & insert(const Array< T > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
Definition: Array.cc:1591
boolMatrix & insert(const boolMatrix &a, octave_idx_type r, octave_idx_type c)
Definition: boolMatrix.cc:56
const bool * data(void) const
Definition: Array.h:479
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
#define MS_BOOL_OPS(M, S)
Definition: mx-op-defs.h:124
#define MM_CMP_OPS(M1, M2)
Definition: mx-op-defs.h:193
bool mx_inline_equal(size_t n, const T1 *x, const T2 *y)
Definition: mx-inlines.cc:441
octave_idx_type cols(void) const
Definition: Array.h:321
bool operator!=(const boolMatrix &a) const
Definition: boolMatrix.cc:50
boolMatrix operator!(void) const
Definition: boolMatrix.cc:65