octave-maintainers
[Top][All Lists]
Advanced

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

Re: mapper functions for 3.1


From: David Bateman
Subject: Re: mapper functions for 3.1
Date: Wed, 13 Feb 2008 23:13:50 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20070914)

John W. Eaton wrote:
>   octave_value octave_matrix::sqrt (void) const
>   {
>     static NDArray::cmapper csqrt = std::sqrt;
>     static NDArray::dmapper dsqrt = std::sqrt;
>
>     return matrix.any_element_less_than (0)
>       ? matrix.map (csqrt) : matrix.map (dsqrt);
>   }
>
>
>   
Ok, I started to look at this implementation of the mapper functions and
have quite a bit of it written. However, I have one issue with your
proposed method of doing this. Currently with the map function in the
octave_value class I'm using

octave_value
octave_matrix::map (double (*fcn) (double)) const
{
  octave_idx_type len = matrix.length ();
  const double *m = matrix.fortran_vec();
  NDArray result (matrix.dims ());
  double *p = result.fortran_vec ();

  for (octave_idx_type i = 0; i < len; i++)
    {
      OCTAVE_QUIT;

      p[i] = fcn (m[i]);

      if (error_state)
        return octave_value ();
    }

  return octave_value (result);
}


Note that the error_state is checked after each function evaluation,
which is normal as functions like lgamma use F7_XFCN that can caller the
error handler. If as you suggest we move the map method to the Array
classes, then we can no longer access the error_state variable as it is
in liboctinterp and so if we accessed error_state in liboctave would
break the separation between  liboctave and liboctinterp.  

I believe that lgamma and gamma are the only mapper functions that can
in fact set error_state and that these two functions are only valid for
real arguments, and so one solution and the one I'm working on is to
just not treat gamma and lgamma as mappers but like any other builtin
function.

Do you have any other suggestions of how to treat this? Do you know
whether there are any other mapper functions that might set the error_state?

D.



reply via email to

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