Mercurial > hg > octave-terminal
changeset 5898:da843f35775c
[project @ 2006-07-19 18:18:08 by jwe]
author | jwe |
---|---|
date | Wed, 19 Jul 2006 18:18:31 +0000 |
parents | 8545ec4d6e65 |
children | 82c38ce145a7 |
files | liboctave/ChangeLog liboctave/oct-inttypes.h src/ChangeLog src/OPERATORS/op-bm-b.cc src/OPERATORS/op-bm-bm.cc src/ov-intx.h src/ov-range.h src/ov-re-mat.cc src/ov-re-mat.h src/ov-re-sparse.cc src/ov-re-sparse.h |
diffstat | 11 files changed, 151 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2006-07-19 John W. Eaton <jwe@octave.org> + + * oct-inttypes.h (octave_int::operator bool (void)): New function. + 2006-07-16 John W. Eaton <jwe@octave.org> * oct-spparms.h, oct-spparms.cc (class octave_sparse_params):
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -247,6 +247,8 @@ OCTAVE_INT_FIT_TO_RANGE (- static_cast<double> (ival), T) : 0; } + operator bool (void) const { return static_cast<bool> (value ()); } + operator char (void) const { return static_cast<char> (value ()); } operator double (void) const { return static_cast<double> (value ()); }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,18 @@ 2006-07-19 John W. Eaton <jwe@octave.org> + * OPERATORS/op-bm-bm.cc (oct_assignop_conv_and_assign): New function. + (install_bm_bm_ops): Install it for various types. + * OPERATORS/op-bm-b.cc (oct_assignop_conv_and_assign): New function. + (install_bm_b_ops): Install it for various types. + * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::bool_array_value, + OCTAVE_VALUE_INT_SCALAR_T::bool_array_value): New functions. + * ov-range.h (octave_range::bool_array_value): New function. + * ov-re-sparse.cc (octave_sparse_matrix::bool_array_value): + New function. + * ov-re-sparse.h: Provide decl. + * ov-re-mat.cc (octave_matrix::bool_array_value): New function. + * ov-re-mat.h: Provide decl. + * ov-base.cc (octave_base_value::numeric_assign): Avoid memory leak when converting LHS.
--- a/src/OPERATORS/op-bm-b.cc +++ b/src/OPERATORS/op-bm-b.cc @@ -31,7 +31,18 @@ #include "ov-bool.h" #include "ov-bool-mat.h" #include "ov-scalar.h" +#include "ov-range.h" #include "ov-re-mat.h" +#include "ov-re-sparse.h" +#include "ov-str-mat.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-typeinfo.h" #include "ops.h" #include "xdiv.h" @@ -48,6 +59,24 @@ DEFNDASSIGNOP_FN (assign, bool_matrix, bool, bool_array, assign) +static octave_value +oct_assignop_conv_and_assign (octave_base_value& a1, + const octave_value_list& idx, + const octave_base_value& a2) +{ + octave_bool_matrix& v1 = dynamic_cast<octave_bool_matrix&> (a1); + + // FIXME -- perhaps add a warning for this conversion if the values + // are not all 0 or 1? + + boolNDArray v2 = a2.bool_array_value (); + + if (! error_state) + v1.assign (idx, v2); + + return octave_value (); +} + void install_bm_b_ops (void) { @@ -59,6 +88,22 @@ INSTALL_CATOP (octave_matrix, octave_bool, m_b); INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_bool, assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_scalar, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_range, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_sparse_matrix, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int8_scalar, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int16_scalar, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int32_scalar, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int64_scalar, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint8_scalar, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint16_scalar, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint32_scalar, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint64_scalar, conv_and_assign); } /*
--- a/src/OPERATORS/op-bm-bm.cc +++ b/src/OPERATORS/op-bm-bm.cc @@ -29,7 +29,18 @@ #include "oct-obj.h" #include "ov.h" #include "ov-bool-mat.h" +#include "ov-range.h" #include "ov-re-mat.h" +#include "ov-re-sparse.h" +#include "ov-str-mat.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-typeinfo.h" #include "ops.h" #include "xdiv.h" @@ -71,6 +82,24 @@ DEFNDASSIGNOP_FN (assign, bool_matrix, bool_matrix, bool_array, assign) +static octave_value +oct_assignop_conv_and_assign (octave_base_value& a1, + const octave_value_list& idx, + const octave_base_value& a2) +{ + octave_bool_matrix& v1 = dynamic_cast<octave_bool_matrix&> (a1); + + // FIXME -- perhaps add a warning for this conversion if the values + // are not all 0 or 1? + + boolNDArray v2 = a2.bool_array_value (); + + if (! error_state) + v1.assign (idx, v2); + + return octave_value (); +} + void install_bm_bm_ops (void) { @@ -91,6 +120,24 @@ INSTALL_CATOP (octave_matrix, octave_bool_matrix, m_bm); INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_bool_matrix, assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_char_matrix_str, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_char_matrix_sq_str, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_range, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_sparse_matrix, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int8_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int16_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int32_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int64_matrix, conv_and_assign); + + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint8_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint16_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint32_matrix, conv_and_assign); + INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint64_matrix, conv_and_assign); } /*
--- a/src/ov-intx.h +++ b/src/ov-intx.h @@ -125,6 +125,19 @@ return retval; } + boolNDArray + bool_array_value (void) const + { + boolNDArray retval (dims ()); + + octave_idx_type nel = numel (); + + for (octave_idx_type i = 0; i < nel; i++) + retval(i) = static_cast<bool>(matrix(i)); + + return retval; + } + charNDArray char_array_value (bool = false) const { @@ -301,6 +314,14 @@ return retval; } + boolNDArray + bool_array_value (void) const + { + boolNDArray retval (dim_vector (1, 1)); + retval(0) = static_cast<bool>(scalar); + return retval; + } + charNDArray char_array_value (bool = false) const {
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -160,6 +160,9 @@ Complex complex_value (bool = false) const; + boolNDArray bool_array_value (void) const + { return boolNDArray (range.matrix_value ()); } + ComplexMatrix complex_matrix_value (bool = false) const { return ComplexMatrix (range.matrix_value ()); }
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -145,6 +145,12 @@ return ComplexNDArray (matrix); } +boolNDArray +octave_matrix::bool_array_value (void) const +{ + return boolNDArray (matrix); +} + charNDArray octave_matrix::char_array_value (bool) const {
--- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -135,6 +135,8 @@ ComplexNDArray complex_array_value (bool = false) const; + boolNDArray bool_array_value (void) const; + charNDArray char_array_value (bool = false) const; NDArray array_value (bool = false) const { return matrix; }