help-octave
[Top][All Lists]
Advanced

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

Re: Calling other functions from .oct files


From: Paul Kienzle
Subject: Re: Calling other functions from .oct files
Date: Thu, 01 May 2003 21:57:31 -0400
User-agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3a) Gecko/20021212

John W. Eaton wrote:

On  1-May-2003, Peter Williams <address@hidden> wrote:

| That did the trick. I'm looking to speed up some monte carlos that | I've got and the real bottleneck is updating the paths.

Then you don't really want to be using feval.  It will still be slow.
If you use Octave 2.1.46, then you can call rand directly, without
having to go through feval, because the guts of the rand function have
been moved to a liboctave class instead of being defined directly in a
DEFUN function.  Execution speed was the reason for the move -- I was
doing something similar to what you are now doing.

You could always buffer your random numbers in your
simulation so that the overhead of feval is insignificant.

On the other hand you should be able to call
the computational stuff from another oct-file directly so
that things in liboctave don't have special status.  In
principle it is easy enough.   In the same way that you
load Frand from rand.oct, you could load a pointer
to a direct rand function.  You would need a call to
something like:
   typedef  double (*FDrand)(void);
   FDrand rand  = LoadDirect("rand");
   ...
   nextrand = (*rand)();
   ...

It would be nice to do overloading so that you could
export all of:
   double rand();
   Matrix rand(int,int);
   void rand(Matrix&);
but I can't think how to do this without getting familiar
with the C++ name mangling scheme the compiler uses.

Perhaps it would be sufficient to call them different names
such as the following:
   typedef double (*FDrand)(void);
   typedef Matrix (*FDrand_matrix)(int,int);
   typedef void (*FDrand_matrix_update)(Matrix &);

   FDrand_matrix_update rand = LoadDirect("rand","rand_matrix_update");
   ...
   Matrix x(100,100);
   while (more) {
      (*rand)(x);
      ...
   }

A few macros would help.  And an oct-file
specific header file, which would need to be
placed somewhere that mkoctfile can find it.

Exporting the classes is probably too much
to hope for.

Paul Kienzle
address@hidden



-------------------------------------------------------------
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]