[Numpy-discussion] Two bugs in numpy 0.9.2 and a suggestion.
Paulo J. S. Silva
pjssilva at ime.usp.br
Thu Jan 12 03:39:01 EST 2006
Hello,
I have just installed numpy 0.9.2 in my system. Thanks for the good
work. I think I got two bugs:
1) In the numpy.linalg method the cholesky decomposition doesn't work
because the function triu is not available from numpy.core. If you add a
line "from numpy import triu" on the top of the linalg.py file (with the
other imports), it starts working.
2) If you try to instantiate a ndarray with weird parameters it can
segfault and abort the interpreter. For example try to do the following:
a = arange(10.)
b = ndarray(a)
Now the suggestion. What about adding a "transpose" property (in the
Python parlance) to ndarray objects? I would call it "t". The following
Python code explains what I mean:
from numpy import *
class Myndarray(ndarray):
t = property(transpose, None, None)
If you add this 3 lines to a file, import the Myndarray class, and
create one of such arrays you will get transpose(a) by simply typing
a.t. This allow for the following type of code (which I prefer):
cost = dot(c.t, x)
instead of
cost = dot(transpose(c), x)
or
cost = dot(c.transpose(), x)
Such a compact notation can be a blessing in code that needs lots of
transpose (like the BFGS formula for example).
If I knew more about writing C extensions for Python I would try to do
it myself, but I don't. Is it possible to define properties in a C
extension?
Best,
Paulo
--
Paulo José da Silva e Silva
Professor Assistente do Dep. de Ciência da Computação
(Assistant Professor of the Computer Science Dept.)
Universidade de São Paulo - Brazil
e-mail: rsilva at ime.usp.br Web: http://www.ime.usp.br/~rsilva
Teoria é o que não entendemos o (Theory is something we don't)
suficiente para chamar de prática. (understand well enough to call
practice)
More information about the NumPy-Discussion
mailing list