[PYTHON MATRIX-SIG] linear algebra (Column major arrays)
Mon, 19 Aug 1996 16:10:18 -0400
Phil Austin wrote:
> >>>>> "Konrad" == Konrad HINSEN <firstname.lastname@example.org> writes:
> >> Just to throw in a suggestion let me tell what the Ada95
> >> standard does to work around this problem. In Ada95 the
> >> compiler has to have a " pragma Convention (Fortran,
> >> Fortran_Matrix);" which changes the way an array is actually
> >> stored in memory. For the programmer there is no change at
> >> all, the compiler takes care of all necessary changes to make
> >> the array Fortran as well as Ada compatible.
> >> Would this be possible in python without a serious perfomance
> >> overhead ?
> Konrad> One could have a second kind of array object that used
> Konrad> Fortran conventions for storage and inverts indexing. But
> Konrad> I doubt that this is worth the effort.
> We're hoping that users can implement column-major arrays without
> large performance penalties if they aren't intrinsic to the Python
> matrix library. Settling on one index order among our binary data api
> (netcdf), other matrix packages (splus), and our compiled code (F77,
> HPF, F90, and C++ using MV++,r A++/P++ or Barton and Nackman--all
> column major), eliminates a vexing source of confusion and cuts a
> suprising amount of work from debugging, tutorial writing, etc.
I have to admit to a certain bafflement as to the importance of this
issue to people...
Nonetheless, there are many ways of implementing column major arrays
with close to zero performance hit within NumPy. The use of general
strides allows for you to force Array objects to access their data
exactly as if they were a FORTRAN column-major array. Personally I find
this approach rather distasteful, but a number of diehard FORTRAN users
were thrilled when they figured out they could do this, so if it's
useful to you...
Also, the transpose function is extremely efficient (almost
negligible). So long as your C/FORTRAN functions can handle
discontiguous strided arrays (as apparently Lapack can) then this option
will also work for you.
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: email@example.com
administrivia to: firstname.lastname@example.org