[Top][All Lists]

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

Get pointer to data in Matrix classes [possible solution]

From: José Luis García Pallero
Subject: Get pointer to data in Matrix classes [possible solution]
Date: Thu, 12 Mar 2009 10:30:50 +0100


From my last message:

Exist any method in Matrix and Column/RowVector classes to get a pointer for
access directly to the memory? I have some C functions that works with
matrices stored as vectors in column major order, and I would like to link
them with octave without duplicate memory copying the original data.

I wrote this example function for fill a matrix fron a C function:

//assign data
void DataAssign(double* data,int nData);
//octave function
DEFUN_DLD(test,args,,"Assign test")
//return list
octave_value_list retval;
//input arguments
int rows=args(0).int_value();
int cols=args(1).int_value();
//creating the output matrix
Matrix mat(rows,cols);
//address of data
double* data=""> //data assingn
//assignment to return list
retval(0) = mat;
//returning results
return retval;
void DataAssign(double* data,int nData)
for(int i=0;i<nData;i++)
data[i] = i;
//end of the function

This code appears to run OK in my tests. In liboctave.pdf says that Array<T> class has a method named data() that retirns a const pointer
to the memory space where the data are stored. I suppose that Matrix class inherit the method. Are the same for Row/ColumnVector classes?
Is correct the conversion double* data="" It runs but I don't know if exist any implication for future
operations with Matrix-Matrix operations.
José Luis García Pallero
/ / \
Use Debian GNU/Linux and enjoy!

reply via email to

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