Mercurial > hg > octave-shane
changeset 9993:b22a2f4b34aa
support min/max with logical arrays
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 16 Dec 2009 22:11:38 +0100 |
parents | a5a05b2ebb9d |
children | fdc3a43c0be8 |
files | src/ChangeLog src/DLD-FUNCTIONS/max.cc |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2009-12-16 Jaroslav Hajek <highegg@gmail.com> + + * DLD-FUNCTIONS/max.cc (do_minmax_red_op<boolNDArray>): New + specialization. + (do_minmax_body): Handle btyp_bool. + 2009-12-16 Jaroslav Hajek <highegg@gmail.com> * symtab.cc (symbol_table::cleanup): Call clear_variables rather than
--- a/src/DLD-FUNCTIONS/max.cc +++ b/src/DLD-FUNCTIONS/max.cc @@ -75,6 +75,37 @@ return retval; } +// Specialization for bool arrays. +template <> +octave_value_list +do_minmax_red_op<boolNDArray> (const octave_value& arg, + int nargout, int dim, bool ismin) +{ + octave_value_list retval; + + if (nargout <= 1) + { + // This case can be handled using any/all. + boolNDArray array = arg.bool_array_value (); + + if (array.is_empty ()) + retval(0) = array; + else if (ismin) + retval(0) = array.all (dim); + else + retval(0) = array.any (dim); + } + else + { + // any/all don't have indexed versions, so do it via a conversion. + retval = do_minmax_red_op<int8NDArray> (arg, nargout, dim, ismin); + if (! error_state) + retval(0) = retval(0).bool_array_value (); + } + + return retval; +} + template <class ArrayType> static octave_value do_minmax_bin_op (const octave_value& argx, const octave_value& argy, @@ -210,6 +241,9 @@ MAKE_INT_BRANCH (uint32); MAKE_INT_BRANCH (uint64); #undef MAKE_INT_BRANCH + case btyp_bool: + retval = do_minmax_red_op<boolNDArray> (arg, nargout, dim, ismin); + break; default: gripe_wrong_type_arg (func, arg); }