help-octave
[Top][All Lists]
Advanced

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

Re: Casting a Matrix object as a single dimensional array


From: David Grundberg
Subject: Re: Casting a Matrix object as a single dimensional array
Date: Tue, 08 Jun 2010 14:38:35 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4

On 06/08/2010 02:16 PM, Chidambaram Annamalai wrote:
I still don't see how I can access the internal double* pointer. Could
you please elaborate? (That is, show a simple example?)

Thanks,
Chillu

On 6/7/10, David Grundberg<address@hidden>  wrote:
On 06/07/2010 12:54 PM, Chidambaram Annamalai wrote:
I am writing C++ code to manipulate Matrix objects using the octave
headers. I want to copy it to the GPU, for which I require a pointer
to the underlying chunk of memory the Matrix object stores its data
in. Is there a way to do this?

If I cannot get the pointer (due to private visibility mode etc. or
otherwise) what's the most efficient (in terms of least amount of
memory copies) way to do this?

I hope there's a better way than creating my own vanilla array and
copying the elements of the matrix because the matrices are very large
in size.

Thanks,
Chillu

These functions are part of the Array<T>  class:

const T * data  (void) const
const T * fortran_vec (void) const
T * fortran_vec (void)

And Matrix inherits from Array<double>  (via MArray<double>).

David


Please reply on the bottom of the post. It makes the thread easier to follow.

    Matrix mymatrix (4, 4);
    double * ptr;

    ptr = mymatrix.fortran_vec ();

    for (int i = 0; i < 16; i++)
        ptr[i] = i;

    const double * cptr;

    cptr = mymatrix.fortran_vec (); // or data ()

    for (int i = 0; i < 16; i++)
        printf ("%1.0f, ", cptr[i]);

David


reply via email to

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