op-sbm-bm.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2004-2012 David Bateman
00004 Copyright (C) 1998-2004 Andy Adler
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "gripes.h"
00029 #include "oct-obj.h"
00030 #include "ov.h"
00031 #include "ov-typeinfo.h"
00032 #include "ov-bool-mat.h"
00033 #include "boolMatrix.h"
00034 #include "ov-int8.h"
00035 #include "ov-int16.h"
00036 #include "ov-int32.h"
00037 #include "ov-int64.h"
00038 #include "ov-uint8.h"
00039 #include "ov-uint16.h"
00040 #include "ov-uint32.h"
00041 #include "ov-uint64.h"
00042 #include "ov-range.h"
00043 #include "ov-scalar.h"
00044 #include "ov-str-mat.h"
00045 #include "ops.h"
00046 #include "ov-null-mat.h"
00047 #include "ov-re-sparse.h"
00048 #include "ov-bool-sparse.h"
00049 #include "smx-bm-sbm.h"
00050 #include "smx-sbm-bm.h"
00051 
00052 // sparse bool matrix by bool matrix ops.
00053 
00054 DEFBINOP_FN (eq, sparse_bool_matrix, bool_matrix, mx_el_eq)
00055 DEFBINOP_FN (ne, sparse_bool_matrix, bool_matrix, mx_el_ne)
00056 
00057 DEFBINOP_FN (el_and, sparse_bool_matrix, bool_matrix, mx_el_and)
00058 DEFBINOP_FN (el_or,  sparse_bool_matrix, bool_matrix, mx_el_or)
00059 
00060 DEFCATOP (sbm_bm, sparse_bool_matrix, bool_matrix)
00061 {
00062   CAST_BINOP_ARGS (octave_sparse_bool_matrix&, const octave_bool_matrix&);
00063 
00064   SparseBoolMatrix tmp (v2.bool_matrix_value ());
00065   return octave_value (v1.sparse_bool_matrix_value (). concat (tmp, ra_idx));
00066 }
00067 
00068 DEFCATOP (sbm_m, sparse_bool_matrix, matrix)
00069 {
00070   CAST_BINOP_ARGS (octave_sparse_bool_matrix&, const octave_matrix&);
00071 
00072   SparseMatrix tmp (v2.matrix_value ());
00073   return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx));
00074 }
00075 
00076 DEFCATOP (sm_bm, sparse_matrix, bool_matrix)
00077 {
00078   CAST_BINOP_ARGS (octave_sparse_matrix&, const octave_bool_matrix&);
00079 
00080   SparseMatrix tmp (v2.matrix_value ());
00081   return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx));
00082 }
00083 
00084 DEFASSIGNOP (assign, sparse_bool_matrix, bool_matrix)
00085 {
00086   CAST_BINOP_ARGS (octave_sparse_bool_matrix&, const octave_bool_matrix&);
00087 
00088   v1.assign (idx, SparseBoolMatrix (v2.bool_matrix_value ()));
00089   return octave_value ();
00090 }
00091 
00092 DEFNULLASSIGNOP_FN (null_assign, sparse_bool_matrix, delete_elements)
00093 
00094 static octave_value
00095 oct_assignop_conv_and_assign (octave_base_value& a1,
00096                               const octave_value_list& idx,
00097                               const octave_base_value& a2)
00098 {
00099   octave_sparse_bool_matrix& v1 = dynamic_cast<octave_sparse_bool_matrix&> (a1);
00100 
00101   // FIXME -- perhaps add a warning for this conversion if the values
00102   // are not all 0 or 1?
00103 
00104   SparseBoolMatrix v2 (a2.bool_array_value ());
00105 
00106   if (! error_state)
00107     v1.assign (idx, v2);
00108 
00109   return octave_value ();
00110 }
00111 
00112 void
00113 install_sbm_bm_ops (void)
00114 {
00115   INSTALL_BINOP (op_eq, octave_sparse_bool_matrix, octave_bool_matrix, eq);
00116   INSTALL_BINOP (op_ne, octave_sparse_bool_matrix, octave_bool_matrix, ne);
00117 
00118   INSTALL_BINOP (op_el_and, octave_sparse_bool_matrix, octave_bool_matrix,
00119                  el_and);
00120   INSTALL_BINOP (op_el_or, octave_sparse_bool_matrix, octave_bool_matrix,
00121                  el_or);
00122 
00123   INSTALL_CATOP (octave_sparse_bool_matrix, octave_bool_matrix, sbm_bm);
00124   INSTALL_CATOP (octave_sparse_matrix, octave_bool_matrix, sm_bm);
00125   INSTALL_CATOP (octave_sparse_bool_matrix, octave_matrix, sbm_m);
00126 
00127   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix,
00128                     octave_bool_matrix, assign);
00129 
00130   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_matrix,
00131                     conv_and_assign);
00132   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix,
00133                     octave_char_matrix_str, conv_and_assign);
00134   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix,
00135                     octave_char_matrix_sq_str, conv_and_assign);
00136 
00137   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_range,
00138                     conv_and_assign);
00139 
00140   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_sparse_matrix,
00141                     conv_and_assign);
00142 
00143   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int8_matrix,
00144                     conv_and_assign);
00145   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int16_matrix,
00146                     conv_and_assign);
00147   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int32_matrix,
00148                     conv_and_assign);
00149   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int64_matrix,
00150                     conv_and_assign);
00151 
00152   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint8_matrix,
00153                     conv_and_assign);
00154   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint16_matrix,
00155                     conv_and_assign);
00156   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint32_matrix,
00157                     conv_and_assign);
00158   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint64_matrix,
00159                     conv_and_assign);
00160 
00161   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_null_matrix,
00162                     null_assign);
00163   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_null_str,
00164                     null_assign);
00165   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_null_sq_str,
00166                     null_assign);
00167 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines