octave-maintainers
[Top][All Lists]
Advanced

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

Re: feval vs. Ffunction_name in C++


From: John W. Eaton
Subject: Re: feval vs. Ffunction_name in C++
Date: Tue, 22 Jan 2019 13:37:20 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1

On 1/22/19 1:13 PM, Rik wrote:
jwe,

Happened to be looking at the code for the dot product in dot.cc today.
There is an if/elseif tree to dispatch complex/real and single/double
inputs directly to Fortran routines.  However, for other cases, like int8,
there is an unoptimized path as shown below:

--- Start Code ---
   else
     {
       // Non-optimized evaluation.
       octave_value_list tmp;
       tmp(1) = dim + 1;
       tmp(0) = do_binary_op (octave_value::op_el_mul, argx, argy);

       tmp = octave::feval ("sum", tmp, 1);
       if (! tmp.empty ())
         retval = tmp(0);
     }
--- End Code ---

Do we need to use feval in this case or would it be slightly more efficient
to just call Fsum directly?

Presumably this code in dot.cc is never called if someone has overloaded
the dot function for their class.

Correct.

I suppose it is possible that someone
has overloaded sum, but why wouldn't you just overload the base
mathematical functions plus() and then rely on Fsum to do the right thing?

There is no reason to expect that overloading sum would affect dot as there is no guarantee that dot is implemented by calling sum.

I think the reason for using feval here is just that the code was written before we provided declarations for built-in functions and so it was recommended to use feval instead.

jwe




reply via email to

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