octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ranges are not vectors


From: John W. Eaton
Subject: ranges are not vectors
Date: Tue, 2 Mar 2004 21:45:50 -0600

On  2-Mar-2004, Paul Kienzle <address@hidden> wrote:

| I'm sure this issue was raised a number of years ago,
| but it occasionally bites people:  most operations
| on ranges convert the range to a vector first.  This
| can lead to bad benchmark results, since the syntactic
| difference is subtle.
|
| However, it is pretty bad worst case performance.  Fixing
| it 'properly' would require quite a bit of work in
| liboctave/Range.{cc,h} and src/ov-range.cc so that the
| full matrix is never created.
| 
| A much simpler solution is to create the full matrix, but
| cache the result so that the penalty is only paid once.

Thanks for looking at this again.  Caching the matrix value will be a
nice improvement even if it is not the absolute most efficient
solution.

| I provide two patches.  The first, range.diff, casts away the
| const on range and caches all calls to matrix_value.

I think you can avoid the const_cast if you declare the cache variable
as mutable.

Also, you should invalidate the cache if any of the non-const
functions

  void sort (void);

  void set_base (double b) { rng_base = b;  }
  void set_limit (double l) { rng_limit = l; }
  void set_inc (double i) { rng_inc = i;   }

  void print_range (void);

are called (and actually result in a change to the range data).

I'm not sure why print_range is non-const (or at this point, why it
even exists, so I'd vote for removing it).

Would you please revise your patch to use mutable, remove the casts,
and reset the cache (if necessary) in the above functions?

Thanks,

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]