[Numpy-discussion] inverting and calculating eigenvalues for many small matrices
David Warde-Farley
wardefar@iro.umontreal...
Tue Aug 16 04:53:59 CDT 2011
On 2011-08-15, at 4:11 PM, Daniel Wheeler wrote:
> One thing that I know I'm doing wrong is
> reassigning every sub-matrix to a new array. This may not be that
> costly, but it seems fairly ugly. I wasn't sure how to pass the
> address of the submatrix to the lapack routines so I'm assigning to a
> new array and passing that instead.
It looks like the arrays you're passing are C contiguous. Am I right about this? (I ask because I was under the impression that BLAS/LAPACK routines typically want Fortran-ordered input arrays).
If your 3D array is also C-contiguous, you should be able to do pointer arithmetic with A.data and B.data. foo.strides[0] will tell you how many bytes you need to move to get to the next element along that axis.
If the 3D array is anything but C contiguous, then I believe the copy is necessary. You should check for that in your Python-visible "solve" wrapper, and make a copy of it that is C contiguous if necessary (check foo.flags.c_contiguous), as this will be likely faster than copying to the same buffer each time in the loop.
David
More information about the NumPy-Discussion
mailing list