Mercurial > hg > octave-avbm
changeset 8756:d0755c9db5ed
implement fast logical sum (counting)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 16 Feb 2009 12:41:55 +0100 |
parents | 59c0fde890a0 |
children | 79576d40acb6 |
files | liboctave/ChangeLog liboctave/boolNDArray.cc liboctave/boolNDArray.h liboctave/mx-inlines.cc src/ChangeLog src/data.cc |
diffstat | 6 files changed, 33 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,10 @@ +2009-02-16 Jaroslav Hajek <highegg@gmail.com> + + * mx-inlines.cc (OP_RED_FCNN): Use explicit type qualification. + (mx_inline_count): New overloaded template function. + * boolNDArray.h (boolNDArray::sum): Return NDArray. + * boolNDArray.cc (boolNDArray::sum): Return NDArray, use do_mx-red_op. + 2009-02-16 Jaroslav Hajek <highegg@gmail.com> * Array-C.cc, Array-fC.cc: Don't redefine complex comparison.
--- a/liboctave/boolNDArray.cc +++ b/liboctave/boolNDArray.cc @@ -57,10 +57,11 @@ return do_mx_red_op<boolNDArray> (*this, dim, mx_inline_any); } -boolNDArray +NDArray boolNDArray::sum (int dim) const { - MX_ND_REDUCTION (retval(result_idx) |= elem (iter_idx), true, boolNDArray); + // NOTE: going via octave_idx_type is faster even though it requires a conversion. + return do_mx_red_op<Array<octave_idx_type> > (*this, dim, mx_inline_count); } boolNDArray
--- a/liboctave/boolNDArray.h +++ b/liboctave/boolNDArray.h @@ -66,7 +66,7 @@ boolNDArray all (int dim = -1) const; boolNDArray any (int dim = -1) const; - boolNDArray sum (int dim = -1) const; + NDArray sum (int dim = -1) const; boolNDArray concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx);
--- a/liboctave/mx-inlines.cc +++ b/liboctave/mx-inlines.cc @@ -339,6 +339,7 @@ } OP_RED_FCN (mx_inline_sum, T, T, OP_RED_SUM, 0) +OP_RED_FCN (mx_inline_count, bool, T, OP_RED_SUM, 0) OP_RED_FCN (mx_inline_prod, T, T, OP_RED_PROD, 1) OP_RED_FCN (mx_inline_sumsq, T, T, OP_RED_SUMSQ, 0) OP_RED_FCN (mx_inline_sumsq, std::complex<T>, T, OP_RED_SUMSQC, 0) @@ -362,6 +363,7 @@ } OP_RED_FCN2 (mx_inline_sum, T, T, OP_RED_SUM, 0) +OP_RED_FCN2 (mx_inline_count, bool, T, OP_RED_SUM, 0) OP_RED_FCN2 (mx_inline_prod, T, T, OP_RED_PROD, 1) OP_RED_FCN2 (mx_inline_sumsq, T, T, OP_RED_SUMSQ, 0) OP_RED_FCN2 (mx_inline_sumsq, std::complex<T>, T, OP_RED_SUMSQC, 0) @@ -378,7 +380,7 @@ { \ for (octave_idx_type i = 0; i < u; i++) \ { \ - r[i] = F (v, n); \ + r[i] = F<T> (v, n); \ v += n; \ } \ } \ @@ -394,6 +396,7 @@ } OP_RED_FCNN (mx_inline_sum, T, T) +OP_RED_FCNN (mx_inline_count, bool, T) OP_RED_FCNN (mx_inline_prod, T, T) OP_RED_FCNN (mx_inline_sumsq, T, T) OP_RED_FCNN (mx_inline_sumsq, std::complex<T>, T)
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2009-02-16 Jaroslav Hajek <highegg@gmail.com> + + * data.cc (NATIVE_REDUCTION): Use boolNDArray::any for native bool + summation, boolNDArray::sum for double-valued. + 2009-02-16 Jaroslav Hajek <highegg@gmail.com> * ov-base-mat.cc (octave_base_matrix<MT>::assign (const octave_value_list&,
--- a/src/data.cc +++ b/src/data.cc @@ -1335,7 +1335,13 @@ else if NATIVE_REDUCTION_1 (FCN, int16, dim) \ else if NATIVE_REDUCTION_1 (FCN, int32, dim) \ else if NATIVE_REDUCTION_1 (FCN, int64, dim) \ - else if NATIVE_REDUCTION_1 (FCN, bool, dim) \ + else if (arg.is_bool_type ()) \ + { \ + boolNDArray tmp = arg. bool_array_value (); \ + if (! error_state) \ + retval = tmp.any (dim); \ + } \ + \ else if (arg.is_char_matrix ()) \ { \ error (#FCN, ": invalid char type"); \ @@ -1378,6 +1384,12 @@ return retval; \ } \ } \ + else if (arg.is_bool_type ()) \ + { \ + boolNDArray tmp = arg.bool_array_value (); \ + if (! error_state) \ + retval = tmp.FCN (dim); \ + } \ else if (!isdouble && arg.is_single_type ()) \ { \ if (arg.is_real_type ()) \