strange dimension-dependent behaviour of einsum

Hello, I am encountering a very strange behaviour of einsum on my machine. I tracked the problem down to the following test code: from numpy import * T = random.random((3,10,10)) W = random.random((3,10,7,275)) print all(einsum('ij...,j...->i...',T[0],W[0]) + einsum('ij...,j...->i...',T[1],W[1]) + einsum('ij...,j...->i...',T[2],W[2]) - einsum('pij,pjts->its',T,W)< 1e-10) print sum(abs(einsum('ij...,j...->i...',T[0],W[0]) + einsum('ij...,j...->i...',T[1],W[1]) + einsum('ij...,j...->i...',T[2],W[2]) - einsum('pij,pjts->its',T,W))) On my machine the equality is not fulfilled. However, this depends, strange enough, on the dimensions of W: if the last dimension e.g. is 500 instead of 275, things work again and the equality is fulfilled. Are you encountering similar problems or is this just my machine/installation? Since I am heavily relying on einsum but can't trust my code any more, I am happily waiting for you answers. Thanks a lot! Wieland

On Tue, May 17, 2011 at 6:47 PM, Wieland Brendel <wielandbrendel@gmx.net>wrote:
Hello, I am encountering a very strange behaviour of einsum on my machine. I tracked the problem down to the following test code:
from numpy import *
T = random.random((3,10,10)) W = random.random((3,10,7,275))
print all(einsum('ij...,j...->i...',T[0],W[0]) + einsum('ij...,j...->i...',T[1],W[1]) + einsum('ij...,j...->i...',T[2],W[2]) - einsum('pij,pjts->its',T,W)< 1e-10) print sum(abs(einsum('ij...,j...->i...',T[0],W[0]) + einsum('ij...,j...->i...',T[1],W[1]) + einsum('ij...,j...->i...',T[2],W[2]) - einsum('pij,pjts->its',T,W)))
On my machine the equality is not fulfilled. However, this depends, strange enough, on the dimensions of W: if the last dimension e.g. is 500 instead of 275, things work again and the equality is fulfilled.
The equality being that the expression should be ~0? I see the problem when the last index is in the range 235 - 390.
Are you encountering similar problems or is this just my machine/installation?
Out of curiosity, which machine/OS are you using? I'm on 64 bit fedora 14, AMD 940. Chuck

On Tue, May 17, 2011 at 7:32 PM, Charles R Harris <charlesr.harris@gmail.com
wrote:
On Tue, May 17, 2011 at 6:47 PM, Wieland Brendel <wielandbrendel@gmx.net>wrote:
Hello, I am encountering a very strange behaviour of einsum on my machine. I tracked the problem down to the following test code:
from numpy import *
T = random.random((3,10,10)) W = random.random((3,10,7,275))
print all(einsum('ij...,j...->i...',T[0],W[0]) + einsum('ij...,j...->i...',T[1],W[1]) + einsum('ij...,j...->i...',T[2],W[2]) - einsum('pij,pjts->its',T,W)< 1e-10) print sum(abs(einsum('ij...,j...->i...',T[0],W[0]) + einsum('ij...,j...->i...',T[1],W[1]) + einsum('ij...,j...->i...',T[2],W[2]) - einsum('pij,pjts->its',T,W)))
On my machine the equality is not fulfilled. However, this depends, strange enough, on the dimensions of W: if the last dimension e.g. is 500 instead of 275, things work again and the equality is fulfilled.
The equality being that the expression should be ~0?
I see the problem when the last index is in the range 235 - 390.
Are you encountering similar problems or is this just my machine/installation?
Out of curiosity, which machine/OS are you using? I'm on 64 bit fedora 14, AMD 940.
Using T = ones((2,8,8)) W = ones((2,8,8,i)) The problem occurs for i in the closed ranges 129..204 and 257..341. The starting points look suspicious but the end points not so much. I think something isn't getting reset to zero. Chuck

On Tue, May 17, 2011 at 8:09 PM, Wieland Brendel <wielandbrendel@gmx.net>wrote:
It also fails for
T = random.random((2,d,d)) W = random.random((2,d,d,i))
and d > 2. For d = 3 it fails for i = 911...1365.
Should I submit this as a bug (if so, how do I do that?) and/or contact the author Mark Wiebe?
Wieland
PS: How do I reply directly to your messages? **
Just reply in the normal way and it will go to the list so everyone can see it. To open a ticket, go to the scipy site <http://www.scipy.org/> and click on the report bugs icon and follow instructions. You will need to register and it will help if you can produce a simple example the reproduces the problem. I used powers of two for the dimensions because these sort of problems tend to be related to counting in binary. Ones instead of random makes the arithmetic exact so it is easier to see what is going on, etc. Chuck

Thanks for your reply! I managed to open a ticket, http://projects.scipy.org/numpy/ticket/1834 You are actually right, you can also just use zeros instead of random. Maybe I can test a bit more tomorrow... but its 4am in the morning now ;-). Thanks for your help and kindness! Wieland
participants (2)
-
Charles R Harris
-
Wieland Brendel