Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.vdot() incorrect on signed zeros #7221

Closed
pitrou opened this issue Feb 9, 2016 · 5 comments
Closed

np.vdot() incorrect on signed zeros #7221

pitrou opened this issue Feb 9, 2016 · 5 comments

Comments

@pitrou
Copy link
Member

pitrou commented Feb 9, 2016

See:

>>> complex(1,0) * complex(-1,0).conjugate()
(-1-0j)

but:

>>> a = np.array([complex(1, 0)])
>>> b = np.array([complex(-1, 0)])
>>> np.vdot(a, b)
(-1+0j)

Also:

>>> a * b.conjugate()
array([-1.-0.j])
@pv
Copy link
Member

pv commented Feb 10, 2016

I'd be surprised if BLAS implementations are consistent vs. signed zero, there's probably a speed vs ieee-correctness tradeoff. vdot appears to dispatch to cblas, so it may be the inconsistency comes from there.

@pitrou
Copy link
Member Author

pitrou commented Feb 10, 2016

For contiguous arrays, it probably depends on the BLAS implementation. But the non-contiguous implementation is faulty:

>>> a = np.array([complex(1, 0)]*2)[::-1]
>>> b = np.array([complex(-1, 0)]*2)[::-1]
>>> (a * b.conjugate())
array([-1.-0.j, -1.-0.j])
>>> np.vdot(a, b)
(-2+0j)

Note that np.sum() is faulty as well:

>>> (a * b.conjugate()).sum()
(-2+0j)

@pitrou
Copy link
Member Author

pitrou commented Feb 10, 2016

By the way, the way this popped up is that MKL (which is becoming the default BLAS in Anaconda) seems to get it right.

@pitrou
Copy link
Member Author

pitrou commented Feb 10, 2016

Though it may depend on the particular specialization (depending on the ISA features)... Perhaps we should skip testing for negative zeroes ;)

@seberg
Copy link
Member

seberg commented Jan 28, 2024

Pretty much the same as gh-21342, so will just make a note there. IIRC from the PR: You can possibly fix this for multi-dimenasional dot (0 initial value is passed in and -0 might help), but not vdot, as the scalar version doesn't pass it in: Probably not worthwhile, one issue is enough.

@seberg seberg closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants