コード例 #1
0
ファイル: test_half.py プロジェクト: frank1991430/test
    def test_nans_infs(self):
        with np.errstate(all='ignore'):
            # Check some of the ufuncs
            assert_equal(np.isnan(self.all_f16), np.isnan(self.all_f32))
            assert_equal(np.isinf(self.all_f16), np.isinf(self.all_f32))
            assert_equal(np.isfinite(self.all_f16), np.isfinite(self.all_f32))
            assert_equal(np.signbit(self.all_f16), np.signbit(self.all_f32))
            assert_equal(np.spacing(float16(65504)), np.inf)

            # Check comparisons of all values with NaN
            nan = float16(np.nan)

            assert_(not (self.all_f16 == nan).any())
            assert_(not (nan == self.all_f16).any())

            assert_((self.all_f16 != nan).all())
            assert_((nan != self.all_f16).all())

            assert_(not (self.all_f16 < nan).any())
            assert_(not (nan < self.all_f16).any())

            assert_(not (self.all_f16 <= nan).any())
            assert_(not (nan <= self.all_f16).any())

            assert_(not (self.all_f16 > nan).any())
            assert_(not (nan > self.all_f16).any())

            assert_(not (self.all_f16 >= nan).any())
            assert_(not (nan >= self.all_f16).any())
コード例 #2
0
 def _check_ninf_nan(dummy):
     msgform = "csqrt(-inf, nan) is (%f, %f), expected (nan, +-inf)"
     z = np.sqrt(np.array(complex(-np.inf, np.nan)))
     #Fixme: ugly workaround for isinf bug.
     with np.errstate(invalid='ignore'):
         if not (np.isnan(z.real) and np.isinf(z.imag)):
             raise AssertionError(msgform % (z.real, z.imag))
コード例 #3
0
ファイル: test_scalarmath.py プロジェクト: frank1991430/test
 def test_zero_division(self):
     with np.errstate(all="ignore"):
         for t in [np.complex64, np.complex128]:
             a = t(0.0)
             b = t(1.0)
             assert_(np.isinf(b / a))
             b = t(complex(np.inf, np.inf))
             assert_(np.isinf(b / a))
             b = t(complex(np.inf, np.nan))
             assert_(np.isinf(b / a))
             b = t(complex(np.nan, np.inf))
             assert_(np.isinf(b / a))
             b = t(complex(np.nan, np.nan))
             assert_(np.isnan(b / a))
             b = t(0.)
             assert_(np.isnan(b / a))
コード例 #4
0
 def test_masked(self):
     mat = np.ma.fix_invalid(_ndat)
     msk = mat._mask.copy()
     for f in [np.nanmin]:
         res = f(mat, axis=1)
         tgt = f(_ndat, axis=1)
         assert_equal(res, tgt)
         assert_equal(mat._mask, msk)
         assert_(not np.isinf(mat).any())
