Mercurial > hg > octave-lojdl
changeset 4811:198f3712c692
[project @ 2004-03-03 19:24:33 by jwe]
author | jwe |
---|---|
date | Wed, 03 Mar 2004 19:24:33 +0000 |
parents | 72a6d410a14a |
children | 5997796932b1 |
files | liboctave/ChangeLog liboctave/Range.cc liboctave/Range.h liboctave/base-lu.cc scripts/ChangeLog scripts/plot/hist.m |
diffstat | 6 files changed, 65 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,17 @@ +2004-03-03 Hans Ekkehard Plesser <hans.ekkehard.plesser@nlh.no> + + * base-lu.cc (base_lu<>::L): Check bounds before setting diagonal + element. + +2004-03-03 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Range.h (Range::Range): Add cache to member initialization list. + (Range::clear_cache): New private function. + + * Range.h (Range::set_base, Range::set_limit, Range::set_inc): + Use clear cache. Don't do anything if range does not change. + * Range.cc (Range::sort): Likewise. + 2004-03-02 Paul Kienzle <pkienzle@users.sf.net> * Range.cc (Range::matrix_value): Cache result.
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -52,7 +52,7 @@ Matrix Range::matrix_value (void) const { - if (rng_nelem > 0 && cache.rows() == 0) + if (rng_nelem > 0 && cache.rows () == 0) { cache.resize (1, rng_nelem); double b = rng_base; @@ -129,7 +129,7 @@ rng_base = min (); rng_limit = tmp; rng_inc = -rng_inc; - cache.resize (0,0); + clear_cache (); } }
--- a/liboctave/Range.h +++ b/liboctave/Range.h @@ -36,23 +36,23 @@ public: Range (void) - : rng_base (-1), rng_limit (-1), rng_inc (-1), rng_nelem (-1) { } + : rng_base (-1), rng_limit (-1), rng_inc (-1), rng_nelem (-1), cache () { } Range (const Range& r) : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc), - rng_nelem (r.rng_nelem) { } + rng_nelem (r.rng_nelem), cache () { } Range (double b, double l) : rng_base (b), rng_limit (l), rng_inc (1), - rng_nelem (nelem_internal ()) { } + rng_nelem (nelem_internal ()), cache () { } Range (double b, double l, double i) : rng_base (b), rng_limit (l), rng_inc (i), - rng_nelem (nelem_internal ()) { } + rng_nelem (nelem_internal ()), cache () { } - double base (void) const { return rng_base; } + double base (void) const { return rng_base; } double limit (void) const { return rng_limit; } - double inc (void) const { return rng_inc; } + double inc (void) const { return rng_inc; } int nelem (void) const { return rng_nelem; } bool all_elements_are_ints (void) const; @@ -64,9 +64,32 @@ void sort (void); - void set_base (double b) { rng_base = b; cache.resize (0,0); } - void set_limit (double l) { rng_limit = l; cache.resize (0,0); } - void set_inc (double i) { rng_inc = i; cache.resize (0,0); } + void set_base (double b) + { + if (rng_base != b) + { + rng_base = b; + clear_cache (); + } + } + + void set_limit (double l) + { + if (rng_limit != l) + { + rng_limit = l; + clear_cache (); + } + } + + void set_inc (double i) + { + if (rng_inc != i) + { + rng_inc = i; + clear_cache (); + } + } friend std::ostream& operator << (std::ostream& os, const Range& r); friend std::istream& operator >> (std::istream& is, Range& r); @@ -75,14 +98,17 @@ private: - mutable Matrix cache; double rng_base; double rng_limit; double rng_inc; int rng_nelem; + mutable Matrix cache; + int nelem_internal (void) const; + + void clear_cache (void) const { cache.resize (0, 0); } }; extern Range operator - (const Range& r);
--- a/liboctave/base-lu.cc +++ b/liboctave/base-lu.cc @@ -42,7 +42,9 @@ for (int i = 0; i < a_nr; i++) { - l.xelem (i, i) = 1.0; + if (i < a_nc) + l.xelem (i, i) = 1.0; + for (int j = 0; j < (i < a_nc ? i : a_nc); j++) l.xelem (i, j) = a_fact.xelem (i, j); }
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2004-03-03 Stefan van der Walt <stefan@sun.ac.za> + + * plot/hist.m: Compute histogram correctly for n>=30. + 2004-03-02 Paul Kienzle <pkienzle@users.sf.net> * signal/sinc.m: Use i(:) instead of i when checking for any nonzeros.
--- a/scripts/plot/hist.m +++ b/scripts/plot/hist.m @@ -95,7 +95,7 @@ ## Put cutoff elements between boundaries, integrate over all ## elements, keep totals at boundaries. [s, idx] = sort ([cutoff(:); y(:)]); - chist = cumsum(idx>n); + chist = cumsum(idx>=n); chist = [0; chist(idx<n); chist(end)]; endif @@ -114,3 +114,8 @@ endif endfunction + +%!test +%! for n = [1, 10, 30, 100, 1000] +%! assert( sum(hist([1:n], [1:n])) == n ); +%! endfor