help-octave
[Top][All Lists]
Advanced

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

Re: Calling octave functions from oct-files


From: Carlo de Falco
Subject: Re: Calling octave functions from oct-files
Date: Thu, 17 Jan 2008 12:06:14 +0000

Hi,
I am not really sure wether this is of any help,
but you could have a look at the source code of the
ODE/DAE solver functions which all can take function
handles as an input, and then have to evaluate them repeatedly.

for example I see (in src/DLD-FUNCTIONS/daspk.cc) things like

daspk_fcn = c(0).function_value ();     

that might be related to what you want to do.
c.


On 17/gen/08, at 05:21, Evan wrote:

On Jan 17, 2008 12:16 AM, Przemek Klosowski <address@hidden> wrote:
I think you may have a wrong impression on why and how to
speed-optimize in Octave.  The Octave calculation engine is very
fast---once you have marshalled the arguments, it goes to pretty well
optimized libraries, and rips through data.  The delays are caused by
slow interpretation of control structures (for/while loops) and by
extraneous manipulation of the arguments (extra copies, reallocation, etc).

When Octave interpreter runs, it scans your scripts and arranges for
the execution of commands therein, by keeping track of arguments,
building data structures to pass to the library routines and calling
them. If you write an .oct file with feval()s you are essentially
replicating what the interpreter does, so no wonder it is as slow or
slower than the scripts.

To speed things up you'd need to rewrite them in C/C++ completely. Of
course, in the extreme, you could write C/C++ completely independently
from Octave, but you will probably find useful things in the octave
library will help you---and it's nice to be able to use your
computation code from within Octave, for data I/O, plotting, etc. You
need to directly call the binary library routines that the Octave
interpreter uses, It actually is kind-of like your (*p)(args) but you
do need to get the specific details right.

THere's a document called 'Da Coda Al Fine' describing writing .oct
files: http://octave.sourceforge.net/coda/index.html . Beyond that,
there's some info on the web, especially in the archives of this
mailing list


Thanks for the detailed explanation.

The problem in which I am involved is like this, first I write my
program completely in octave scripts. Then I found it too slowly
because there are loops in a function and these loops cannot be
vectorized. So I want to rewrite the function in oct-file. However, in
the function there is a definition of a function handle. I would have
rewritten this definition in complete C++ code too if I know how.
Because I don't know how to define a function handle from another, I
fall back on feval and eval_string expecting that in oct-files they
would be as fast as in octave scripts, and the loops in oct-file would
be much faster than that in octave script, so I would finally get a
faster oct-file. Unfortunately, the defined function handle is used in
the loops and cause the loops even slower than when it is in octave
scripts (I know this because if I call from the oct-file an octave
script to accomplish the definition of the function handle instead of
using feval and eval_string, the loops would be very fast).

That's why I am seeking methods of defining a function handle in
oct-files without using feval or eval_string.
_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave



reply via email to

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