On Tue, May 8, 2012 at 3:11 PM, Lisandro Dalcin <span dir="ltr"><<a href="mailto:dalcinl@gmail.com" target="_blank">dalcinl@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 8 May 2012 12:25, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
> On Tue, May 8, 2012 at 11:15 AM, Lisandro Dalcin <<a href="mailto:dalcinl@gmail.com">dalcinl@gmail.com</a>> wrote:<br>
>><br>
>> On 8 May 2012 12:04, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
>> > On Tue, May 8, 2012 at 11:00 AM, Christian Staudt<br>
>> > <<a href="mailto:christian.staudt@ira.uka.de">christian.staudt@ira.uka.de</a>> wrote:<br>
>> >><br>
>> >> Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
>> >><br>
>> >> a) Is there an easy and efficient way to convert a numpy.ndarray to a<br>
>> >><br>
>> >> PETSc.Vec or PETSc.Mat (and vice-versa)? (A PETSc.Vec.getArray()<br>
>> >> returns<br>
>> >> a<br>
>> >><br>
>> >> numpy.ndarray, though I have found no such method for PETSc.Mat yet. )<br>
>> >><br>
>> >><br>
>> >><br>
>> >> If you are using dense matrices (MATDENSE) then MatGetArray() works.<br>
>> >><br>
>> >><br>
>> >> I don't think this is implemented in petsc4py: At least, there's no<br>
>> >> method<br>
>> >> PETSc.Mat.getArray()<br>
>> ><br>
>> ><br>
>> > If you ask Lisandro for it, he will put it in.<br>
>> ><br>
>><br>
>> Matt, I've never put that in just because I'm not sure how to make it<br>
>> general. PETSc have many different matrix formats, and MatGetArray()<br>
>> call is like a hack, where you can get very different things (the "1D"<br>
>> values of an AIJ matrix, the "2D" values of a dense matrix in Fortran<br>
>> order). What about MPIAIJ, what should I return to users? Can you<br>
>> suggest some approach or API to implement this (I mean, how to get<br>
>> arrays for the various matrix types)?<br>
><br>
><br>
> I think the whole point is that you should not do it. However, that has<br>
> never stopped us from giving users<br>
> what they ask for. We are not int he business of reforming computing<br>
> practices, which is why we have<br>
> MatGetArray(). I would make a wrapper that failed unless the type was<br>
> MATDENSE.<br>
><br>
<br>
Yea, that's really easy.<br>
<br>
However, Is there anything better for AIJ matrices? Right now, we have<br>
mat.getValuesCSR()... it works by calling MatGetRow() row by row twice<br>
(first pass to count and allocate, next to get values and copy to<br>
NumPy arrays).</blockquote><div><br></div><div>For AIJ specifically, you can use MatGetIJ() and MatGetArray().</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Lisandro Dalcin<br>
---------------<br>
CIMEC (INTEC/CONICET-UNL)<br>
Predio CONICET-Santa Fe<br>
Colectora RN 168 Km 472, Paraje El Pozo<br>
3000 Santa Fe, Argentina<br>
Tel: <a href="tel:%2B54-342-4511594" value="+543424511594">+54-342-4511594</a> (ext 1011)<br>
Tel/Fax: <a href="tel:%2B54-342-4511169" value="+543424511169">+54-342-4511169</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>