help-octave
[Top][All Lists]
Advanced

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

Oct-file magic


From: Michael Friedlander
Subject: Oct-file magic
Date: Wed, 2 Jul 2008 19:36:32 -0700

Hi Folks,

I'd like to write an oct-file that modifies a vector in-place. Of course, this isn't a good idea in general, but I'd like to squeeze some efficiency out of a routine that's called many times over.

The oct-file is a wrapper to a simple C-routine that already works in- place and has the simple interface

   void foo(int m, double x);

Here is my current oct-file:

DEFUN_DLD(foo, args, nargout, "foo a vector") {
    octave_value_list retval;
    Matrix x = args(0).matrix_value();
    int m = x.nelem();
    double *xv = x.fortran_vec();
    foo(m, xv);
    retval(0) = x;
    return retval;
}

If I make the call

  x = foo(x);

from within Octave, does this oct-file work in-place, or does it modify a copy of x? If it's the latter, how can I trick the Octave interface into doing things in-place, so that I can just call the function as

  foo(x);

Many thanks for your help!

Michael



reply via email to

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