test_arrayfuncs.py 793 B

1234567891011121314151617181920212223242526
  1. import numpy as np
  2. import pytest
  3. from sklearn.utils._testing import assert_allclose
  4. from sklearn.utils.arrayfuncs import min_pos
  5. def test_min_pos():
  6. # Check that min_pos returns a positive value and that it's consistent
  7. # between float and double
  8. X = np.random.RandomState(0).randn(100)
  9. min_double = min_pos(X)
  10. min_float = min_pos(X.astype(np.float32))
  11. assert_allclose(min_double, min_float)
  12. assert min_double >= 0
  13. @pytest.mark.parametrize("dtype", [np.float32, np.float64])
  14. def test_min_pos_no_positive(dtype):
  15. # Check that the return value of min_pos is the maximum representable
  16. # value of the input dtype when all input elements are <= 0 (#19328)
  17. X = np.full(100, -1.0).astype(dtype, copy=False)
  18. assert min_pos(X) == np.finfo(dtype).max