You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ma...@apache.org on 2018/06/06 21:34:40 UTC

[incubator-mxnet] branch v1.2.0 updated: Fix test_sparse_mathematical_core sensitivity to scipy v1.1 (#10961) (#11175)

This is an automated email from the ASF dual-hosted git repository.

marcoabreu pushed a commit to branch v1.2.0
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/v1.2.0 by this push:
     new c2bfcf0  Fix test_sparse_mathematical_core sensitivity to scipy v1.1 (#10961) (#11175)
c2bfcf0 is described below

commit c2bfcf093100081816a34fe25aa794a4567d5e27
Author: Marco de Abreu <ma...@users.noreply.github.com>
AuthorDate: Wed Jun 6 23:34:32 2018 +0200

    Fix test_sparse_mathematical_core sensitivity to scipy v1.1 (#10961) (#11175)
---
 tests/python/unittest/test_sparse_operator.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tests/python/unittest/test_sparse_operator.py b/tests/python/unittest/test_sparse_operator.py
index 2c9bedd..e2a040a 100644
--- a/tests/python/unittest/test_sparse_operator.py
+++ b/tests/python/unittest/test_sparse_operator.py
@@ -1035,12 +1035,16 @@ def test_sparse_mathematical_core():
 
             try:
                 from scipy import special as scipy_special
-                import_succeeded = True
+                # On scipy v1.0, psi([0, -1, -2, -3, ...]) = [ inf, inf, inf, inf, ...]
+                # On scipy v1.1, psi([0, -1, -2, -3, ...]) = [-inf, nan, nan, nan, ...]
+                # Map the behavior of v1.1 psi() to that of v1.0 for ints <= 0 for consistency
+                scipy_psi = np.vectorize(lambda x: np.inf if float(x).is_integer() and x <= 0 else
+                                         scipy_special.psi(x))
                 # gamma
                 check_sparse_mathematical_core("gamma", stype,
                                                lambda x: mx.sym.sparse.gamma(x),
                                                lambda x: scipy_special.gamma(x),
-                                               lambda x: scipy_special.gamma(x) * scipy_special.psi(x),
+                                               lambda x: scipy_special.gamma(x) * scipy_psi(x),
                                                output_grad_stype=output_grad_stype,
                                                input_grad_stype=input_grad_stype,
                                                force_overlap=force_overlap,
@@ -1049,17 +1053,14 @@ def test_sparse_mathematical_core():
                 check_sparse_mathematical_core("gammaln", stype,
                                                lambda x: mx.sym.sparse.gammaln(x),
                                                lambda x: scipy_special.gammaln(x),
-                                               lambda x: scipy_special.psi(x),
+                                               lambda x: scipy_psi(x),
                                                output_grad_stype=output_grad_stype,
                                                input_grad_stype=input_grad_stype,
                                                force_overlap=force_overlap,
                                                density=density, ograd_density=ograd_density)
 
-            except:
-                if import_succeeded == False:
-                    print("Could not import scipy. Skipping unit tests for special functions")
-                else:
-                    raise
+            except ImportError:
+                print("Could not import scipy. Skipping unit tests for special functions")
 
     for i in range(1):
         print("pass", i)

-- 
To stop receiving notification emails like this one, please contact
marcoabreu@apache.org.