op-bm-bm.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-bool-mat.h"
00031 #include "ov-scalar.h"
00032 #include "ov-range.h"
00033 #include "ov-re-mat.h"
00034 #include "ov-flt-re-mat.h"
00035 #include "ov-re-sparse.h"
00036 #include "ov-str-mat.h"
00037 #include "ov-int8.h"
00038 #include "ov-int16.h"
00039 #include "ov-int32.h"
00040 #include "ov-int64.h"
00041 #include "ov-uint8.h"
00042 #include "ov-uint16.h"
00043 #include "ov-uint32.h"
00044 #include "ov-uint64.h"
00045 #include "ov-typeinfo.h"
00046 #include "ov-null-mat.h"
00047 #include "ops.h"
00048 #include "xdiv.h"
00049 #include "xpow.h"
00050 
00051 // unary bool matrix ops.
00052 
00053 DEFNDUNOP_OP (not, bool_matrix, bool_array, !)
00054 DEFNDUNOP_OP (uplus, bool_matrix, array, +)
00055 DEFNDUNOP_OP (uminus, bool_matrix, array, -)
00056 
00057 DEFNCUNOP_METHOD (invert, bool_matrix, invert)
00058 
00059 DEFUNOP (transpose, bool_matrix)
00060 {
00061   CAST_UNOP_ARG (const octave_bool_matrix&);
00062 
00063   if (v.ndims () > 2)
00064     {
00065       error ("transpose not defined for N-d objects");
00066       return octave_value ();
00067     }
00068   else
00069     return octave_value (v.bool_matrix_value().transpose ());
00070 }
00071 
00072 // bool matrix by bool matrix ops.
00073 
00074 DEFNDBINOP_FN (eq, bool_matrix, bool_matrix, bool_array, bool_array, mx_el_eq)
00075 DEFNDBINOP_FN (ne, bool_matrix, bool_matrix, bool_array, bool_array, mx_el_ne)
00076 
00077 DEFNDBINOP_FN (el_and, bool_matrix, bool_matrix, bool_array, bool_array,
00078                mx_el_and)
00079 
00080 DEFNDBINOP_FN (el_or,  bool_matrix, bool_matrix, bool_array, bool_array,
00081                mx_el_or)
00082 
00083 DEFNDBINOP_FN (el_not_and, bool_matrix, bool_matrix, bool_array, bool_array,
00084                mx_el_not_and)
00085 
00086 DEFNDBINOP_FN (el_not_or,  bool_matrix, bool_matrix, bool_array, bool_array,
00087                mx_el_not_or)
00088 
00089 DEFNDBINOP_FN (el_and_not, bool_matrix, bool_matrix, bool_array, bool_array,
00090                mx_el_and_not)
00091 
00092 DEFNDBINOP_FN (el_or_not,  bool_matrix, bool_matrix, bool_array, bool_array,
00093                mx_el_or_not)
00094 
00095 DEFNDCATOP_FN (bm_bm, bool_matrix, bool_matrix, bool_array, bool_array, concat)
00096 DEFNDCATOP_FN (bm_m, bool_matrix, matrix, array, array, concat)
00097 DEFNDCATOP_FN (m_bm, matrix, bool_matrix, array, array, concat)
00098 DEFNDCATOP_FN (bm_fm, bool_matrix, float_matrix, float_array, float_array, concat)
00099 DEFNDCATOP_FN (fm_bm, float_matrix, bool_matrix, float_array, float_array, concat)
00100 
00101 DEFNDASSIGNOP_FN (assign, bool_matrix, bool_matrix, bool_array, assign)
00102 DEFNDASSIGNOP_FNOP (assign_and, bool_matrix, bool_matrix, bool_array, mx_el_and_assign)
00103 DEFNDASSIGNOP_FNOP (assign_or, bool_matrix, bool_matrix, bool_array, mx_el_or_assign)
00104 
00105 DEFNULLASSIGNOP_FN (null_assign, bool_matrix, delete_elements)
00106 
00107 static octave_value
00108 oct_assignop_conv_and_assign (octave_base_value& a1,
00109                               const octave_value_list& idx,
00110                               const octave_base_value& a2)
00111 {
00112   octave_bool_matrix& v1 = dynamic_cast<octave_bool_matrix&> (a1);
00113 
00114   // FIXME -- perhaps add a warning for this conversion if the values
00115   // are not all 0 or 1?
00116 
00117   boolNDArray v2 = a2.bool_array_value (true);
00118 
00119   if (! error_state)
00120     v1.assign (idx, v2);
00121 
00122   return octave_value ();
00123 }
00124 
00125 DEFCONVFN (matrix_to_bool_matrix, matrix, bool)
00126 DEFCONVFN (scalar_to_bool_matrix, scalar, bool)
00127 
00128 void
00129 install_bm_bm_ops (void)
00130 {
00131   INSTALL_UNOP (op_not, octave_bool_matrix, not);
00132   INSTALL_UNOP (op_uplus, octave_bool_matrix, uplus);
00133   INSTALL_UNOP (op_uminus, octave_bool_matrix, uminus);
00134   INSTALL_UNOP (op_transpose, octave_bool_matrix, transpose);
00135   INSTALL_UNOP (op_hermitian, octave_bool_matrix, transpose);
00136 
00137   INSTALL_NCUNOP (op_not, octave_bool_matrix, invert);
00138 
00139   INSTALL_BINOP (op_eq, octave_bool_matrix, octave_bool_matrix, eq);
00140   INSTALL_BINOP (op_ne, octave_bool_matrix, octave_bool_matrix, ne);
00141 
00142   INSTALL_BINOP (op_el_and, octave_bool_matrix, octave_bool_matrix, el_and);
00143   INSTALL_BINOP (op_el_or, octave_bool_matrix, octave_bool_matrix, el_or);
00144   INSTALL_BINOP (op_el_not_and, octave_bool_matrix, octave_bool_matrix, el_not_and);
00145   INSTALL_BINOP (op_el_not_or, octave_bool_matrix, octave_bool_matrix, el_not_or);
00146   INSTALL_BINOP (op_el_and_not, octave_bool_matrix, octave_bool_matrix, el_and_not);
00147   INSTALL_BINOP (op_el_or_not, octave_bool_matrix, octave_bool_matrix, el_or_not);
00148 
00149   INSTALL_CATOP (octave_bool_matrix, octave_bool_matrix, bm_bm);
00150   INSTALL_CATOP (octave_bool_matrix, octave_matrix, bm_m);
00151   INSTALL_CATOP (octave_matrix, octave_bool_matrix, m_bm);
00152   INSTALL_CATOP (octave_bool_matrix, octave_float_matrix, bm_fm);
00153   INSTALL_CATOP (octave_float_matrix, octave_bool_matrix, fm_bm);
00154 
00155   INSTALL_CONVOP (octave_matrix, octave_bool_matrix, matrix_to_bool_matrix);
00156   INSTALL_CONVOP (octave_scalar, octave_bool_matrix, scalar_to_bool_matrix);
00157 
00158   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_bool_matrix, assign);
00159 
00160   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_matrix, conv_and_assign);
00161   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_char_matrix_str, conv_and_assign);
00162   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_char_matrix_sq_str, conv_and_assign);
00163 
00164   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_range, conv_and_assign);
00165 
00166   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_sparse_matrix, conv_and_assign);
00167 
00168   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int8_matrix, conv_and_assign);
00169   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int16_matrix, conv_and_assign);
00170   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int32_matrix, conv_and_assign);
00171   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int64_matrix, conv_and_assign);
00172 
00173   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint8_matrix, conv_and_assign);
00174   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint16_matrix, conv_and_assign);
00175   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint32_matrix, conv_and_assign);
00176   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint64_matrix, conv_and_assign);
00177 
00178   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_null_matrix, null_assign);
00179   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_null_str, null_assign);
00180   INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_null_sq_str, null_assign);
00181 
00182   INSTALL_ASSIGNOP (op_el_and_eq, octave_bool_matrix, octave_bool_matrix, assign_and);
00183   INSTALL_ASSIGNOP (op_el_or_eq, octave_bool_matrix, octave_bool_matrix, assign_or);
00184 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines