But obviously I'm doing something wrong.
I've been chasing a bug all night, and I've finally solved it. Consider:
xs = np.arange(100 * 3).reshape(100, 3)
W = np.arange(3 * 17).reshape(3, 17)
a = np.einsum('df, hg -> dg', xs, W)
b = np.dot(xs, W)
In the above a != b
.
The issue I discovered was in the einsum, I say df, hg -> dg
, but if I instead swap out that h
for an f
, it works as expected:
a = np.einsum('df, fg -> dg', xs, W)
b = np.dot(xs, W)
Now, a == b
.
What is the summation doing differently in both cases, I'd expect them to be the same?