dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #11739
Re: numpy ndarray from/to dolfin matrix
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
> > Here is how the c++ image data is converted from/to
> > numpy in our project:
> >
> > http://code.google.com/p/wrapitk/source/browse/trunk/ExternalProjects/PyBuf
> >fer/itkPyBuffer.txx
> >
> > I'm trying to solve some variational image processing problems where
> > the data term in the PDE comes from the image buffer. Just to make
> > sure, is dolfin matrix the right way of inputing the image data or am
> > I missing something?
>
> I think the best way to find out is to state your question in mathematical
> terms. Who knows maybee someone on the list are trying to solve the same
> problem, I am not...
>
> Probably you want to read in the data in a Function and use this in your
> variational formulation.
>
> Johan
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev
Attachment:
signature.asc
Description: Digital signature
Follow ups
References