# HG changeset patch # User jwe # Date 1153333111 0 # Node ID da843f35775c4145ee2adfce317217c25f832467 # Parent 8545ec4d6e65eae07e2a3196cb652c269786f76d [project @ 2006-07-19 18:18:08 by jwe] diff -r 8545ec4d6e65 -r da843f35775c liboctave/ChangeLog --- a/liboctave/ChangeLog Wed Jul 19 16:52:12 2006 +0000 +++ b/liboctave/ChangeLog Wed Jul 19 18:18:31 2006 +0000 @@ -1,3 +1,7 @@ +2006-07-19 John W. Eaton + + * oct-inttypes.h (octave_int::operator bool (void)): New function. + 2006-07-16 John W. Eaton * oct-spparms.h, oct-spparms.cc (class octave_sparse_params): diff -r 8545ec4d6e65 -r da843f35775c liboctave/oct-inttypes.h --- a/liboctave/oct-inttypes.h Wed Jul 19 16:52:12 2006 +0000 +++ b/liboctave/oct-inttypes.h Wed Jul 19 18:18:31 2006 +0000 @@ -247,6 +247,8 @@ OCTAVE_INT_FIT_TO_RANGE (- static_cast (ival), T) : 0; } + operator bool (void) const { return static_cast (value ()); } + operator char (void) const { return static_cast (value ()); } operator double (void) const { return static_cast (value ()); } diff -r 8545ec4d6e65 -r da843f35775c src/ChangeLog --- a/src/ChangeLog Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ChangeLog Wed Jul 19 18:18:31 2006 +0000 @@ -1,5 +1,18 @@ 2006-07-19 John W. Eaton + * 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. diff -r 8545ec4d6e65 -r da843f35775c src/OPERATORS/op-bm-b.cc --- a/src/OPERATORS/op-bm-b.cc Wed Jul 19 16:52:12 2006 +0000 +++ b/src/OPERATORS/op-bm-b.cc Wed Jul 19 18:18:31 2006 +0000 @@ -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 (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); } /* diff -r 8545ec4d6e65 -r da843f35775c src/OPERATORS/op-bm-bm.cc --- a/src/OPERATORS/op-bm-bm.cc Wed Jul 19 16:52:12 2006 +0000 +++ b/src/OPERATORS/op-bm-bm.cc Wed Jul 19 18:18:31 2006 +0000 @@ -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 (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); } /* diff -r 8545ec4d6e65 -r da843f35775c src/ov-intx.h --- a/src/ov-intx.h Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ov-intx.h Wed Jul 19 18:18:31 2006 +0000 @@ -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(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(scalar); + return retval; + } + charNDArray char_array_value (bool = false) const { diff -r 8545ec4d6e65 -r da843f35775c src/ov-range.h --- a/src/ov-range.h Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ov-range.h Wed Jul 19 18:18:31 2006 +0000 @@ -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 ()); } diff -r 8545ec4d6e65 -r da843f35775c src/ov-re-mat.cc --- a/src/ov-re-mat.cc Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ov-re-mat.cc Wed Jul 19 18:18:31 2006 +0000 @@ -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 { diff -r 8545ec4d6e65 -r da843f35775c src/ov-re-mat.h --- a/src/ov-re-mat.h Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ov-re-mat.h Wed Jul 19 18:18:31 2006 +0000 @@ -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; } diff -r 8545ec4d6e65 -r da843f35775c src/ov-re-sparse.cc --- a/src/ov-re-sparse.cc Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ov-re-sparse.cc Wed Jul 19 18:18:31 2006 +0000 @@ -136,6 +136,12 @@ return matrix.matrix_value (); } +boolNDArray +octave_sparse_matrix::bool_array_value (void) const +{ + return boolNDArray (matrix.matrix_value ()); +} + ComplexMatrix octave_sparse_matrix::complex_matrix_value (bool) const { diff -r 8545ec4d6e65 -r da843f35775c src/ov-re-sparse.h --- a/src/ov-re-sparse.h Wed Jul 19 16:52:12 2006 +0000 +++ b/src/ov-re-sparse.h Wed Jul 19 18:18:31 2006 +0000 @@ -101,6 +101,8 @@ Complex complex_value (bool = false) const; + boolNDArray bool_array_value (void) const; + ComplexMatrix complex_matrix_value (bool = false) const; ComplexNDArray complex_array_value (bool = false) const;