[Top][All Lists]

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

Re: Get pointer to data in Matrix classes [possible solution]

From: Jaroslav Hajek
Subject: Re: Get pointer to data in Matrix classes [possible solution]
Date: Thu, 12 Mar 2009 12:16:09 +0100

On Thu, Mar 12, 2009 at 12:03 PM, José Luis García Pallero
<address@hidden> wrote:
>> The liboctave reference is far from complete and also somewhat
>> outdated, because liboctave is changing constantly.
>> Help would be appreciated.
> One possibility is to generate the documentation of liboctave via doxygen
> and put a link in "Docs" section of Though the functions
> don't have documentation, we could see the class diagrams and the
> declaration of the methods.

No question, but someone has to do it. Also, quoting Soren Hauberg:
"I think one problem with documenting the API's is that it might give
the impression that they are stable."
Which is well said. Most of Octave developers agree that the API needs
to be modernized, so documenting it now would possibly mean a lost

>> The Matrix class may share all or part of its data with another Matrix
>> (or NDArray or ColumnVector etc). When you want to write to the
>> Matrix, you first need to ensure this is not true, making copy if
>> needed.
> Ok. For example:
> 1. I create a matrix -> a=[1 2 3;4 5 6];
> 2. I pass the matrix to an *.oct function
> 3. In oct function I get the pointer to the data -> double*
> data=a.fortran_vec();
> 4. Do something...
> Is the correct working way with normal matrices?

Yes, but it will make a copy, and you need to return the modified
matrix as a return value, otherwise the argument will not be modified.
If you need only to read the matrix data, query data () which gives
you a const pointer.

> And, for example, imagine that I'm working with a diagonal matrix, like an a
> priori weighting matrix:
> a=diag([1 2 3 4 5]);
> and I pass it to my oct function for solve a least squares proble, for
> example. I want that the a posteriori covariance matrix has the data in the
> same space of memory of a, for saving resources, but the a posteriori matrix
> will be full, not diagonal. The original a=diag([1 2 3 4 5]); sentence in
> octave creates a diagonal matrix. Are correct the syntax Matrix
> a=arg(0).matrix_value(); in an oct file for get the a matrix from octave? Is
> full this Matrix a in memory file? Can I use double* b=a.fortran_vec()? Are
> the data duplicated?
> Thanks and sorry for this long list of questions

Not sure I understand exactly, but you matrix_value called on a
diagonal matrix object will convert it to a full one.
The diagonal data will, of course, be copied.

RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic

reply via email to

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