help-octave
[Top][All Lists]
Advanced

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

Re: oct function question


From: Søren Hauberg
Subject: Re: oct function question
Date: Sun, 01 Oct 2006 20:51:09 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060918)

Hi,

Anand Patil skrev:
OK: I'm writing lightweight oct functions that get called millions of times that involve nonlinear operations on matrix elements. Past experience with such situations in C++ indicates that the overhead from any function calls or indirection involved in using Matrix's get and set functions may add up. Is there any way to get the address of the underlying array out of the Matrix class, as with the mex function mxGetPr()?
Since newer versions of Octave support most of the mex interface, you can just use that. But you can also use "fortran_vec" function. But I'd recommend using the index operators,

  Matrix a(30, 30, 0); // Create a 30x30 matrix of zeros
  a(10, 10) = 7; // Remember to use zero-based indexes in C++


Also: Is there any way to construct a Matrix so that it shares its underlying array with another Matrix? That is, is it possible to pass a matrix into an oct function but then work with it under a name other than args(i).matrix_value()?
You can just use
  Matrix a = args(i).matrix_value();
and then work on a.

Søren


reply via email to

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