[SciPy-dev] Patches for numpy.linalg and scipy.linalg

Norbert Nemec Norbert.Nemec.list at gmx.de
Sun Mar 12 07:58:19 CST 2006


Over the past few days I worked a bit on the linalg packages in both
numpy and scipy. Attached are patches for both numpy and scipy. Both are
a bit interdependent, so I'm submitting all in one cross-posted mail.

I don't know about the SVN-write-access policy of numpy/scipy. If it is
not kept too restrictive, it might be convenient for everyone to give me
write access. I cannot promise to find much time working on the code,
but linalg sure needs some cleanup and I might continue doing a bit of it.

Here a few explanations about the attached patches:


numpy-1-cleanup.diff
    just a bit of cosmetics to make the other patches cleaner

numpy-2-rename-functions.diff
    numpy.linalg used to contain a number of aliases (like
'inv'=='inverse' and others) this is pointless and more confusing then
helpful. Unless there is a really good reason, a library should offer
one name only. I chose the short version of each name as the "official"
name, because I think all the abbreviations are well-known and easy to
understand for anyone handling numerical linear algebra. Currently all
the definition that would be needed for backwards-compatibility are
deactivated in a "if False:" block. If people think they should be
deprecated slowly, this block could easily be re-activated.

numpy-3-svd-compute_uv.diff
    numpy.linalg.svd now also has the compute_uv option that
scipy.linalg.svd already had. Default behavior is the same as before.

numpy-4-svd-bug-workaround.diff
    the dgesdd function of the lapack library installed on my system
seems to contain a strange bug. Should probably be investigated and
fixed. For the moment I just included a workaround.

numpy-5-norm-copy-from-scipy.diff
    copied and the "norm" function from scipy.linalg and adjusted
internals to work in the new environment

numpy-6-norm-change-default.diff
    the 'scipy.linalg.norm' function was sub-optimal: for matrices, the
frobenius norm is faster then the "max(svd())" by about an order of
magnitude for all the test cases that I came up with. It also is
invariant under orthogonal/unitary transformations, which makes it the
best candidate to be the default in any case that I could come up with.
The computation of the Frobenius norm can be done with the same line of
code used for the vector-square norm and can even be generalized to
arrays of arbitrary rank, always giving a reasonable norm for both real
and complex numbers.
    The most straightforward way to clean up a number of inefficiencies
in the definition of "norm" was to introduce a norm with "ord=None"
which always calculates sqrt(sum((conjugate(x)*x).ravel())) which is
generally the most efficient implementation and does not even need a
check of the rank of the array.
    I also made this choice the default of the "norm" function. I know
that this may cause hard-to-find errors in existing code if people
explicitely want the "svd"-norm for a matrix and relied on the old
default setting. Personally, I don't believe this is a real danger,
because I don't believe there are many algorithms that depend on using
the svd-norm and break if frobenius is used. If people are strictly
against changing the default behavior, the patch should still be
accepted and only the function header changed back.

numpy-7-castCopyAndTranspose.diff
    simplyfied this function for purely aesthetic reasons: I believe a
function that can be written cleanly in two lines should not be extended
unnessecarily to 6 lines...

numpy-8-dual.diff
    added 'norm', 'eigh' and 'eigvalsh' to the list of dual functions.

scipy-1-eigh-eigvalsh.diff
    added two new functions to scipy.linalg. All the interfaces were
there already...

scipy-2-dual-norm.diff
    added 'norm' to the list of dual functions

scipy-3-norm-change-default.diff
    changed the norm in the same way as "numpy.linalg.norm" was changed.
See comments above.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-1-cleanup.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-2-rename-functions.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0001.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-3-svd-compute_uv.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0002.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-4-svd-bug-workaround.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0003.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-5-norm-copy-from-scipy.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0004.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-6-norm-change-default.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0005.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-7-castCopyAndTranspose.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0006.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy-8-dual.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0007.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: scipy-1-eigh-eigvalsh.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0008.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: scipy-2-dual-norm.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0009.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: scipy-3-norm-change-default.diff
Url: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060312/21e975de/attachment-0010.pl 


More information about the Scipy-dev mailing list