help-octave
[Top][All Lists]
Advanced

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

Re: Realtime cost of call by value


From: John W. Eaton
Subject: Re: Realtime cost of call by value
Date: Thu, 30 Oct 2003 13:49:24 -0600

On 30-Oct-2003, address@hidden <address@hidden> wrote:

| Well, drawing a parallel from the weakly-typed nature of variables in
| the Octave interpreter, I believe that it should be possible to have
| these references to all types.

No, you can't have one reference that works for all types.  At least
not a reference to the actual underlying data.  Because for that you
need to know the exact type of the underlying data.  You can have a
reference to a generic octave_value object, but that is not the same
as having a reference to the actual data (which is what the OP needed
to gain efficiency).

| Every function needs to do input type
| checking anyways, and whenever a new type is added to Octave, those
| need to be updated as well, no?

No and yes.

Instead of

  if (ov.is_matrix ())  // i.e., check that ov is an octave_matrix object
    {
      Matrix m = ov.matrix_value ();
      // Do something with m ...
    }
  else
    error (...);

you should write

  Matrix m = ov.matrix_value ();

  if (! error_state)
    {
      // Do something with m ...
    }
  else
    error (...);

that way, if someone introduces a new type that can be converted to a
matrix, but that is not actually a "matrix" (i.e., a double precision
matrix object), then your code doesn't have to change.

Eventually, the mechanism for checking for errors will probably be
exceptions rather than looking at error_state, but the concept is the
same.  Try to extract the value and see if it works rather than asking
precisely what type you have.

Currently, if you look at the code for things like SVD, you will see
something like

  if (ov.is_complex_type ())
    ...
  else if (ov.is_real_type ())
    ...
  else
    error (...);

but code like this needs to be fixed so that it will be possible to
add a new type (say banded matrices) and not have to go back to svd.cc
and add a new case.  We need a better method for dispatching.

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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