# HG changeset patch # User jwe # Date 1094824462 0 # Node ID 13aaef87cf18eb688dea52a53d15cb8d264af9ca # Parent c0866f89c43db7498db390498faa6bbd0de9025e [project @ 2004-09-10 13:51:29 by jwe] diff -r c0866f89c43d -r 13aaef87cf18 scripts/ChangeLog --- a/scripts/ChangeLog Fri Sep 10 13:48:18 2004 +0000 +++ b/scripts/ChangeLog Fri Sep 10 13:54:22 2004 +0000 @@ -1,3 +1,11 @@ +2004-09-10 David Bateman + + * statistics/distributions/binomial_rnd.m: Fix error for scalar n + and p with n > 1, and fix for matrix n and p with n == 1. + + * statistics/distributions/poisson_rnd.m: Fix for matrix length, + due to row vs. column vector operations. + 2004-09-03 David Bateman * general/repmat.m: Fix to allow logical classes. diff -r c0866f89c43d -r 13aaef87cf18 scripts/statistics/distributions/binomial_rnd.m --- a/scripts/statistics/distributions/binomial_rnd.m Fri Sep 10 13:48:18 2004 +0000 +++ b/scripts/statistics/distributions/binomial_rnd.m Fri Sep 10 13:54:22 2004 +0000 @@ -82,7 +82,7 @@ else nel = prod (sz); tmp = rand (n, nel); - rnd = tmp < ones (n, nel) * p; + rnd = sum(tmp < ones (n, nel) * p, 1); rnd = reshape(rnd, sz); endif else @@ -101,7 +101,7 @@ tmp = rand (N, L); ind = (1 : N)' * ones (1, L); rnd(k) = sum ((tmp < ones (N, 1) * p(k)(:)') & - (ind <= ones (N, 1) * n(k)(:)')); + (ind <= ones (N, 1) * n(k)(:)'),1); endif endif diff -r c0866f89c43d -r 13aaef87cf18 scripts/statistics/distributions/poisson_rnd.m --- a/scripts/statistics/distributions/poisson_rnd.m Fri Sep 10 13:48:18 2004 +0000 +++ b/scripts/statistics/distributions/poisson_rnd.m Fri Sep 10 13:54:22 2004 +0000 @@ -101,7 +101,7 @@ ind = find (sum < 1); if (any (ind)) sum(ind) = (sum(ind) - - log (1 - rand (1, length (ind))) ./ l(ind)); + - log (1 - rand (length (ind), 1)) ./ l(ind)); num(ind) = num(ind) + 1; else break; diff -r c0866f89c43d -r 13aaef87cf18 src/ov-intx.h --- a/src/ov-intx.h Fri Sep 10 13:48:18 2004 +0000 +++ b/src/ov-intx.h Fri Sep 10 13:54:22 2004 +0000 @@ -51,12 +51,10 @@ ~OCTAVE_VALUE_INT_MATRIX_T (void) { } - octave_value * - clone (void) const + octave_value *clone (void) const { return new OCTAVE_VALUE_INT_MATRIX_T (*this); } - octave_value * - empty_clone (void) const + octave_value *empty_clone (void) const { return new OCTAVE_VALUE_INT_MATRIX_T (); } OCTAVE_INT_NDARRAY_T @@ -83,11 +81,7 @@ } - double - scalar_value (bool = false) const - { - return double_value (); - } + double scalar_value (bool = false) const { return double_value (); } NDArray array_value (bool = false) const @@ -137,39 +131,39 @@ ~OCTAVE_VALUE_INT_SCALAR_T (void) { } - octave_value * - clone (void) const + octave_value *clone (void) const { return new OCTAVE_VALUE_INT_SCALAR_T (*this); } - octave_value * - empty_clone (void) const + octave_value *empty_clone (void) const { return new OCTAVE_VALUE_INT_SCALAR_T (); } octave_value do_index_op (const octave_value_list& idx, int resize_ok) - { - octave_value retval; + { + octave_value retval; + + if (idx.valid_scalar_indices ()) + retval = scalar; + else + { + // XXX FIXME XXX -- this doesn't solve the problem of + // + // a = 1; a([1,1], [1,1], [1,1]) + // + // and similar constructions. Hmm... - if (idx.valid_scalar_indices ()) - retval = scalar; - else - { - // XXX FIXME XXX -- this doesn't solve the problem of - // - // a = 1; a([1,1], [1,1], [1,1]) - // - // and similar constructions. Hmm... + // XXX FIXME XXX -- using this constructor avoids narrowing the + // 1x1 matrix back to a scalar value. Need a better solution + // to this problem. - // XXX FIXME XXX -- using this constructor avoids narrowing the - // 1x1 matrix back to a scalar value. Need a better solution - // to this problem. + octave_value tmp + (new OCTAVE_VALUE_INT_MATRIX_T + (OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION ())); - octave_value tmp (new OCTAVE_VALUE_INT_MATRIX_T ( - OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION ())); - retval = tmp.do_index_op (idx, resize_ok); - } + retval = tmp.do_index_op (idx, resize_ok); + } - return retval; - } + return retval; + } OCTAVE_INT_T OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (void) const @@ -180,19 +174,16 @@ { return OCTAVE_INT_NDARRAY_T (dim_vector (1, 1), scalar); } octave_value resize (const dim_vector& dv) const - { OCTAVE_INT_NDARRAY_T retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } - - double - double_value (bool = false) const { - return double (scalar); + OCTAVE_INT_NDARRAY_T retval (dv); + if (dv.numel()) + retval(0) = scalar; + return retval; } - double - scalar_value (bool = false) const - { - return double (scalar); - } + double double_value (bool = false) const { return double (scalar); } + + double scalar_value (bool = false) const { return double (scalar); } NDArray array_value (bool = false) const