Boost logo

Boost :

From: Michael Stevens (michael_at_[hidden])
Date: 2002-09-26 03:33:32


> From:
>nbecker_at_[hidden] (Neal D. Becker)
>
>Can ublas matrixes interconvert to/from plain old C pointers (to
>interop with legacy code)? If so, how can a Matrix be converted to a
>pointer to the start of storage? Is conversion in the other direction
>possible?

It is very easy to get a pointer to the start of storage. The uBLAS contianer (matrix,vector etc) all wrap an underling storage type. This is usualy the 'unbounded_array' type. You can easily get a reference to this array using the accessor functions '.data()'.
>From then it is easy to get a pointer to the begin of the storage using '.begin()'

Therefore to get a pointer to the first element of matrix A used
        A.data().begin()

Obviously you have to be very carful about matching up with the underlining storage layout of A.
For example if you are calling a LAPACK function you will need to make sure the A is dense, rectangular, and column major. i.e. you should use
        ublas::matrix<double, ublas::column_major> A;

I don't think it is possible at present to go the other way. The nearest thing is bounded_array but this allocates its own memory. It would be relatively easy to create a new class 'external_array' that similar but takes a pointer to the external memory to be used.

There may already be other containers around that do this, and would be suitable for use in ublas as the requirements are only that of a Random Access Container.

Michael


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk