Repository navigation
TST: Have array assert_eq check scalars - #2681
Conversation
|
I didn't see any tests for |
|
|
||
| def test_assert_eq_empty_passes(): | ||
| # Treat empty arrays as equivalent | ||
| assert_eq(np.array([[], []]), np.array([])) |
There was a problem hiding this comment.
I think this was the intention of that code block original, based on the comment # Treat all empty arrays as equivalent. Does that sound right to you @mrocklin?
|
Caught at least one bug I think 😬
[25] > /Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/array/tests/test_linalg.py(536)test_norm_2dim()
-> assert_eq(a_r, d_r)
(Pdb++) a_r
array([[ 5.04874206]])
(Pdb++) d_r.compute()
5.0487420596453054
(Pdb++) shape, chunks, axis, norm, keepdims
((5, 6), (2, 2), None, 'nuc', True)I'll open another issue if that's not a quick fix. |
|
I don't have strong memories about what was going on with empty arrays. I
would not be surprised if I ran into something that I just didn't want to
bother with at the time.
…On Thu, Sep 14, 2017 at 5:58 PM, Tom Augspurger ***@***.***> wrote:
Caught at least one bug I think 😬
pytest dask/array/tests/test_linalg.py::test_norm_2dim --pdb -x
[25] > /Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/array/tests/test_linalg.py(536)test_norm_2dim()-> assert_eq(a_r, d_r)
(Pdb++) a_r
array([[ 5.04874206]])
(Pdb++) d_r.compute()5.0487420596453054
(Pdb++) shape, chunks, axis, norm, keepdims
((5, 6), (2, 2), None, 'nuc', True)
I'll open another issue if that's not a quick fix.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2681 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszGAVA1fUU2cKhd-2LKINqaS_5e_fks5siaGAgaJpZM4PYOf3>
.
|
|
Fixed the linalg bugs in ff63420. keepdims was being ignored in a few cases.
I'll see what removing that check breaks. |
|
Just one failure after removing that clause: 2452 assert_eq(da.ones((5, 5), chunks=(2, 3))[:, :0] + 0,
2453 -> np.ones((5, 5))[:0] + 0)which looks to be an error in the test? If so, I'll just remove the empty array special casing. |
ff63420 to
c688423
Compare
|
OK, the empty array special casing is gone, and everything is passing for me locally. |
|
Hmm, this failure looks real: https://travis-ci.org/dask/dask/jobs/275665665#L7745 (you need the cc @jakirkham. Does that look like a bug in the test, or is it in the code? 113 usvt = np.dot(u, np.dot(np.diag(s), vt))
114
115 tol = 0.2
116 assert_eq(np.linalg.norm(mat - usvt),
117 np.linalg.norm(mat),
118 -> rtol=tol, atol=tol) # average accuracy checkedit: Sorry, I should have done dask/dask/array/tests/test_linalg.py Lines 101 to 118 in a1a75a7 |
|
|
||
| r = svd(x)[1].sum() | ||
| if keepdims: | ||
| r = r[None, None] |
There was a problem hiding this comment.
Maybe we should just pass keepdims=keepdims to sum.
There was a problem hiding this comment.
I think that only prevents 1 dimension from being removed. We need the output to be 2 dimensions.
There was a problem hiding this comment.
Although maybe all of these could be replaced by a single check just before returning r?
There was a problem hiding this comment.
Shouldn't. That would be a bug.
With NumPy...
In [1]: np.arange(6).reshape(2, 3).sum(keepdims=True)
Out[1]: array([[15]])There was a problem hiding this comment.
Oh, I think it's the slice that removes a dimension, and then the reduction that removes the second.
There was a problem hiding this comment.
So svd returns multiple values. The index is just selecting which one to use.
There was a problem hiding this comment.
I think I see what you mean now. The middle argument is a vector. So we need to add another dimension to it in order to get a matrix back. It's a strange case to have keepdims in, but it make sense what NumPy is doing.
There was a problem hiding this comment.
Adding one singleton dimension before the reduction function with these svd cases and then calling the reduction function with keepdims did the trick for me.
| elif len(axis) == 2 and ord == 2: | ||
| r = svd(x)[1].max() | ||
| if keepdims: | ||
| r = r[None, None] |
There was a problem hiding this comment.
Maybe we should just pass keepdims=keepdims to max.
| elif len(axis) == 2 and ord == -2: | ||
| r = svd(x)[1].min() | ||
| if keepdims: | ||
| r = r[None, None] |
There was a problem hiding this comment.
Maybe we should just pass keepdims=keepdims to min.
|
Thanks for the assist with handling All of the methods being called there ( |
Ah ok. Yeah didn't really touch the |
c688423 to
893e50b
Compare
|
Glad that you are working on fixing this. Also @bmerry may be interested in this too. |
| assert allclose(a, b, **kwargs) | ||
| assert a.shape == b.shape | ||
| assert allclose(a, b, **kwargs) | ||
| return |
There was a problem hiding this comment.
Was this suppose to return something (not None)?
There was a problem hiding this comment.
Maybe True like the return below?
There was a problem hiding this comment.
Sure, I'll return True to match the below.
893e50b to
67a51e8
Compare
|
I'm pretty confused about why the new |
7cf8b57 to
d7aceec
Compare
|
I'm still stumped by the non-svd failure. Does https://travis-ci.org/dask/dask/jobs/276491069#L7791 make any sense (with these debug statements)? Looking into the SVD stuff later today. |
The common feature seems to be PYTHONOPTIMIZE=2, which I assume turns on the |
d7aceec to
862e527
Compare
|
@bmerry thanks! I think that's it: https://travis-ci.org/dask/dask/jobs/276491069#L720 Here's the related issue: #1388 I'm skipping that test when optimize is enabled. |
| from dask.array.utils import assert_eq | ||
|
|
||
|
|
||
| @pytest.mark.skipif(sys.flags.optimize == 2, reason="Assertions disabled.") |
There was a problem hiding this comment.
I think this should just be sys.flags.optimize. Assertions are disabled even at level 1 (it just happens that Travis only tests with level 2).
862e527 to
a70974a
Compare
Make the right assertion
a70974a to
a0a5bc5
Compare
|
OK, by linear algebra is a little rusty, but I think a0a5bc5 has the fix for the compressed SVD test. Does that look right @marianotepper? |
Testing only that two matrices have the same norm seems like a weak test; perhaps the original intent was to check that the norm of the difference was (approximately) zero? |
|
Checking that the norms are the same follows the pattern of the other tests (and there are additional checks below). I think this is ready to go. If we want to fix up |
| tol = 0.2 | ||
| assert_eq(np.linalg.norm(mat - usvt), | ||
| assert_eq(np.linalg.norm(usvt), | ||
| np.linalg.norm(mat), |
There was a problem hiding this comment.
Yeah what was happening here makes no sense to me. This seems like the best fix without taking this PR in a new direction. Would be nice to have an issue to revisit test_svd_compressed for someone to look at later.
There was a problem hiding this comment.
@mrocklin, do you know more about what this test was trying to do?
There was a problem hiding this comment.
It was probably trying to compare equality between the original and the recomputed result. This might be better written as assert_eq(mat, usvt) if there is some way to add in a tolerance to assert_eq (which there may be, I'm just a little rusty here)
There was a problem hiding this comment.
On a related note, should we document assert_eq and it to the public API?
There was a problem hiding this comment.
...if there is some way to add in a tolerance to
assert_eq(which there may be, I'm just a little rusty here)
Seems like there is as assert_eq calls allclose.
There was a problem hiding this comment.
Would be nice to have an issue to revisit
test_svd_compressedfor someone to look at later.
Added as issue ( #2695 ).
|
No objection from me :)
…On Thu, Sep 21, 2017 at 10:50 AM, jakirkham ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In dask/array/tests/test_linalg.py
<#2681 (comment)>:
> @@ -113,7 +113,7 @@ def test_svd_compressed():
usvt = np.dot(u, np.dot(np.diag(s), vt))
tol = 0.2
- assert_eq(np.linalg.norm(mat - usvt),
+ assert_eq(np.linalg.norm(usvt),
np.linalg.norm(mat),
On a related note, should we document assert_eq and it to the public API?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2681 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszHUyn1Bop2gypTMduQ_IRaQcsyciks5sknexgaJpZM4PYOf3>
.
|
Ok, added as issue ( #2694 ). |
|
Any objections to merging? :) |
|
None from me. In the future I recommend an optimistic approach like saying "I plan to merge this in a bit if no one objects", waiting for a few hours, and then merging. |
|
Ok noted. |
|
+1 from me :)
…On Thu, Sep 21, 2017 at 10:42 AM, jakirkham ***@***.***> wrote:
Ok noted.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2681 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIoa_QJTrx5IoZW0FVMF0uRoXMWNMks5skoPkgaJpZM4PYOf3>
.
|
* TST: Have array assert_eq check scalars Closes dask#2680 * TST: Fixed broadcasting test * TST: Fix svd_compressed Make the right assertion
Closes #2680