5050import dpnp .backend .extensions .statistics ._statistics_impl as statistics_ext
5151
5252# 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
5454
5555__all__ = [
5656 "bincount" ,
@@ -409,9 +409,7 @@ def bincount(x, weights=None, minlength=None):
409409 x_casted , weights_casted , minlength , ntype_casted , usm_type
410410 )
411411
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 )
415413
416414
417415def digitize (x , bins , right = False ):
@@ -657,7 +655,7 @@ def histogram(a, bins=10, range=None, density=None, weights=None):
657655 )
658656 _manager .add_event_pair (mem_ev , ht_ev )
659657
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 )
661659
662660 if density :
663661 db = dpnp .astype (
@@ -811,12 +809,10 @@ def _histdd_make_edges(sample, bins, range, usm_type):
811809
812810
813811def _histdd_flatten_binedges (bedges_list , edges_count_list , dtype ):
814- queue = bedges_list [0 ].sycl_queue
815- usm_type = bedges_list [0 ].usm_type
816812 total_edges_size = numpy .sum (edges_count_list )
817813
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
820816 )
821817
822818 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):
932928 ----------
933929 sample : {dpnp.ndarray, usm_ndarray}
934930 Input (N, D)-shaped array to be histogrammed.
935-
936931 bins : {sequence, int}, optional
937932 The bin specification:
933+
938934 * A sequence of arrays describing the monotonically increasing bin
939935 edges along each dimension.
940936 * The number of bins for each dimension (nx, ny, ... =bins)
941937 * The number of bins for all dimensions (nx=ny=...=bins).
938+
942939 Default: ``10``
943940 range : {None, sequence}, optional
944941 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):
947944 An entry of None in the sequence results in the minimum and maximum
948945 values being used for the corresponding dimension.
949946 None is equivalent to passing a tuple of D None values.
947+
950948 Default: ``None``
951949 weights : {dpnp.ndarray, usm_ndarray}, optional
952950 An (N,)-shaped array of values `w_i` weighing each sample
953951 `(x_i, y_i, z_i, ...)`.
954952 Weights are normalized to 1 if density is True. If density is False,
955953 the values of the returned histogram are equal to the sum of the
956954 weights belonging to the samples falling into each bin.
955+
957956 Default: ``None``
958957 density : {bool}, optional
959958 If ``False``, the default, returns the number of samples in each bin.
960959 If ``True``, returns the probability *density* function at the bin,
961960 ``bin_count / sample_count / bin_volume``.
961+
962962 Default: ``False``
963963
964964 Returns
965965 -------
966966 H : {dpnp.ndarray}
967967 The multidimensional histogram of sample x. See density and weights
968968 for the different possible semantics.
969- edges : {list of ndarrays }
969+ edges : {list of dpnp.ndarray }
970970 A list of D arrays describing the bin edges for each dimension.
971971
972972 See Also
@@ -977,36 +977,26 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False):
977977 Examples
978978 --------
979979 >>> import dpnp as np
980- >>> r = np.random.normal(size=(100,3))
980+ >>> r = np.random.normal(size=(100, 3))
981981 >>> H, edges = np.histogramdd(r, bins = (5, 8, 4))
982982 >>> H.shape, edges[0].size, edges[1].size, edges[2].size
983983 ((5, 8, 4), 6, 9, 5)
984984
985985 """
986986
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 )
992990
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 :
996992 sample = dpnp .reshape (sample , (sample .size , 1 ))
997993 elif sample .ndim > 2 :
998994 raise ValueError ("sample must have no more than 2 dimensions" )
999995
1000996 ndim = sample .shape [1 ] if sample .size > 0 else 1
1001997
1002998 _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 )
10101000
10111001 bins = _histdd_normalize_bins (bins , ndim )
10121002 range = _histdd_normalize_range (range , ndim )
@@ -1037,7 +1027,7 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False):
10371027 )
10381028
10391029 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 )
10411031
10421032 if density :
10431033 # calculate the probability density function
0 commit comments