Mercurial > hg > octave-jordi
changeset 16969:58188d5a2587
Use isfinite() to replace isinf() | isnan() combination for 30% speed-up.
* scripts/general/int2str.m, scripts/general/quadv.m,
scripts/linear-algebra/cond.m, scripts/polynomial/roots.m,
scripts/statistics/distributions/normcdf.m,
scripts/statistics/distributions/norminv.m,
scripts/statistics/distributions/normpdf.m,
scripts/statistics/distributions/normrnd.m,
scripts/statistics/distributions/tpdf.m:
Use isfinite() to replace isinf() | isnan() combination for 30% speed-up.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 12 Jul 2013 20:31:08 -0700 |
parents | e424cdb2ef96 |
children | 78116b88dbf5 |
files | scripts/general/int2str.m scripts/general/quadv.m scripts/linear-algebra/cond.m scripts/polynomial/roots.m scripts/statistics/distributions/normcdf.m scripts/statistics/distributions/norminv.m scripts/statistics/distributions/normpdf.m scripts/statistics/distributions/normrnd.m scripts/statistics/distributions/tpdf.m |
diffstat | 9 files changed, 12 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/int2str.m +++ b/scripts/general/int2str.m @@ -86,7 +86,7 @@ fmt = sprintf ("%%%dd", 1 + sep); else ## Maybe have some zeros. - nan_inf = isinf (t) | isnan (t); + nan_inf = ! isfinite (t); if (any (nan_inf)) if (any (t(nan_inf) < 0)) min_fw = 4 + sep;
--- a/scripts/general/quadv.m +++ b/scripts/general/quadv.m @@ -106,7 +106,7 @@ if (nfun > 10000) warning ("maximum iteration count reached"); - elseif (any (isnan (q)(:) | isinf (q)(:))) + elseif (any (! isfinite (q(:)))) warning ("infinite or NaN function evaluations were returned"); elseif (hmin < (b - a) * myeps) warning ("minimum step size reached -- possibly singular integral");
--- a/scripts/linear-algebra/cond.m +++ b/scripts/linear-algebra/cond.m @@ -58,7 +58,7 @@ if (p == 2) if (isempty (A)) retval = 0.0; - elseif (any (isinf (A(:)) | isnan (A(:)))) + elseif (any (! isfinite (A(:)))) error ("cond: A must not contain Inf or NaN values"); else sigma = svd (A);
--- a/scripts/polynomial/roots.m +++ b/scripts/polynomial/roots.m @@ -81,7 +81,7 @@ if (nargin != 1 || (! isvector (v) && ! isempty (v))) print_usage (); - elseif (any (isnan (v) | isinf (v))) + elseif (any (! isfinite (v))) error ("roots: inputs must not contain Inf or NaN"); endif
--- a/scripts/statistics/distributions/normcdf.m +++ b/scripts/statistics/distributions/normcdf.m @@ -54,13 +54,13 @@ endif if (isscalar (mu) && isscalar (sigma)) - if (!isinf (mu) && !isnan (mu) && (sigma > 0) && (sigma < Inf)) + if (isfinite (mu) && (sigma > 0) && (sigma < Inf)) cdf = stdnormal_cdf ((x - mu) / sigma); else cdf = NaN (size (x), class (cdf)); endif else - k = isinf (mu) | isnan (mu) | !(sigma > 0) | !(sigma < Inf); + k = ! isfinite (mu) | !(sigma > 0) | !(sigma < Inf); cdf(k) = NaN; k = ! k;
--- a/scripts/statistics/distributions/norminv.m +++ b/scripts/statistics/distributions/norminv.m @@ -54,11 +54,11 @@ endif if (isscalar (mu) && isscalar (sigma)) - if (!isinf (mu) && !isnan (mu) && (sigma > 0) && (sigma < Inf)) + if (isfinite (mu) && (sigma > 0) && (sigma < Inf)) inv = mu + sigma * stdnormal_inv (x); endif else - k = !isinf (mu) & !isnan (mu) & (sigma > 0) & (sigma < Inf); + k = isfinite (mu) & (sigma > 0) & (sigma < Inf); inv(k) = mu(k) + sigma(k) .* stdnormal_inv (x(k)); endif
--- a/scripts/statistics/distributions/normpdf.m +++ b/scripts/statistics/distributions/normpdf.m @@ -54,7 +54,7 @@ endif if (isscalar (mu) && isscalar (sigma)) - if (!isinf (mu) && !isnan (mu) && (sigma > 0) && (sigma < Inf)) + if (isfinite (mu) && (sigma > 0) && (sigma < Inf)) pdf = stdnormal_pdf ((x - mu) / sigma) / sigma; else pdf = NaN (size (x), class (pdf));
--- a/scripts/statistics/distributions/normrnd.m +++ b/scripts/statistics/distributions/normrnd.m @@ -83,14 +83,14 @@ endif if (isscalar (mu) && isscalar (sigma)) - if (!isnan (mu) && !isinf (mu) && (sigma > 0) && (sigma < Inf)) + if (isfinite (mu) && (sigma > 0) && (sigma < Inf)) rnd = mu + sigma * randn (sz, cls); else rnd = NaN (sz, cls); endif else rnd = mu + sigma .* randn (sz, cls); - k = isnan (mu) | isinf (mu) | !(sigma > 0) | !(sigma < Inf); + k = ! isfinite (mu) | !(sigma > 0) | !(sigma < Inf); rnd(k) = NaN; endif
--- a/scripts/statistics/distributions/tpdf.m +++ b/scripts/statistics/distributions/tpdf.m @@ -53,7 +53,7 @@ k = isnan (x) | !(n > 0) | !(n < Inf); pdf(k) = NaN; - k = !isinf (x) & !isnan (x) & (n > 0) & (n < Inf); + k = isfinite (x) & (n > 0) & (n < Inf); if (isscalar (n)) pdf(k) = (exp (- (n + 1) * log (1 + x(k) .^ 2 / n)/2) / (sqrt (n) * beta (n/2, 1/2)));