boolMatrix.cc

Go to the documentation of this file.
00001 // Matrix manipulations.
00002 /*
00003 
00004 Copyright (C) 1996-2012 John W. Eaton
00005 Copyright (C) 2009-2010 VZLU Prague, a.s.
00006 
00007 This file is part of Octave.
00008 
00009 Octave is free software; you can redistribute it and/or modify it
00010 under the terms of the GNU General Public License as published by the
00011 Free Software Foundation; either version 3 of the License, or (at your
00012 option) any later version.
00013 
00014 Octave is distributed in the hope that it will be useful, but WITHOUT
00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00017 for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with Octave; see the file COPYING.  If not, see
00021 <http://www.gnu.org/licenses/>.
00022 
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028 
00029 #include <iostream>
00030 
00031 #include "Array-util.h"
00032 #include "lo-error.h"
00033 #include "str-vec.h"
00034 #include "mx-base.h"
00035 #include "mx-inlines.cc"
00036 #include "mx-op-defs.h"
00037 
00038 // boolMatrix class.
00039 
00040 bool
00041 boolMatrix::operator == (const boolMatrix& a) const
00042 {
00043   if (rows () != a.rows () || cols () != a.cols ())
00044     return 0;
00045 
00046   return mx_inline_equal (length (), data (), a.data ());
00047 }
00048 
00049 bool
00050 boolMatrix::operator != (const boolMatrix& a) const
00051 {
00052   return !(*this == a);
00053 }
00054 
00055 boolMatrix&
00056 boolMatrix::insert (const boolMatrix& a, octave_idx_type r, octave_idx_type c)
00057 {
00058   Array<bool>::insert (a, r, c);
00059   return *this;
00060 }
00061 
00062 // unary operations
00063 
00064 boolMatrix
00065 boolMatrix::operator ! (void) const
00066 {
00067   octave_idx_type nr = rows ();
00068   octave_idx_type nc = cols ();
00069 
00070   boolMatrix b (nr, nc);
00071 
00072   for (octave_idx_type j = 0; j < nc; j++)
00073     for (octave_idx_type i = 0; i < nr; i++)
00074       b.elem (i, j) = ! elem (i, j);
00075 
00076   return b;
00077 }
00078 
00079 // other operations
00080 
00081 boolMatrix
00082 boolMatrix::diag (octave_idx_type k) const
00083 {
00084   return Array<bool>::diag (k);
00085 }
00086 
00087 // FIXME Do these really belong here?  Maybe they should be
00088 // in a base class?
00089 
00090 boolMatrix
00091 boolMatrix::all (int dim) const
00092 {
00093   return do_mx_red_op<bool, bool> (*this, dim, mx_inline_all);
00094 }
00095 
00096 boolMatrix
00097 boolMatrix::any (int dim) const
00098 {
00099   return do_mx_red_op<bool, bool> (*this, dim, mx_inline_any);
00100 }
00101 
00102 MM_BOOL_OPS (boolMatrix, boolMatrix)
00103 MS_BOOL_OPS (boolMatrix, bool)
00104 SM_BOOL_OPS (bool, boolMatrix)
00105 MM_CMP_OPS (boolMatrix, boolMatrix)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines