Exemple #1
0
 def test_histogram_density(self, xp, dtype):
     x = testing.shaped_arange((10, ), xp, dtype)
     y, bin_edges = xp.histogram(x, density=True)
     # check normalization
     area = xp.sum(y * xp.diff(bin_edges))
     testing.assert_allclose(area, 1)
     return y, bin_edges
Exemple #2
0
    def test_count_nonzero_int_axis(self, dtype):
        for ax in range(3):

            def func(xp):
                m = testing.shaped_random((2, 3, 4), xp, xp.bool_)
                a = testing.shaped_random((2, 3, 4), xp, dtype) * m
                return xp.count_nonzero(a, axis=ax)

            testing.assert_allclose(func(numpy), func(cupy))
Exemple #3
0
 def check_returned(self, a, axis, weights):
     average_cpu, sum_weights_cpu = numpy.average(
         a, axis, weights, returned=True)
     result = cupy.average(
         cupy.asarray(a), axis, weights, returned=True)
     self.assertTrue(isinstance(result, tuple))
     self.assertEqual(len(result), 2)
     average_gpu, sum_weights_gpu = result
     testing.assert_allclose(average_cpu, average_gpu)
     testing.assert_allclose(sum_weights_cpu, sum_weights_gpu)
Exemple #4
0
    def test_count_nonzero_tuple_axis(self, dtype):
        for ax in range(3):
            for ay in range(3):
                if ax == ay:
                    continue

                def func(xp):
                    m = testing.shaped_random((2, 3, 4), xp, xp.bool_)
                    a = testing.shaped_random((2, 3, 4), xp, dtype) * m
                    return xp.count_nonzero(a, axis=(ax, ay))

                testing.assert_allclose(func(numpy), func(cupy))
Exemple #5
0
 def test_histogram_range_with_weights_and_density(self, xp, dtype):
     a = xp.arange(10, dtype=dtype) + .5
     w = xp.arange(10, dtype=dtype) + .5
     h, b = xp.histogram(a, range=[1, 9], weights=w, density=True)
     testing.assert_allclose(float((h * xp.diff(b)).sum()), 1)
     return h
Exemple #6
0
 def test_histogram_range_with_density(self, xp, dtype):
     a = xp.arange(10, dtype=dtype) + .5
     h, b = xp.histogram(a, range=[1, 9], density=True)
     # check normalization
     testing.assert_allclose(float((h * xp.diff(b)).sum()), 1)
     return h