50
50
import dpnp .backend .extensions .statistics ._statistics_impl as statistics_ext
51
51
52
52
# pylint: disable=no-name-in-module
53
- from .dpnp_utils import map_dtype_to_device
53
+ from .dpnp_utils import get_usm_allocations , map_dtype_to_device
54
54
55
55
__all__ = [
56
56
"bincount" ,
@@ -409,9 +409,7 @@ def bincount(x, weights=None, minlength=None):
409
409
x_casted , weights_casted , minlength , ntype_casted , usm_type
410
410
)
411
411
412
- n = dpnp .asarray (n_casted , dtype = ntype , usm_type = usm_type , order = "C" )
413
-
414
- return n
412
+ return dpnp .asarray (n_casted , dtype = ntype , usm_type = usm_type )
415
413
416
414
417
415
def digitize (x , bins , right = False ):
@@ -657,7 +655,7 @@ def histogram(a, bins=10, range=None, density=None, weights=None):
657
655
)
658
656
_manager .add_event_pair (mem_ev , ht_ev )
659
657
660
- n = dpnp .asarray (n_casted , dtype = ntype , usm_type = usm_type , order = "C" )
658
+ n = dpnp .asarray (n_casted , dtype = ntype , usm_type = usm_type )
661
659
662
660
if density :
663
661
db = dpnp .astype (
@@ -811,12 +809,10 @@ def _histdd_make_edges(sample, bins, range, usm_type):
811
809
812
810
813
811
def _histdd_flatten_binedges (bedges_list , edges_count_list , dtype ):
814
- queue = bedges_list [0 ].sycl_queue
815
- usm_type = bedges_list [0 ].usm_type
816
812
total_edges_size = numpy .sum (edges_count_list )
817
813
818
- bin_edges_flat = dpnp .empty (
819
- shape = total_edges_size , dtype = dtype , sycl_queue = queue , usm_type = usm_type
814
+ bin_edges_flat = dpnp .empty_like (
815
+ bedges_list [ 0 ], shape = total_edges_size , dtype = dtype
820
816
)
821
817
822
818
offset = numpy .pad (numpy .cumsum (edges_count_list ), (1 , 0 ))
@@ -932,13 +928,14 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False):
932
928
----------
933
929
sample : {dpnp.ndarray, usm_ndarray}
934
930
Input (N, D)-shaped array to be histogrammed.
935
-
936
931
bins : {sequence, int}, optional
937
932
The bin specification:
933
+
938
934
* A sequence of arrays describing the monotonically increasing bin
939
935
edges along each dimension.
940
936
* The number of bins for each dimension (nx, ny, ... =bins)
941
937
* The number of bins for all dimensions (nx=ny=...=bins).
938
+
942
939
Default: ``10``
943
940
range : {None, sequence}, optional
944
941
A sequence of length D, each an optional (lower, upper) tuple giving
@@ -947,26 +944,29 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False):
947
944
An entry of None in the sequence results in the minimum and maximum
948
945
values being used for the corresponding dimension.
949
946
None is equivalent to passing a tuple of D None values.
947
+
950
948
Default: ``None``
951
949
weights : {dpnp.ndarray, usm_ndarray}, optional
952
950
An (N,)-shaped array of values `w_i` weighing each sample
953
951
`(x_i, y_i, z_i, ...)`.
954
952
Weights are normalized to 1 if density is True. If density is False,
955
953
the values of the returned histogram are equal to the sum of the
956
954
weights belonging to the samples falling into each bin.
955
+
957
956
Default: ``None``
958
957
density : {bool}, optional
959
958
If ``False``, the default, returns the number of samples in each bin.
960
959
If ``True``, returns the probability *density* function at the bin,
961
960
``bin_count / sample_count / bin_volume``.
961
+
962
962
Default: ``False``
963
963
964
964
Returns
965
965
-------
966
966
H : {dpnp.ndarray}
967
967
The multidimensional histogram of sample x. See density and weights
968
968
for the different possible semantics.
969
- edges : {list of ndarrays }
969
+ edges : {list of dpnp.ndarray }
970
970
A list of D arrays describing the bin edges for each dimension.
971
971
972
972
See Also
@@ -977,36 +977,26 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False):
977
977
Examples
978
978
--------
979
979
>>> import dpnp as np
980
- >>> r = np.random.normal(size=(100,3))
980
+ >>> r = np.random.normal(size=(100, 3))
981
981
>>> H, edges = np.histogramdd(r, bins = (5, 8, 4))
982
982
>>> H.shape, edges[0].size, edges[1].size, edges[2].size
983
983
((5, 8, 4), 6, 9, 5)
984
984
985
985
"""
986
986
987
- if not dpnp .is_supported_array_type (sample ):
988
- raise ValueError ("sample must be dpnp.ndarray or usm_ndarray" )
989
-
990
- if weights is not None and not dpnp .is_supported_array_type (weights ):
991
- raise ValueError ("weights must be dpnp.ndarray or usm_ndarray" )
987
+ dpnp .check_supported_arrays_type (sample )
988
+ if weights is not None :
989
+ dpnp .check_supported_arrays_type (weights )
992
990
993
- if sample .ndim == 0 and sample .size == 1 :
994
- sample = dpnp .reshape (sample , (1 , 1 ))
995
- elif sample .ndim == 1 :
991
+ if sample .ndim < 2 :
996
992
sample = dpnp .reshape (sample , (sample .size , 1 ))
997
993
elif sample .ndim > 2 :
998
994
raise ValueError ("sample must have no more than 2 dimensions" )
999
995
1000
996
ndim = sample .shape [1 ] if sample .size > 0 else 1
1001
997
1002
998
_arrays = _histdd_extract_arrays (sample , weights , bins )
1003
- usm_type = dpu .get_coerced_usm_type ([a .usm_type for a in _arrays ])
1004
- queue = dpu .get_execution_queue ([a .sycl_queue for a in _arrays ])
1005
-
1006
- assert usm_type is not None
1007
-
1008
- if queue is None :
1009
- raise ValueError ("all arrays must be allocated on the same SYCL queue" )
999
+ usm_type , queue = get_usm_allocations (_arrays )
1010
1000
1011
1001
bins = _histdd_normalize_bins (bins , ndim )
1012
1002
range = _histdd_normalize_range (range , ndim )
@@ -1037,7 +1027,7 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False):
1037
1027
)
1038
1028
1039
1029
expexted_hist_dtype = _histdd_hist_dtype (queue , weights )
1040
- n = dpnp .asarray (n , dtype = expexted_hist_dtype , usm_type = usm_type , order = "C" )
1030
+ n = dpnp .asarray (n , dtype = expexted_hist_dtype , usm_type = usm_type )
1041
1031
1042
1032
if density :
1043
1033
# calculate the probability density function
0 commit comments