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
TST: Review _assert_within_tol
positional arguments
#15087
Merged
Kai-Striega
merged 9 commits into
scipy:master
from
Kai-Striega:fix_distance_verbosity_test
Dec 2, 2021
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7104f8f
TST: Review ``_assert_within_tol`` positional arguments
Kai-Striega 192c768
STY: Fix whitespace around operators
Kai-Striega 623f6f4
TST: Review test tolerances
Kai-Striega 1bc855f
TST: Remove ``_asert_within_tol`` helper function
Kai-Striega 3a6faa4
TST: Use atol for ``test_pdist_cosine_iris_*`` tests
Kai-Striega d3bdc48
Merge branch 'master' into fix_distance_verbosity_test
Kai-Striega c382bdf
TST: Remove `_assert_within_tol` from merge commit
Kai-Striega 229b658
TST: Fix verbose_ argument
Kai-Striega abbfda5
TST: Revert to `atol` test_pdist_jensenshannon_iris
Kai-Striega File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,24 +439,24 @@ def _my_metric(x, y, arg, kwarg=1, kwarg2=2): | |
arg=1.1, kwarg2=3.3), 5.4) | ||
|
||
def test_cdist_euclidean_random_unicode(self): | ||
eps = 1e-07 | ||
eps = 1e-15 | ||
X1 = eo['cdist-X1'] | ||
X2 = eo['cdist-X2'] | ||
Y1 = wcdist_no_const(X1, X2, 'euclidean') | ||
Y2 = wcdist_no_const(X1, X2, 'test_euclidean') | ||
_assert_within_tol(Y1, Y2, eps, verbose > 2) | ||
_assert_within_tol(Y1, Y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
@pytest.mark.parametrize("p", [1.0, 1.23, 2.0, 3.8, 4.6, np.inf]) | ||
def test_cdist_minkowski_random(self, p): | ||
eps = 1e-07 | ||
eps = 1e-15 | ||
X1 = eo['cdist-X1'] | ||
X2 = eo['cdist-X2'] | ||
Y1 = wcdist_no_const(X1, X2, 'minkowski', p=p) | ||
Y2 = wcdist_no_const(X1, X2, 'test_minkowski', p=p) | ||
_assert_within_tol(Y1, Y2, eps, verbose > 2) | ||
_assert_within_tol(Y1, Y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
def test_cdist_cosine_random(self): | ||
eps = 1e-07 | ||
eps = 1e-14 | ||
X1 = eo['cdist-X1'] | ||
X2 = eo['cdist-X2'] | ||
Y1 = wcdist(X1, X2, 'cosine') | ||
|
@@ -467,7 +467,7 @@ def norms(X): | |
|
||
Y2 = 1 - np.dot((X1 / norms(X1)), (X2 / norms(X2)).T) | ||
|
||
_assert_within_tol(Y1, Y2, eps, verbose > 2) | ||
_assert_within_tol(Y1, Y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
def test_cdist_mahalanobis(self): | ||
# 1-dimensional observations | ||
|
@@ -575,11 +575,11 @@ def test_cdist_dtype_equivalence(self): | |
else: | ||
for new_type in test[1]: | ||
y2 = cdist(new_type(X1), new_type(X2), metric=metric) | ||
_assert_within_tol(y1, y2, eps, verbose > 2) | ||
_assert_within_tol(y1, y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
def test_cdist_out(self): | ||
# Test that out parameter works properly | ||
eps = 1e-07 | ||
eps = 1e-15 | ||
X1 = eo['cdist-X1'] | ||
X2 = eo['cdist-X2'] | ||
out_r, out_c = X1.shape[0], X2.shape[0] | ||
|
@@ -592,7 +592,7 @@ def test_cdist_out(self): | |
Y1 = cdist(X1, X2, metric, **kwargs) | ||
Y2 = cdist(X1, X2, metric, out=out1, **kwargs) | ||
# test that output is numerically equivalent | ||
_assert_within_tol(Y1, Y2, eps, verbose > 2) | ||
_assert_within_tol(Y1, Y2, rtol=eps, verbose_=verbose > 2) | ||
# test that Y_test1 and out1 are the same object | ||
assert_(Y2 is out1) | ||
# test for incorrect shape | ||
|
@@ -616,7 +616,7 @@ def test_cdist_out(self): | |
def test_striding(self): | ||
# test that striding is handled correct with calls to | ||
# _copy_array_if_base_present | ||
eps = 1e-07 | ||
eps = 1e-15 | ||
X1 = eo['cdist-X1'][::2, ::2] | ||
X2 = eo['cdist-X2'][::2, ::2] | ||
X1_copy = X1.copy() | ||
|
@@ -638,7 +638,7 @@ def test_striding(self): | |
Y1 = cdist(X1, X2, metric, **kwargs) | ||
Y2 = cdist(X1_copy, X2_copy, metric, **kwargs) | ||
# test that output is numerically equivalent | ||
_assert_within_tol(Y1, Y2, eps, verbose > 2) | ||
_assert_within_tol(Y1, Y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
def test_cdist_refcount(self): | ||
for metric in _METRICS_NAMES: | ||
|
@@ -747,7 +747,7 @@ def test_pdist_euclidean_iris_float32(self): | |
X = np.float32(eo['iris']) | ||
Y_right = eo['pdist-euclidean-iris'] | ||
Y_test1 = wpdist_no_const(X, 'euclidean') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
@pytest.mark.slow | ||
def test_pdist_euclidean_iris_nonC(self): | ||
|
@@ -846,7 +846,7 @@ def test_pdist_cosine_iris_float32(self): | |
X = np.float32(eo['iris']) | ||
Y_right = eo['pdist-cosine-iris'] | ||
Y_test1 = wpdist(X, 'cosine') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and here... |
||
|
||
@pytest.mark.slow | ||
def test_pdist_cosine_iris_nonC(self): | ||
|
@@ -900,7 +900,7 @@ def test_pdist_cityblock_iris_float32(self): | |
X = np.float32(eo['iris']) | ||
Y_right = eo['pdist-cityblock-iris'] | ||
Y_test1 = wpdist_no_const(X, 'cityblock') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
|
||
@pytest.mark.slow | ||
def test_pdist_cityblock_iris_nonC(self): | ||
|
@@ -947,7 +947,7 @@ def test_pdist_correlation_iris_float32(self): | |
X = eo['iris'] | ||
Y_right = np.float32(eo['pdist-correlation-iris']) | ||
Y_test1 = wpdist(X, 'correlation') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
|
||
@pytest.mark.slow | ||
def test_pdist_correlation_iris_nonC(self): | ||
|
@@ -1024,7 +1024,7 @@ def test_pdist_minkowski_5_8_iris_float32(self): | |
X = np.float32(eo['iris']) | ||
Y_right = eo['pdist-minkowski-5.8-iris'] | ||
Y_test1 = wpdist_no_const(X, 'minkowski', p=5.8) | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
|
||
@pytest.mark.slow | ||
def test_pdist_minkowski_5_8_iris_nonC(self): | ||
|
@@ -1178,7 +1178,7 @@ def test_pdist_jensenshannon_iris_float32(self): | |
X = np.float32(eo['iris']) | ||
Y_right = eo['pdist-jensenshannon-iris'] | ||
Y_test1 = pdist(X, 'jensenshannon') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
|
||
def test_pdist_jensenshannon_iris_nonC(self): | ||
eps = 5e-12 | ||
|
@@ -1204,7 +1204,7 @@ def test_pdist_chebyshev_random_float32(self): | |
X = np.float32(eo['pdist-double-inp']) | ||
Y_right = eo['pdist-chebyshev'] | ||
Y_test1 = pdist(X, 'chebyshev') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
|
||
def test_pdist_chebyshev_random_nonC(self): | ||
eps = 1e-08 | ||
|
@@ -1225,7 +1225,7 @@ def test_pdist_chebyshev_iris_float32(self): | |
X = np.float32(eo['iris']) | ||
Y_right = eo['pdist-chebyshev-iris'] | ||
Y_test1 = pdist(X, 'chebyshev') | ||
_assert_within_tol(Y_test1, Y_right, eps, verbose > 2) | ||
_assert_within_tol(Y_test1, Y_right, atol=eps, verbose_=verbose > 2) | ||
|
||
def test_pdist_chebyshev_iris_nonC(self): | ||
eps = 1e-15 | ||
|
@@ -1376,15 +1376,15 @@ def test_pdist_canberra_match(self): | |
eps = 1e-10 | ||
y1 = wpdist_no_const(D, "canberra") | ||
y2 = wpdist_no_const(D, "test_canberra") | ||
_assert_within_tol(y1, y2, eps, verbose > 2) | ||
_assert_within_tol(y1, y2, atol=eps, verbose_=verbose > 2) | ||
|
||
def test_pdist_canberra_ticket_711(self): | ||
# Test pdist(X, 'canberra') to see if Canberra gives the right result | ||
# as reported on gh-1238. | ||
eps = 1e-8 | ||
pdist_y = wpdist_no_const(([3.3], [3.4]), "canberra") | ||
right_y = 0.01492537 | ||
_assert_within_tol(pdist_y, right_y, eps, verbose > 2) | ||
_assert_within_tol(pdist_y, right_y, atol=eps, verbose_=verbose > 2) | ||
|
||
def test_pdist_custom_notdouble(self): | ||
# tests that when using a custom metric the data type is not altered | ||
|
@@ -1470,7 +1470,7 @@ def test_pdist_dtype_equivalence(self): | |
else: | ||
for new_type in test[1]: | ||
y2 = pdist(new_type(X1), metric=metric) | ||
_assert_within_tol(y1, y2, eps, verbose > 2) | ||
_assert_within_tol(y1, y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
def test_pdist_out(self): | ||
# Test that out parameter works properly | ||
|
@@ -1516,7 +1516,7 @@ def test_striding(self): | |
Y1 = pdist(X, metric, **kwargs) | ||
Y2 = pdist(X_copy, metric, **kwargs) | ||
# test that output is numerically equivalent | ||
_assert_within_tol(Y1, Y2, eps, verbose > 2) | ||
_assert_within_tol(Y1, Y2, rtol=eps, verbose_=verbose > 2) | ||
|
||
class TestSomeDistanceFunctions: | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try tightening the
eps
in this test? It's still at1e-07
.