Exemplo n.º 1
0
    def test_density(self):
        # Check that the integral of the density equals 1.
        n = 100
        v = dpnp.random.rand(n)
        a, b = dpnp.histogram(v, density=True)
        area = dpnp.sum(a * dpnp.diff(b)[0])[0]
        numpy.testing.assert_almost_equal(area, 1)

        # Check with non-constant bin widths
        v = dpnp.arange(10)
        bins = [0, 1, 3, 6, 10]
        a, b = dpnp.histogram(v, bins, density=True)
        numpy.testing.assert_array_equal(a, .1)
        numpy.testing.assert_equal(dpnp.sum(a * dpnp.diff(b))[0], 1)

        # Test that passing False works too
        a, b = dpnp.histogram(v, bins, density=False)
        numpy.testing.assert_array_equal(a, [1, 2, 3, 4])

        # Variable bin widths are especially useful to deal with
        # infinities.
        v = dpnp.arange(10)
        bins = [0, 1, 3, 6, numpy.inf]
        a, b = dpnp.histogram(v, bins, density=True)
        numpy.testing.assert_array_equal(a, [.1, .1, .1, 0.])

        # Taken from a bug report from N. Becker on the numpy-discussion
        # mailing list Aug. 6, 2010.
        counts, dmy = dpnp.histogram([1, 2, 3, 4], [0.5, 1.5, numpy.inf],
                                     density=True)
        numpy.testing.assert_equal(counts, [.25, 0])
Exemplo n.º 2
0
def test_diff(array):
    a = numpy.array(array)
    ia = inp.array(a)
    expected = numpy.diff(a)
    result = inp.diff(ia)
    numpy.testing.assert_allclose(expected, result)
Exemplo n.º 3
0
def test_diff(array):
    np_a = numpy.array(array)
    dpnp_a = dpnp.array(array)
    expected = numpy.diff(np_a)
    result = dpnp.diff(dpnp_a)
    numpy.testing.assert_allclose(expected, result)