[petsc-users] PETSc recommended visualization packages
Lisandro Dalcin
dalcinl at gmail.com
Thu Jul 14 15:47:12 CDT 2011
On 14 July 2011 16:22, Ethan Coon <ecoon at lanl.gov> wrote:
> Attached patch takes Lisandro's matio.py and puts it in a
> PetscBinaryRead.py that reads a binary with (potentially) multiple Petsc
> objects, deciphers the contents of the file from the header, and returns
> numpy objects. It's basically the same as the PetscBinaryRead.m
>
> I've tested this on Vecs, but not Mats or ISs, and I haven't thoroughly
> tested degenerate cases. Will do some testing, but I wanted Lisandro to
> take a look at it as well...
>
1) readMatDense() is wrong. The I,J,V arrays are the CSR structure,
not the COO (coordinate) format, Then you cannot simply:
for i,j,v in zip(I,J,V):
mat[i,j] = v
I think you have to:
for row, rstart in enumerate(I):
rend = I[row+1]
mat[row, J[rstart:rend]] = V[rstart:rend]
2) It would be nice to provie a 'scipy' Mat format returning a
'scipy.sparse.csr_matrix' instance. A possible implementation would
be:
def readMatSciPy(fh):
(M, N), (I, J, V) = readMatSparse(fh)
from scipy.sparse import csr_matrix
return csr_matrix((V, J, I), shape=(M, N))
--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
More information about the petsc-users
mailing list