コード例 #5
0
ファイル: test_half.py プロジェクト: frank1991430/test
    def test_half_ufuncs(self):
        """Test the various ufuncs"""

        a = np.array([0, 1, 2, 4, 2], dtype=float16)
        b = np.array([-2, 5, 1, 4, 3], dtype=float16)
        c = np.array([0, -1, -np.inf, np.nan, 6], dtype=float16)

        assert_equal(np.add(a, b), [-2, 6, 3, 8, 5])
        assert_equal(np.subtract(a, b), [2, -4, 1, 0, -1])
        assert_equal(np.multiply(a, b), [0, 5, 2, 16, 6])
        assert_equal(np.divide(a, b), [0, 0.199951171875, 2, 1, 0.66650390625])

        assert_equal(np.equal(a, b), [False, False, False, True, False])
        assert_equal(np.not_equal(a, b), [True, True, True, False, True])
        assert_equal(np.less(a, b), [False, True, False, False, True])
        assert_equal(np.less_equal(a, b), [False, True, False, True, True])
        assert_equal(np.greater(a, b), [True, False, True, False, False])
        assert_equal(np.greater_equal(a, b), [True, False, True, True, False])
        assert_equal(np.logical_and(a, b), [False, True, True, True, True])
        assert_equal(np.logical_or(a, b), [True, True, True, True, True])
        assert_equal(np.logical_xor(a, b), [True, False, False, False, False])
        assert_equal(np.logical_not(a), [True, False, False, False, False])

        assert_equal(np.isnan(c), [False, False, False, True, False])
        assert_equal(np.isinf(c), [False, False, True, False, False])
        assert_equal(np.isfinite(c), [True, True, False, False, True])
        assert_equal(np.signbit(b), [True, False, False, False, False])

        assert_equal(np.copysign(b, a), [2, 5, 1, 4, 3])

        assert_equal(np.maximum(a, b), [0, 5, 2, 4, 3])
        x = np.maximum(b, c)
        assert_(np.isnan(x[3]))
        x[3] = 0
        assert_equal(x, [0, 5, 1, 0, 6])
        assert_equal(np.minimum(a, b), [-2, 1, 1, 4, 2])
        x = np.minimum(b, c)
        assert_(np.isnan(x[3]))
        x[3] = 0
        assert_equal(x, [-2, -1, -np.inf, 0, 3])
        assert_equal(np.fmax(a, b), [0, 5, 2, 4, 3])
        assert_equal(np.fmax(b, c), [0, 5, 1, 4, 6])
        assert_equal(np.fmin(a, b), [-2, 1, 1, 4, 2])
        assert_equal(np.fmin(b, c), [-2, -1, -np.inf, 4, 3])

        assert_equal(np.floor_divide(a, b), [0, 0, 2, 1, 0])
        assert_equal(np.remainder(a, b), [0, 1, 0, 0, 2])
        assert_equal(np.divmod(a, b), ([0, 0, 2, 1, 0], [0, 1, 0, 0, 2]))
        assert_equal(np.square(b), [4, 25, 1, 16, 9])
        assert_equal(np.reciprocal(b),
                     [-0.5, 0.199951171875, 1, 0.25, 0.333251953125])
        assert_equal(np.ones_like(b), [1, 1, 1, 1, 1])
        assert_equal(np.conjugate(b), b)
        assert_equal(np.absolute(b), [2, 5, 1, 4, 3])
        assert_equal(np.negative(b), [2, -5, -1, -4, -3])
        assert_equal(np.positive(b), b)
        assert_equal(np.sign(b), [-1, 1, 1, 1, 1])
        assert_equal(np.modf(b), ([0, 0, 0, 0, 0], b))
        assert_equal(np.frexp(b),
                     ([-0.5, 0.625, 0.5, 0.5, 0.75], [2, 3, 1, 3, 2]))
        assert_equal(np.ldexp(b, [0, 1, 2, 4, 2]), [-2, 10, 4, 64, 12])
コード例 #6
0
 def test_ind(self):
     with np.errstate(divide='ignore', invalid='ignore'):
         assert_all(np.isinf(np.array((0., )) / 0.) == 0)
コード例 #7
0
 def test_neginf_scalar(self):
     with np.errstate(divide='ignore', invalid='ignore'):
         assert_all(np.isinf(np.array(-1.) / 0.) == 1)
コード例 #8
0
 def test_goodvalues(self):
     z = np.array((-1., 0., 1.))
     res = np.isinf(z) == 0
     assert_all(np.all(res, axis=0))
コード例 #9
0
 def _check_inf_inf(dummy):
     msgform = "cexp(inf, inf) is (%f, %f), expected (+-inf, nan)"
     with np.errstate(invalid='ignore'):
         z = f(np.array(complex(np.inf, np.inf)))
         if not np.isinf(z.real) or not np.isnan(z.imag):
             raise AssertionError(msgform % (z.real, z.imag))