Mercurial > hg > octave-lyh
changeset 12757:824c60c8f7b9 stable
preserve type when assigning values to sparse logical
* op-sbm-b.cc (oct_assignop_conv_and_assign): New assignment
operator function.
(install_sbm_b_ops): Install it for various RHS types.
* op-sbm-bm.cc (oct_assignop_conv_and_assign): New assignment
operator function.
(install_sbm_bm_ops): Install it for various RHS types.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 20 Jun 2011 11:03:21 -0400 |
parents | 1dfeacd003bb |
children | ecd1364a2700 |
files | src/OPERATORS/op-sbm-b.cc src/OPERATORS/op-sbm-bm.cc test/build_sparse_tests.sh |
diffstat | 3 files changed, 107 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/OPERATORS/op-sbm-b.cc +++ b/src/OPERATORS/op-sbm-b.cc @@ -30,6 +30,14 @@ #include "ov.h" #include "ov-typeinfo.h" #include "ov-bool.h" +#include "ov-int8.h" +#include "ov-int16.h" +#include "ov-int32.h" +#include "ov-int64.h" +#include "ov-uint8.h" +#include "ov-uint16.h" +#include "ov-uint32.h" +#include "ov-uint64.h" #include "ov-scalar.h" #include "ops.h" @@ -77,6 +85,24 @@ return octave_value (); } +static octave_value +oct_assignop_conv_and_assign (octave_base_value& a1, + const octave_value_list& idx, + const octave_base_value& a2) +{ + octave_sparse_bool_matrix& v1 = dynamic_cast<octave_sparse_bool_matrix&> (a1); + + // FIXME -- perhaps add a warning for this conversion if the values + // are not all 0 or 1? + + SparseBoolMatrix v2 (1, 1, a2.bool_value ()); + + if (! error_state) + v1.assign (idx, v2); + + return octave_value (); +} + void install_sbm_b_ops (void) { @@ -91,4 +117,25 @@ INSTALL_CATOP (octave_sparse_matrix, octave_bool, sm_b); INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_bool, assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_scalar, + conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int8_scalar, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int16_scalar, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int32_scalar, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int64_scalar, + conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint8_scalar, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint16_scalar, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint32_scalar, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint64_scalar, + conv_and_assign); }
--- a/src/OPERATORS/op-sbm-bm.cc +++ b/src/OPERATORS/op-sbm-bm.cc @@ -31,9 +31,18 @@ #include "ov-typeinfo.h" #include "ov-bool-mat.h" #include "boolMatrix.h" +#include "ov-int8.h" +#include "ov-int16.h" +#include "ov-int32.h" +#include "ov-int64.h" +#include "ov-uint8.h" +#include "ov-uint16.h" +#include "ov-uint32.h" +#include "ov-uint64.h" +#include "ov-range.h" #include "ov-scalar.h" +#include "ov-str-mat.h" #include "ops.h" - #include "ov-re-sparse.h" #include "ov-bool-sparse.h" #include "smx-bm-sbm.h" @@ -79,6 +88,24 @@ return octave_value (); } +static octave_value +oct_assignop_conv_and_assign (octave_base_value& a1, + const octave_value_list& idx, + const octave_base_value& a2) +{ + octave_sparse_bool_matrix& v1 = dynamic_cast<octave_sparse_bool_matrix&> (a1); + + // FIXME -- perhaps add a warning for this conversion if the values + // are not all 0 or 1? + + SparseBoolMatrix v2 (a2.bool_array_value ()); + + if (! error_state) + v1.assign (idx, v2); + + return octave_value (); +} + void install_sbm_bm_ops (void) { @@ -96,4 +123,35 @@ INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_bool_matrix, assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, + octave_char_matrix_str, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, + octave_char_matrix_sq_str, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_range, + conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_sparse_matrix, + conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int8_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int16_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int32_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_int64_matrix, + conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint8_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint16_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint32_matrix, + conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_bool_matrix, octave_uint64_matrix, + conv_and_assign); }
--- a/test/build_sparse_tests.sh +++ b/test/build_sparse_tests.sh @@ -102,7 +102,7 @@ # gen_assembly_tests # test for sparse constructors with 'sum' vs. 'unique' # gen_select_tests -# indexing tests +# indexing and assignment tests # gen_solver_tests # Tests the solve function with triangular/banded, etc matrices