Oct-file magic

Michael Friedlander mpf at cs.ubc.ca
Wed Jul 2 21:36:32 CDT 2008


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



More information about the Help-octave mailing list