<p dir="ltr">Ethan, can you make a deep copy of the transposed vals array? I would guess that petsc4py is not not using the transposed view correctly.</p>
<div class="gmail_quote">On Jan 18, 2013 11:55 AM, "Ethan Coon" <<a href="mailto:ecoon@lanl.gov">ecoon@lanl.gov</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
First, apologies for not looking into this more closely, but I wanted to<br>
make sure I wasn't missing something stupid before I rebuilt petsc-dev<br>
and petsc4py-dev and started writing PETSc-only versions to see what is<br>
going on.<br>
<br>
See the following odd result:<br>
<br>
<br>
In [1]: from petsc4py import PETSc<br>
<br>
In [2]: import numpy as np<br>
<br>
In [3]: n = [0,1]<br>
<br>
In [4]: vals = np.array([[0,1],[0,0]], 'd')<br>
<br>
In [5]: A = PETSc.Mat().createAIJ(2,2)<br>
<br>
In [6]: A.assemble()<br>
<br>
In [7]: B = A.duplicate()<br>
<br>
In [8]: B.setValues(n,n,vals, PETSc.InsertMode.ADD_VALUES)<br>
<br>
In [9]: B.assemble()<br>
<br>
In [10]: B.transpose(out=A)<br>
Out[10]: <petsc4py.PETSc.Mat at 0x2afb7e0><br>
<br>
In [11]: A.view()<br>
Matrix Object: 1 MPI processes<br>
type: seqbaij<br>
row 0: (0, 0) (1, 0)<br>
row 1: (0, 1) (1, 0)<br>
<br>
In [12]: vals<br>
Out[12]:<br>
array([[ 0., 1.],<br>
[ 0., 0.]])<br>
<br>
In [13]: A.setValues(n,n,-vals.transpose(), PETSc.InsertMode.ADD_VALUES)<br>
<br>
In [14]: A.assemble()<br>
<br>
In [15]: A.view()<br>
Matrix Object: 1 MPI processes<br>
type: seqbaij<br>
row 0: (0, 0) (1, -1)<br>
row 1: (0, 1) (1, 0)<br>
<br>
where I would have expected A to be all zeros...<br>
<br>
This is on petsc4py-3.3 and petsc-3.3-p5, and I know this code worked on<br>
older versions of petsc4py/petsc. If I'm not missing something dumb<br>
I'll look a little closer into whether it is PETSc or petsc4py...<br>
<br>
Thanks,<br>
<br>
Ethan<br>
<br>
<br>
<br>
--<br>
------------------------------------<br>
Ethan Coon<br>
Post-Doctoral Researcher<br>
Applied Mathematics - T-5<br>
Los Alamos National Laboratory<br>
505-665-8289<br>
<br>
<a href="http://www.ldeo.columbia.edu/~ecoon/" target="_blank">http://www.ldeo.columbia.edu/~ecoon/</a><br>
------------------------------------<br>
<br>
</blockquote></div>