help-octave
[Top][All Lists]
Advanced

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

Re: oct function question


From: Paul Kienzle
Subject: Re: oct function question
Date: Sun, 1 Oct 2006 16:43:04 -0400


On Oct 1, 2006, at 2:14 PM, Anand Patil wrote:

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()?

You can get a handle to the underlying data in two ways.

To modify a matrix:

  Matrix data(args(k).matrix_value());
  double *p = data.fortran_vec();

To query a matrix:

  const Matrix data(args(k).matrix_value());
  const double *p = data.data();

John mentioned changing these both to use .data(), with the
const form returning in place and the non-const form performing
a copy, but I don't know if this has been done.

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()?

Not sure I understand your question.  The matrix object owns the
data and there is no way to create a new matrix object which points
to existing data.  Two matrix objects can point to the same data,
but the data is copied if either are modified.

- Paul



reply via email to

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