← Back to team overview

dolfin team mailing list archive

Re: [Question #129481]: Writing matrices in Python

 

On Thu, Oct 14, 2010 at 12:34:22PM -0700, Johan Hake wrote:
> On Thursday October 14 2010 12:20:55 Andy R Terrel wrote:
> > New question #129481 on DOLFIN:
> > https://answers.launchpad.net/dolfin/+question/129481
> >
> > I need to write out some assembled matrices in Matrix Market format,
> > hopefully from the Python interface.  Easily for small matrices I can do:
> >
> > from dolfin import *
> > from scipy.io import mmio
> > from scipy.sparse import csr_matrix
> > ...
> >        A = Matrix()
> >         b = Vector()
> >
> >         assemble_system(a, L, bcs=bc0, A_tensor=A, b_tensor=b)
> >
> >         mmio.mmwrite("A.mtx", csr_matrix(A.array()))
> >         mmio.mmwrite("b.mtx", csr_matrix(b.array()))
> >
> > But once A gets large calling "A.array()" takes forever.  Is there a way in
> > python that I can just query the sparsity structure of A?
> >
> > Any other ideas on how to do this quickly?
>
> Shift backend to MTL4 or uBLAS and then:
>
>    rows, cols, values = A.data()
>
> Johan

Another option would be to add a backend for writing to the Matrix
Market format. We've had one before (around 2005) but it was removed
since it wasn't being maintained. If you roll back in the bzr
repository you should be able to find it.

--
Anders



References