Mercurial > octave
diff src/OPERATORS/op-sbm-b.cc @ 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 | 12df7854fa7c |
children | 72c96de7a403 |
line wrap: on
line diff
--- a/src/OPERATORS/op-sbm-b.cc Thu Jun 02 16:31:13 2011 +0200 +++ b/src/OPERATORS/op-sbm-b.cc Mon Jun 20 11:03:21 2011 -0400 @@ -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); }