Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_density for histogram #1115

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def convert_single_elem_array_to_scalar(obj, keepdims=False):

if (obj.ndim > 0) and (obj.size == 1) and (keepdims is False):
return obj.dtype.type(obj[0])
elif (obj.ndim == 0):
return obj.dtype.type(obj)

return obj

Expand Down Expand Up @@ -221,6 +223,9 @@ def get_dpnp_descriptor(ext_obj, copy_when_strides=True, copy_when_nondefault_qu
if ext_obj.strides != shape_offsets or ext_obj_offset != 0:
ext_obj = array(ext_obj)

if numpy.isscalar(ext_obj) and isinstance(ext_obj, numpy.generic):
ext_obj = array(ext_obj)

# while dpnp functions are based on DPNP_QUEUE
# we need to create a copy on device associated with DPNP_QUEUE
# if function get implementation for different queue
Expand Down
1 change: 0 additions & 1 deletion tests/skipped_tests_gpu.tbl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([[i, i] for i in x])]

tests/test_arraymanipulation.py::TestConcatenate::test_concatenate
tests/test_histograms.py::TestHistogram::test_density
tests/test_mathematical.py::TestGradient::test_gradient_y1[array0]
tests/test_mathematical.py::TestGradient::test_gradient_y1[array1]
tests/test_mathematical.py::TestGradient::test_gradient_y1[array2]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def test_density(self):
n = 100
v = dpnp.random.rand(n)
a, b = dpnp.histogram(v, density=True)
area = dpnp.sum(a * dpnp.diff(b)[0])[0]
area = dpnp.sum(a * dpnp.diff(b)[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)
numpy.testing.assert_equal(dpnp.sum(a * dpnp.diff(b)), 1)

# Test that passing False works too
a, b = dpnp.histogram(v, bins, density=False)
Expand Down