octave-maintainers
[Top][All Lists]
Advanced

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

mapper functions for 3.1


From: John W. Eaton
Subject: mapper functions for 3.1
Date: Tue, 05 Feb 2008 17:32:02 -0500

On  5-Feb-2008, David Bateman wrote:

| In the "goals for 3.1" thread there were the points
| 
| 8. Make mapper functions work like other built-in functions?
| 
| 9. Mapper functions like real, imag, and mod should preserve type (are
| there others?)
| 
| I can see easily how to address point 9 in ov-mapper.cc itself, though
| in might involve some if/else blocks. However, I'm not sure I see what
| is meant by point 8. John what was your thoughts for point 8? Does this
| mean that you wanted to get rid of the ov-mapper class and duplicate the
| mapper loops in the functions themselves?

Yes, that was my original idea.  It seemed like it would be good to
have an individual DEFUN for each one, same as all other functions.  I
was thinking that dispatching for the mapper functions would not work
properly otherwise, but that may be wrong.

| The nice thing about the
| current code is that it the loops aren't duplicated for each function.
| How can we make the mapper functions more like other functions without
| massive code duplication?

I think we could still avoid code duplication by using function
pointers and some templates.

  DEFUN (sin, args, , "...")
  {
    octave_value retval;
    if (args.length () == 1)
      retval = args(0).map (std::sin);
    else
      print_usage ();

    return retval;
  }

Then we would need some map functions:

  octave_value octave_value::map (double (*fcn) (double)) const
  {
    return rep->map (fcn);
  }

  octave_value octave_value::map (bool (*fcn) (double)) const
  {
    return rep->map (fcn);
  }

  ...

and also to implement these in the numeric/character classes, then
ultimately in the Array<T> and Sparse<T> classes.  I think some use of
templates or macros there could avoid duplicating the loops (at least
in the source code itself).

jwe


reply via email to

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