Mercurial > hg > octave-lojdl
changeset 14593:f4acb362b513
maint: Periodic merge of stable to default
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 03 May 2012 00:50:03 -0400 |
parents | b99cb1b0ee7c (current diff) 6250e1232c9c (diff) |
children | e4d380c01dcf 11a9d448fdc3 |
files | scripts/statistics/distributions/poissrnd.m src/ov-base-diag.cc |
diffstat | 5 files changed, 26 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/DiagArray2.cc +++ b/liboctave/DiagArray2.cc @@ -82,16 +82,14 @@ // A two-dimensional array with diagonal elements only. -template <class T> -T -DiagArray2<T>::checkelem (octave_idx_type r, octave_idx_type c) const +template <typename T> +void +DiagArray2<T>::check_idx (octave_idx_type r, octave_idx_type c) const { if (r < 0 || r >= dim1 ()) gripe_index_out_of_range (2, 1, r+1, dim1 ()); if (c < 0 || c >= dim2 ()) gripe_index_out_of_range (2, 2, c+1, dim2 ()); - - return elem (r, c); } template <class T>
--- a/liboctave/DiagArray2.h +++ b/liboctave/DiagArray2.h @@ -119,15 +119,22 @@ T& dgelem (octave_idx_type i) { return Array<T>::elem (i); } - T checkelem (octave_idx_type r, octave_idx_type c) const; + void check_idx (octave_idx_type r, octave_idx_type c) const; T operator () (octave_idx_type r, octave_idx_type c) const { #if defined (BOUNDS_CHECKING) - return checkelem (r, c); -#else + check_idx (r, c); +#endif return elem (r, c); + } + + T& operator () (octave_idx_type r, octave_idx_type c) + { +#if defined (BOUNDS_CHECKING) + check_idx (r, c); #endif + return elem (r, c); } // No checking.
--- a/scripts/statistics/distributions/poissrnd.m +++ b/scripts/statistics/distributions/poissrnd.m @@ -76,7 +76,7 @@ endif if (isscalar (lambda)) - if (lambda > 0 && lambda < Inf) + if (lambda >= 0 && lambda < Inf) rnd = randp (lambda, sz); if (strcmp (cls, "single")) rnd = single (rnd); @@ -87,7 +87,7 @@ else rnd = NaN (sz, cls); - k = (lambda > 0) & (lambda < Inf); + k = (lambda >= 0) & (lambda < Inf); rnd(k) = randp (lambda(k)); endif @@ -118,3 +118,6 @@ %!error poissrnd (ones (2,2), [3, 2]) %!error poissrnd (ones (2,2), 2, 3) +%!assert (poissrnd (0, 1, 1), 0) +%!assert (poissrnd ([0, 0, 0], [1, 3]), [0 0 0]) +