op-sbm-b.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.h"
00033 #include "ov-int8.h"
00034 #include "ov-int16.h"
00035 #include "ov-int32.h"
00036 #include "ov-int64.h"
00037 #include "ov-uint8.h"
00038 #include "ov-uint16.h"
00039 #include "ov-uint32.h"
00040 #include "ov-uint64.h"
00041 #include "ov-scalar.h"
00042 #include "ops.h"
00043 
00044 #include "ov-re-sparse.h"
00045 #include "ov-bool-sparse.h"
00046 
00047 // sparse bool matrix by bool ops.
00048 
00049 DEFBINOP_FN (ne, sparse_bool_matrix, bool, mx_el_ne)
00050 DEFBINOP_FN (eq, sparse_bool_matrix, bool, mx_el_eq)
00051 
00052 DEFBINOP_FN (el_and, sparse_bool_matrix, bool, mx_el_and)
00053 DEFBINOP_FN (el_or, sparse_bool_matrix, bool, mx_el_or)
00054 
00055 DEFCATOP (sbm_b, sparse_bool_matrix, bool)
00056 {
00057   CAST_BINOP_ARGS (octave_sparse_bool_matrix&, const octave_bool&);
00058 
00059   SparseBoolMatrix tmp (1, 1, v2.bool_value ());
00060   return octave_value (v1.sparse_bool_matrix_value (). concat (tmp, ra_idx));
00061 }
00062 
00063 DEFCATOP (sm_b, sparse_matrix, bool)
00064 {
00065   CAST_BINOP_ARGS (octave_sparse_matrix&, const octave_bool&);
00066 
00067   SparseMatrix tmp (1, 1, v2.scalar_value ());
00068   return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx));
00069 }
00070 
00071 DEFCATOP (sbm_s, sparse_bool_matrix, scalar)
00072 {
00073   CAST_BINOP_ARGS (octave_sparse_bool_matrix&, const octave_scalar&);
00074 
00075   SparseMatrix tmp (1, 1, v2.scalar_value ());
00076   return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx));
00077 }
00078 
00079 DEFASSIGNOP (assign, sparse_bool_matrix, bool)
00080 {
00081   CAST_BINOP_ARGS (octave_sparse_bool_matrix&, const octave_bool&);
00082 
00083   SparseBoolMatrix tmp (1, 1, v2.bool_value ());
00084   v1.assign (idx, tmp);
00085   return octave_value ();
00086 }
00087 
00088 static octave_value
00089 oct_assignop_conv_and_assign (octave_base_value& a1,
00090                               const octave_value_list& idx,
00091                               const octave_base_value& a2)
00092 {
00093   octave_sparse_bool_matrix& v1 = dynamic_cast<octave_sparse_bool_matrix&> (a1);
00094 
00095   // FIXME -- perhaps add a warning for this conversion if the values
00096   // are not all 0 or 1?
00097 
00098   SparseBoolMatrix v2 (1, 1, a2.bool_value ());
00099 
00100   if (! error_state)
00101     v1.assign (idx, v2);
00102 
00103   return octave_value ();
00104 }
00105 
00106 void
00107 install_sbm_b_ops (void)
00108 {
00109   INSTALL_BINOP (op_eq, octave_sparse_bool_matrix, octave_bool, eq);
00110   INSTALL_BINOP (op_ne, octave_sparse_bool_matrix, octave_bool, ne);
00111 
00112   INSTALL_BINOP (op_el_and, octave_sparse_bool_matrix, octave_bool, el_and);
00113   INSTALL_BINOP (op_el_or, octave_sparse_bool_matrix, octave_bool, el_or);
00114 
00115   INSTALL_CATOP (octave_sparse_bool_matrix, octave_bool, sbm_b);
00116   INSTALL_CATOP (octave_sparse_bool_matrix, octave_scalar, sbm_s);
00117   INSTALL_CATOP (octave_sparse_matrix, octave_bool, sm_b);
00118 
00119   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_bool, assign);
00120 
00121   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_scalar,
00122                     conv_and_assign);
00123 
00124   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int8_scalar,
00125                     conv_and_assign);
00126   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int16_scalar,
00127                     conv_and_assign);
00128   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int32_scalar,
00129                     conv_and_assign);
00130   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int64_scalar,
00131                     conv_and_assign);
00132 
00133   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint8_scalar,
00134                     conv_and_assign);
00135   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint16_scalar,
00136                     conv_and_assign);
00137   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint32_scalar,
00138                     conv_and_assign);
00139   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint64_scalar,
00140                     conv_and_assign);
00141 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines