Re: [Numpy-discussion] speed up np.diag

2009-07-11 Thread Keith Goodman
On Sat, Jul 11, 2009 at 11:00 AM, Citi, Luca wrote: > I have submitted Ticket #1167 with a patch > to speed up diag and eye. > On average the code is 3 times faster (but > up to 9!). Wow! That's great. With your speed ups it won't be long before I use np.diag(np.eye(10)) instead of np.ones(10) ;

Re: [Numpy-discussion] speed up np.diag

2009-07-11 Thread Citi, Luca
I have submitted Ticket #1167 with a patch to speed up diag and eye. On average the code is 3 times faster (but up to 9!). ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] speed up np.diag

2009-07-10 Thread Citi, Luca
>> if v.flags.f_contiguous: >> v, k, s = v.T, -k, s[::-1] >Is this correct? The .flat iterator always traverses the array in virtual >C-order, not in the order it's laid out in memory. The code could work (and gives the same results) even without the two lines above which in

Re: [Numpy-discussion] speed up np.diag

2009-07-10 Thread Pauli Virtanen
Fri, 10 Jul 2009 15:55:58 +0100, Citi, Luca kirjoitti: [clip] > ## SUGGESTED > def diag(v, k=0): > v = asarray(v) > s = v.shape > if len(s) == 1: [clip] > elif len(s) == 2: > if v.flags.f_contiguous: > v, k, s = v.T, -k, s[::-1] Is this correct? The .flat iterat

[Numpy-discussion] speed up np.diag

2009-07-10 Thread Citi, Luca
Hello, I happened to have a look at the code for np.diag and found it more complicated that necessary. I think it can be rewritten more cleanly and efficiently. Appended you can find both versions. The speed improvement is significant: In [145]: x = S.rand(1000,1300) In [146]: assert all(diag(x,-1