dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #11740
Re: numpy ndarray from/to dolfin matrix
On Fri, Jan 16, 2009 at 8:28 AM, Anders Logg <logg@xxxxxxxxx> wrote:
> On Fri, Jan 16, 2009 at 08:20:40AM +0100, Johan Hake wrote:
>> Ali!
>>
>> > def numpyArrayToDolfinMatrix(a):
>> > nx = a.shape[0]
>> > ny = a.shape[1]
>> > m = dolfin.Matrix(nx, ny)
>> > m.set(a, numpy.arange(0, nx, dtype=numpy.uint0), numpy.arange(0,
>> > ny, dtype=numpy.uint0))
>> > m.apply();
>> > return m
>> >
>> > Can you confirm that from the c++ side, just a buffer pointer is
>> > passed and there is no loop involved?
>>
>> For the DOLFIN library this depends on which linear backend you are using.
>> This is given by:
>>
>> dolfin_get("linear algebra backend")
>>
>> For the uBLAS and MTL4 backend we do a loop. For the PETSc and Epetra backend
>> we just send the pointer to the underlying library. The last ones support
>> distributed data, which DOLFIN also intend to use, so there will probably be
>> some loop in these libraries too.
>>
>> > I'm actually trying to convert a c++ image data structure to dolfin
>> > matrix, why shouldn't dolfin have a design to dynamically accept this
>> > sort of input?
>>
>> Well, the DOLFIN library is built to produce the matrices by assembling
>> variational problems defined by forms. The DOLFIN linear algebra part is
>> built to facilitate this, and to be able to use different backends.
>
> It sounds like you should consider using a dense matrix
> representation which means using the class uBLASDenseMatrix.
>
> --
> Anders
I don't know what you're trying to do, but...
If your image matrix is the data on the right hand side of the PDE
you want to solve, you probably need to convert it to a Vector in
a Function, such that each pixel corresponds to one degree of
freedom in the Function.
Martin
References