Repository navigation
Correct internal dimension of Dask's SVD - #3517
Conversation
Previously the Dask Array SVD code had assumed the shared dimension would be equal to the column in the Dask Array matrix always. However the shared dimension in SVD is whichever is shortest (row or column) of the provided matrix. Computing the results actually provides NumPy Arrays of the expected shape. Meaning that the chunking is merely being misreported when constructing the Dask Arrays from the Dask graph. Hence this fixes how the shapes and chunks of the resulting Dask Arrays are determined.
|
Discovered this bug on my flight. Haven't had time to add a test to it. That said, the bug is real. Basically the shape in the Dask Array metadata does not match the final NumPy array shape computed. It also doesn't match how |
|
Thanks for tracking this down. This looks like it could use a small test, otherwise I'm +1 |
4686afa to
93ab56f
Compare
Make sure that Dask's `svd` returns arrays that would have the correct shapes compared to similar results from NumPy.
93ab56f to
ff331c0
Compare
|
Alright, have added a test to ensure the Dask Arrays returned by |
|
|
||
| for d_e, e in zip([d_u, d_s, d_vt], [u, s, vt]): | ||
| assert d_e.shape == e.shape | ||
| assert d_e.dtype == e.dtype |
There was a problem hiding this comment.
Can we check for these by using assert_eq?
There was a problem hiding this comment.
We could, but that would be overkill as we already know the results are exactly equal.
There was a problem hiding this comment.
Ah I see, I mistakenly assumed that you were comparing to a computation with np.linalg.svd.
I guess I'll change my question then to "given that assert_eq makes this check internally, why didn't we catch this before? Would it make sense to roll these shapes/chunks examples into the parameters of an existing test?"
There was a problem hiding this comment.
So there is also an issue between NumPy and Dask implementations as well, but let's save that discussion for issue ( #3576 ). While we figure that out, it would be good if the Dask Arrays at least didn't misreport the data they hold.
Had looked into including this in another test initially, but the other tests seem to have some pretty niche concerns, which made it unnatural to add this to them and convoluted the otherwise simple logic included here. Plus we want to test several possible shapes, which may have slowed down tests that were comparing results. Given this, opted to breakout the test instead.
Since this test is pretty short, clean, and fast, not sure it is worth spending time trying to stuff it into another test that is running cross-purpose to this one.
|
As you like. Feel free to merge
…On Thu, Jun 7, 2018 at 4:47 PM, jakirkham ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In dask/array/tests/test_linalg.py
<#3517 (comment)>:
> @@ -97,6 +97,23 @@ def test_linalg_consistent_names():
assert same_keys(v1, v2)
***@***.***("m,n", [
+ (10, 20),
+ (15, 15),
+ (20, 10),
+])
+def test_dask_svd_self_consistent(m, n):
+ a = np.random.rand(m, n)
+ d_a = da.from_array(a, chunks=(3, n), name='A')
+
+ d_u, d_s, d_vt = da.linalg.svd(d_a)
+ u, s, vt = da.compute(d_u, d_s, d_vt)
+
+ for d_e, e in zip([d_u, d_s, d_vt], [u, s, vt]):
+ assert d_e.shape == e.shape
+ assert d_e.dtype == e.dtype
So there is also an issue between NumPy and Dask implementations as well,
but let's save that discussion for issue ( #3576
<#3576> ). While we figure that out,
it would be good if the Dask Arrays at least didn't misreport the data they
hold.
Had looked into including this in another test initially, but the other
tests seem to have some pretty niche concerns, which made it unnatural to
add this to them and convoluted the otherwise simple logic included here.
Plus we want to test several possible shapes, which may have slowed down
tests that were comparing results. Given this, opted to breakout the test
instead.
Since this test is pretty short, clean, and fast, not sure it is worth
spending time trying to stuff it into another test that is running
cross-purpose to this one.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3517 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszHURlweMNGEbrphoIrQsM4IaNzC6ks5t6ZFHgaJpZM4UF6rW>
.
|
|
Thanks Matt |
* master: [array.linalg.qr] added sfqr (short-and-fat) as a counterpart to tsqr… (dask#3575) Drop Dask Array's `learn` module (dask#3580) Adds `isneginf` and `isposinf` (dask#3581) Update sizeof definitions (dask#3582) BUG: do not raise IndexError for identity slice in array.vindex (dask#3559) Correct internal dimension of Dask's SVD (dask#3517) Fix check in configuration with env=None (dask#3562) Dataframe sample method docstring fix (dask#3566) Include "region" in key names for da.store (dask#3540) # Conflicts: # dask/array/linalg.py # dask/array/tests/test_linalg.py
Previously the Dask Array SVD code had assumed the shared dimension would be equal to the column in the Dask Array matrix always. However the shared dimension in SVD is whichever is shortest (row or column) of the provided matrix. Computing the results actually provides NumPy Arrays of the expected shape. Meaning that the chunking is merely being misreported when constructing the Dask Arrays from the Dask graph. Hence this fixes how the shapes and chunks of the resulting Dask Arrays are determined.
flake8 dask