diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index e4fe0bcc4b2..9d5ff5a4ef0 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -20,3 +20,6 @@ e62718415aa3660da5f607e352c991a063a54219 # Bump clang-format from 12.0.1 to 22.1.0 version c2d65bd451a7d8e5b6319147da95e9dabf7a382b + +# cython-lint cleanup +6afda951b26d59aee7488f40c40968feb4725ad8 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4ff8b1e6ef0..c4a900b477b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -133,3 +133,8 @@ repos: - id: gersemi exclude: "dpnp/backend/cmake/Modules/" args: ["-i", "-l", "88", "--no-warn-about-unknown-commands"] +- repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.19.0 + hooks: + - id: cython-lint + - id: double-quote-cython-strings diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index 1e755770893..e83b6b58859 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -29,7 +29,8 @@ # ***************************************************************************** -cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this namespace for Enum import +# need this namespace for Enum import +cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": cdef enum DPNPFuncName "DPNPFuncName": DPNP_FN_PARTITION_EXT DPNP_FN_RNG_BETA_EXT @@ -70,7 +71,8 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_RNG_WEIBULL_EXT DPNP_FN_RNG_ZIPF_EXT -cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType": # need this namespace for Enum import +# need this namespace for Enum import +cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType": cdef enum DPNPFuncType "DPNPFuncType": DPNP_FT_NONE DPNP_FT_INT @@ -88,7 +90,11 @@ cdef extern from "dpnp_iface_fptr.hpp": DPNPFuncType return_type_no_fp64 void *ptr_no_fp64 - DPNPFuncData get_dpnp_function_ptr(DPNPFuncName name, DPNPFuncType first_type, DPNPFuncType second_type) except + + DPNPFuncData get_dpnp_function_ptr( + DPNPFuncName name, + DPNPFuncType first_type, + DPNPFuncType second_type, + ) except + """ diff --git a/dpnp/dpnp_algo/dpnp_algo.pyx b/dpnp/dpnp_algo/dpnp_algo.pyx index 53abcad1198..c848430cd7e 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pyx +++ b/dpnp/dpnp_algo/dpnp_algo.pyx @@ -62,22 +62,22 @@ cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype): kind = chr(kind) itemsize = dpnp.dtype(dtype).itemsize - if dt_c == 'd': + if dt_c == "d": return DPNP_FT_DOUBLE - elif dt_c == 'f': + elif dt_c == "f": return DPNP_FT_FLOAT - elif kind == 'i': + elif kind == "i": if itemsize == 8: return DPNP_FT_LONG elif itemsize == 4: return DPNP_FT_INT else: utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype) - elif dt_c == 'F': + elif dt_c == "F": return DPNP_FT_CMPLX64 - elif dt_c == 'D': + elif dt_c == "D": return DPNP_FT_CMPLX128 - elif dt_c == '?': + elif dt_c == "?": return DPNP_FT_BOOL else: utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype) @@ -85,7 +85,8 @@ cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype): cdef dpnp_DPNPFuncType_to_dtype(size_t type): """ - Type 'size_t' used instead 'DPNPFuncType' because Cython has lack of Enum support (0.29) + Type 'size_t' used instead 'DPNPFuncType' because + Cython has lack of Enum support (0.29) TODO needs to use DPNPFuncType here """ if type == DPNP_FT_DOUBLE: diff --git a/dpnp/dpnp_algo/dpnp_algo_indexing.pxi b/dpnp/dpnp_algo/dpnp_algo_indexing.pxi index 54ed3e99fba..b44dccb5ee5 100644 --- a/dpnp/dpnp_algo/dpnp_algo_indexing.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_indexing.pxi @@ -42,7 +42,11 @@ __all__ += [ "dpnp_putmask", ] -cpdef dpnp_putmask(utils.dpnp_descriptor arr, utils.dpnp_descriptor mask, utils.dpnp_descriptor values): +cpdef dpnp_putmask( + utils.dpnp_descriptor arr, + utils.dpnp_descriptor mask, + utils.dpnp_descriptor values, +): cdef int values_size = values.size mask_flatiter = mask.get_pyobj().flat diff --git a/dpnp/dpnp_algo/dpnp_algo_sorting.pxi b/dpnp/dpnp_algo/dpnp_algo_sorting.pxi index c9463b71331..516c080a924 100644 --- a/dpnp/dpnp_algo/dpnp_algo_sorting.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_sorting.pxi @@ -43,52 +43,85 @@ __all__ += [ ] -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_partition_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - void * , - void * , - const size_t, - const shape_elem_type * , - const size_t, - const c_dpctl.DPCTLEventVectorRef) - - -cpdef utils.dpnp_descriptor dpnp_partition(utils.dpnp_descriptor arr, int kth, axis=-1, kind='introselect', order=None): +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_partition_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + void *, + void *, + const size_t, + const shape_elem_type *, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) + + +cpdef utils.dpnp_descriptor dpnp_partition( + utils.dpnp_descriptor arr, int kth, + axis=-1, kind="introselect", order=None, +): cdef shape_type_c shape1 = arr.shape - cdef size_t kth_ = kth if kth >= 0 else (arr.ndim + kth) - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype) - - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PARTITION_EXT, param1_type, param1_type) - - cdef utils.dpnp_descriptor arr2 = dpnp.get_dpnp_descriptor(arr.get_pyobj().copy(), copy_when_nondefault_queue=False) + cdef size_t kth_ = ( + kth if kth >= 0 else (arr.ndim + kth) + ) + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(arr.dtype) + ) + + cdef DPNPFuncData kernel_data = ( + get_dpnp_function_ptr( + DPNP_FN_PARTITION_EXT, + param1_type, param1_type, + ) + ) + + cdef utils.dpnp_descriptor arr2 = ( + dpnp.get_dpnp_descriptor( + arr.get_pyobj().copy(), + copy_when_nondefault_queue=False, + ) + ) arr_obj = arr.get_array() - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(arr.shape, - kernel_data.return_type, - None, - device=arr_obj.sycl_device, - usm_type=arr_obj.usm_type, - sycl_queue=arr_obj.sycl_queue) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + arr.shape, + kernel_data.return_type, + None, + device=arr_obj.sycl_device, + usm_type=arr_obj.usm_type, + sycl_queue=arr_obj.sycl_queue, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_partition_t func = kernel_data.ptr - - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, - arr.get_data(), - arr2.get_data(), - result.get_data(), - kth_, - shape1.data(), - arr.ndim, - NULL) # dep_events_ref - - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_partition_t func = ( + kernel_data.ptr + ) + + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, + arr.get_data(), + arr2.get_data(), + result.get_data(), + kth_, + shape1.data(), + arr.ndim, + NULL, + ) + + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index 00f40a0358e..d037bba5179 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -53,9 +53,7 @@ from dpnp.dpnp_algo.dpnp_algo cimport ( dpnp_DPNPFuncType_to_dtype, ) -""" -Python import functions -""" +# Python import functions __all__ = [ "call_origin", "checker_throw_type_error", @@ -75,9 +73,10 @@ cdef ERROR_PREFIX = "DPNP error:" def convert_item(item): if hasattr(item, "__sycl_usm_array_interface__"): item_converted = dpnp.asnumpy(item) - elif hasattr(item, "__array_interface__"): # detect if it is a container (TODO any better way?) - mod_name = getattr(item, "__module__", 'none') - if (mod_name != 'numpy'): + elif hasattr(item, "__array_interface__"): + # detect if it is a container (TODO any better way?) + mod_name = getattr(item, "__module__", "none") + if (mod_name != "numpy"): item_converted = dpnp.asnumpy(item) else: item_converted = item @@ -118,15 +117,28 @@ def call_origin(function, *args, **kwargs): allow_fallback = kwargs.pop("allow_fallback", False) - if not allow_fallback and config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ == 1: - raise NotImplementedError(f"Requested function={function.__name__} with args={args} and kwargs={kwargs} " - "isn't currently supported and would fall back on NumPy implementation. " - "Define environment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` " - "if the fall back is required to be supported without raising an exception.") + if ( + not allow_fallback + and config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ == 1 + ): + raise NotImplementedError( + f"Requested function={function.__name__} " + f"with args={args} and kwargs={kwargs} " + "isn't currently supported and would fall " + "back on NumPy implementation. " + "Define environment variable " + "`DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` " + "to `0` if the fall back is required to be " + "supported without raising an exception." + ) dpnp_inplace = kwargs.pop("dpnp_inplace", False) sycl_queue = kwargs.pop("sycl_queue", None) - # print(f"DPNP call_origin(): Fallback called. \n\t function={function}, \n\t args={args}, \n\t kwargs={kwargs}, \n\t dpnp_inplace={dpnp_inplace}") + # print(f"DPNP call_origin(): Fallback called. " + # f"\n\t function={function}, " + # f"\n\t args={args}, " + # f"\n\t kwargs={kwargs}, " + # f"\n\t dpnp_inplace={dpnp_inplace}") kwargs_out = kwargs.get("out", None) alloc_queues = [sycl_queue] if sycl_queue else [] @@ -155,11 +167,21 @@ def call_origin(function, *args, **kwargs): exec_q = get_execution_queue(alloc_queues) if exec_q is None: - exec_q = dpnp.get_normalized_queue_device(sycl_queue=sycl_queue) - # print(f"DPNP call_origin(): backend called. \n\t function={function}, \n\t args_new={args_new}, \n\t kwargs_new={kwargs_new}, \n\t dpnp_inplace={dpnp_inplace}") + exec_q = dpnp.get_normalized_queue_device( + sycl_queue=sycl_queue + ) + # print(f"DPNP call_origin(): backend called. " + # f"\n\t function={function}, " + # f"\n\t args_new={args_new}, " + # f"\n\t kwargs_new={kwargs_new}, " + # f"\n\t dpnp_inplace={dpnp_inplace}") # TODO need to put array memory into NumPy call result_origin = function(*args_new, **kwargs_new) - # print(f"DPNP call_origin(): result from backend. \n\t result_origin={result_origin}, \n\t args_new={args_new}, \n\t kwargs_new={kwargs_new}, \n\t dpnp_inplace={dpnp_inplace}") + # print(f"DPNP call_origin(): result from backend. " + # f"\n\t result_origin={result_origin}, " + # f"\n\t args_new={args_new}, " + # f"\n\t kwargs_new={kwargs_new}, " + # f"\n\t dpnp_inplace={dpnp_inplace}") result = result_origin if dpnp_inplace: # enough to modify only first argument in place @@ -173,13 +195,22 @@ def call_origin(function, *args, **kwargs): elif isinstance(result, numpy.ndarray): if kwargs_out is None: - # use dtype from input arguments if present or from the result otherwise - result_dtype = kwargs.get("dtype", None) or result_origin.dtype + # use dtype from input arguments if present + # or from the result otherwise + result_dtype = ( + kwargs.get("dtype", None) or result_origin.dtype + ) if exec_q is not None: - result_dtype = map_dtype_to_device(result_origin.dtype, exec_q.sycl_device) - - result = dpnp_container.empty(result_origin.shape, dtype=result_dtype, sycl_queue=exec_q) + result_dtype = map_dtype_to_device( + result_origin.dtype, exec_q.sycl_device + ) + + result = dpnp_container.empty( + result_origin.shape, + dtype=result_dtype, + sycl_queue=exec_q, + ) else: result = kwargs_out @@ -192,10 +223,17 @@ def call_origin(function, *args, **kwargs): res = res_origin if isinstance(res_origin, numpy.ndarray): if exec_q is not None: - result_dtype = map_dtype_to_device(res_origin.dtype, exec_q.sycl_device) + result_dtype = map_dtype_to_device( + res_origin.dtype, + exec_q.sycl_device, + ) else: result_dtype = res_origin.d_type - res = dpnp_container.empty(res_origin.shape, dtype=result_dtype, sycl_queue=exec_q) + res = dpnp_container.empty( + res_origin.shape, + dtype=result_dtype, + sycl_queue=exec_q, + ) copy_from_origin(res, res_origin) result_list.append(res) @@ -215,7 +253,10 @@ def unwrap_array(x1): def _get_coerced_usm_type(objects): - types_in_use = [obj.usm_type for obj in objects if hasattr(obj, "usm_type")] + types_in_use = [ + obj.usm_type for obj in objects + if hasattr(obj, "usm_type") + ] if len(types_in_use) == 0: return None elif len(types_in_use) == 1: @@ -223,12 +264,17 @@ def _get_coerced_usm_type(objects): common_usm_type = get_coerced_usm_type(types_in_use) if common_usm_type is None: - raise ValueError("Input arrays must have coerced USM types") + raise ValueError( + "Input arrays must have coerced USM types" + ) return common_usm_type def _get_common_allocation_queue(objects): - queues_in_use = [obj.sycl_queue for obj in objects if hasattr(obj, "sycl_queue")] + queues_in_use = [ + obj.sycl_queue for obj in objects + if hasattr(obj, "sycl_queue") + ] if len(queues_in_use) == 0: return None elif len(queues_in_use) == 1: @@ -236,25 +282,38 @@ def _get_common_allocation_queue(objects): common_queue = get_execution_queue(queues_in_use) if common_queue is None: - raise ValueError("Input arrays must be allocated on the same SYCL queue") + raise ValueError( + "Input arrays must be allocated " + "on the same SYCL queue" + ) return common_queue def get_usm_allocations(objects): """ - Given a list of objects returns a tuple of USM type and SYCL queue - which can be used for a memory allocation and to follow compute follows data paradigm, - or returns `(None, None)` if the default USM type and SYCL queue can be used. - An exception will be raised, if the paradigm is broken for the given list of objects. + Given a list of objects returns a tuple of USM type + and SYCL queue which can be used for a memory + allocation and to follow compute follows data + paradigm, or returns `(None, None)` if the default + USM type and SYCL queue can be used. + An exception will be raised, if the paradigm is + broken for the given list of objects. """ if not isinstance(objects, (list, tuple)): - raise TypeError("Expected a list or a tuple, got {}".format(type(objects))) + raise TypeError( + "Expected a list or a tuple, got {}".format( + type(objects) + ) + ) if len(objects) == 0: return (None, None) - return (_get_coerced_usm_type(objects), _get_common_allocation_queue(objects)) + return ( + _get_coerced_usm_type(objects), + _get_common_allocation_queue(objects), + ) def map_dtype_to_device(dtype, device): @@ -263,10 +322,14 @@ def map_dtype_to_device(dtype, device): """ dtype = dpnp.dtype(dtype) - if not hasattr(dtype, 'char'): - raise TypeError(f"Invalid type of input dtype={dtype}") + if not hasattr(dtype, "char"): + raise TypeError( + f"Invalid type of input dtype={dtype}" + ) elif not isinstance(device, dpctl.SyclDevice): - raise TypeError(f"Invalid type of input device={device}") + raise TypeError( + f"Invalid type of input device={device}" + ) dtc = dtype.char if dtc == "?" or dpnp.issubdtype(dtype, dpnp.integer): @@ -298,44 +361,65 @@ def map_dtype_to_device(dtype, device): return dtype # complex64 is default complex type return dpnp.dtype("c8") - raise RuntimeError(f"Unrecognized type of input dtype={dtype}") + raise RuntimeError( + f"Unrecognized type of input dtype={dtype}" + ) cpdef checker_throw_type_error(function_name, given_type): - raise TypeError(f"{ERROR_PREFIX} in function {function_name}() type '{given_type}' is not supported") + raise TypeError( + f"{ERROR_PREFIX} in function {function_name}() " + f"type '{given_type}' is not supported" + ) -cpdef checker_throw_value_error(function_name, param_name, param, expected): +cpdef checker_throw_value_error( + function_name, param_name, param, expected +): # import sys # sys.tracebacklimit = 0 - err_msg = f"{ERROR_PREFIX} in function {function_name}() parameter '{param_name}'" + err_msg = ( + f"{ERROR_PREFIX} in function {function_name}() " + f"parameter '{param_name}'" + ) err_msg += f" expected `{expected}`, but '{param}' provided" raise ValueError(err_msg) -cdef dpnp_descriptor create_output_descriptor(shape_type_c output_shape, - DPNPFuncType c_type, - dpnp_descriptor requested_out, - device=None, - usm_type="device", - sycl_queue=None): +cdef dpnp_descriptor create_output_descriptor( + shape_type_c output_shape, + DPNPFuncType c_type, + dpnp_descriptor requested_out, + device=None, + usm_type="device", + sycl_queue=None, +): cdef dpnp_descriptor result_desc if requested_out is None: - result = None + _result = None if sycl_queue is not None: device = None - result_dtype = dpnp_DPNPFuncType_to_dtype(< size_t > c_type) - result_obj = dpnp_container.empty(output_shape, - dtype=result_dtype, - device=device, - usm_type=usm_type, - sycl_queue=sycl_queue) + result_dtype = dpnp_DPNPFuncType_to_dtype( + < size_t > c_type + ) + result_obj = dpnp_container.empty( + output_shape, + dtype=result_dtype, + device=device, + usm_type=usm_type, + sycl_queue=sycl_queue, + ) result_desc = dpnp_descriptor(result_obj) else: """ Based on 'out' parameter """ if (output_shape != requested_out.shape): - checker_throw_value_error("create_output_descriptor", "out.shape", requested_out.shape, output_shape) + checker_throw_value_error( + "create_output_descriptor", + "out.shape", + requested_out.shape, + output_shape, + ) if isinstance(requested_out, dpnp_descriptor): result_desc = requested_out @@ -354,8 +438,12 @@ cpdef inline tuple _object_to_tuple(object obj): if obj is None: return () - # dpnp.ndarray unconditionally succeeds in PySequence_Check as it implements __getitem__ - if cpython.PySequence_Check(obj) and not dpnp.is_supported_array_type(obj): + # dpnp.ndarray unconditionally succeeds in + # PySequence_Check as it implements __getitem__ + if ( + cpython.PySequence_Check(obj) + and not dpnp.is_supported_array_type(obj) + ): if isinstance(obj, numpy.ndarray): obj = numpy.atleast_1d(obj) @@ -364,7 +452,10 @@ cpdef inline tuple _object_to_tuple(object obj): for i in range(0, nd): if cpython.PyBool_Check(obj[i]): - raise TypeError("DPNP object_to_tuple(): no item in size can be bool") + raise TypeError( + "DPNP object_to_tuple(): " + "no item in size can be bool" + ) # Assumes each item is castable to Py_ssize_t, # otherwise TypeError will be raised @@ -373,20 +464,33 @@ cpdef inline tuple _object_to_tuple(object obj): if dpnp.isscalar(obj): if cpython.PyBool_Check(obj): - raise TypeError("DPNP object_to_tuple(): 'obj' can't be bool") + raise TypeError( + "DPNP object_to_tuple(): " + "'obj' can't be bool" + ) return (obj, ) - raise ValueError("DPNP object_to_tuple(): 'obj' should be 'None', collections.abc.Sequence, or 'int'") + raise ValueError( + "DPNP object_to_tuple(): 'obj' should be " + "'None', collections.abc.Sequence, or 'int'" + ) -cpdef cpp_bool use_origin_backend(input1=None, size_t compute_size=0): +cpdef cpp_bool use_origin_backend( + input1=None, size_t compute_size=0 +): """ - This function needs to redirect particular computation cases to original backend + This function needs to redirect particular + computation cases to original backend. + Parameters: - input1: One of the input parameter of the API function - compute_size: Some amount of total compute size of the task + input1: One of the input parameter of the API + function + compute_size: Some amount of total compute size + of the task Return: - True - computations are better to be executed on original backend + True - computations are better to be executed on + original backend False - it is better to use this SW to compute """ @@ -396,24 +500,47 @@ cpdef cpp_bool use_origin_backend(input1=None, size_t compute_size=0): return False -cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2): - """Get common USM allocation in the form of (sycl_device, usm_type, sycl_queue).""" +cdef tuple get_common_usm_allocation( + dpnp_descriptor x1, dpnp_descriptor x2 +): + """ + Get common USM allocation in the form of + (sycl_device, usm_type, sycl_queue). + """ array1_obj = x1.get_array() array2_obj = x2.get_array() - common_usm_type = get_coerced_usm_type((array1_obj.usm_type, array2_obj.usm_type)) + common_usm_type = get_coerced_usm_type( + (array1_obj.usm_type, array2_obj.usm_type) + ) if common_usm_type is None: raise ValueError( - "could not recognize common USM type for inputs of USM types {} and {}" - "".format(array1_obj.usm_type, array2_obj.usm_type)) - - common_sycl_queue = get_execution_queue((array1_obj.sycl_queue, array2_obj.sycl_queue)) + "could not recognize common USM type " + "for inputs of USM types {} and {}" + "".format( + array1_obj.usm_type, + array2_obj.usm_type, + ) + ) + + common_sycl_queue = get_execution_queue( + (array1_obj.sycl_queue, array2_obj.sycl_queue) + ) if common_sycl_queue is None: raise ValueError( - "could not recognize common SYCL queue for inputs in SYCL queues {} and {}" - "".format(array1_obj.sycl_queue, array2_obj.sycl_queue)) + "could not recognize common SYCL queue " + "for inputs in SYCL queues {} and {}" + "".format( + array1_obj.sycl_queue, + array2_obj.sycl_queue, + ) + ) - return (common_sycl_queue.sycl_device, common_usm_type, common_sycl_queue) + return ( + common_sycl_queue.sycl_device, + common_usm_type, + common_sycl_queue, + ) cdef class dpnp_descriptor: @@ -425,11 +552,15 @@ cdef class dpnp_descriptor: self.dpnp_descriptor_is_scalar = True """ Acquire DPCTL data container storage """ - self.descriptor = getattr(obj, "__sycl_usm_array_interface__", None) + self.descriptor = getattr( + obj, "__sycl_usm_array_interface__", None + ) if self.descriptor is None: """ Acquire main data storage """ - self.descriptor = getattr(obj, "__array_interface__", None) + self.descriptor = getattr( + obj, "__array_interface__", None + ) if self.descriptor is None: return @@ -442,12 +573,18 @@ cdef class dpnp_descriptor: cdef Py_ssize_t shape_it = 0 self.dpnp_descriptor_data_size = 1 for shape_it in self.shape: - # TODO need to use common procedure from utils to calculate array size by shape + # TODO need to use common procedure from + # utils to calculate array size by shape if shape_it < 0: - raise ValueError(f"{ERROR_PREFIX} dpnp_descriptor::__init__() invalid value {shape_it} in 'shape'") + raise ValueError( + f"{ERROR_PREFIX} " + "dpnp_descriptor::__init__() " + f"invalid value {shape_it} " + "in 'shape'" + ) self.dpnp_descriptor_data_size *= shape_it - """ set scalar property """ + # set scalar property self.dpnp_descriptor_is_scalar = False @property @@ -490,7 +627,7 @@ cdef class dpnp_descriptor: @property def offset(self): if self.is_valid: - return self.descriptor.get('offset', 0) + return self.descriptor.get("offset", 0) return 0 @property @@ -512,7 +649,10 @@ cdef class dpnp_descriptor: @property def __array_interface__(self): - # print(f"====dpnp_descriptor::__array_interface__====self.descriptor={ < size_t > self.descriptor}") + # print("====dpnp_descriptor::" + # "__array_interface__====" + # f"self.descriptor=" + # f"{self.descriptor}") if self.descriptor is None: return None @@ -532,14 +672,18 @@ cdef class dpnp_descriptor: return self.origin_pyobj def get_array(self): - if isinstance(self.origin_pyobj, dpnp.tensor.usm_ndarray): + if isinstance( + self.origin_pyobj, dpnp.tensor.usm_ndarray + ): return self.origin_pyobj if isinstance(self.origin_pyobj, dpnp_array): return self.origin_pyobj.get_array() raise TypeError( - "expected either dpnp.tensor.usm_ndarray or dpnp.dpnp_array.dpnp_array, got {}" - "".format(type(self.origin_pyobj))) + "expected either dpnp.tensor.usm_ndarray " + "or dpnp.dpnp_array.dpnp_array, got {}" + "".format(type(self.origin_pyobj)) + ) cdef void * get_data(self): cdef Py_ssize_t item_size = 0 diff --git a/dpnp/random/dpnp_algo_random.pyx b/dpnp/random/dpnp_algo_random.pyx index 018e9b72eea..70aa49ea63c 100644 --- a/dpnp/random/dpnp_algo_random.pyx +++ b/dpnp/random/dpnp_algo_random.pyx @@ -39,11 +39,9 @@ and the rest of the library import numbers -import dpctl import numpy import dpnp -import dpnp.config as config from dpnp.dpnp_array import dpnp_array cimport dpctl as c_dpctl @@ -91,187 +89,290 @@ __all__ = [ ] -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_beta_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_binomial_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const int, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_chisquare_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const int, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_exponential_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_f_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_gamma_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_geometric_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const float, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_gumbel_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_hypergeometric_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const int, - const int, - const int, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_laplace_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_logistic_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_lognormal_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_multinomial_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * result, - const int, - void * , - const size_t, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef void(*fptr_dpnp_rng_multivariate_normal_c_1out_t)(void * , - const int, - void * , - const size_t, - void * , - const size_t, - const size_t) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_negative_binomial_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_noncentral_chisquare_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_normal_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const int64_t, - void * , - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_pareto_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_poisson_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_power_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_rayleigh_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_shuffle_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, void * , - const size_t, - const size_t, - const size_t, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef void(*fptr_dpnp_rng_srand_c_1out_t)(const size_t) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_standard_cauchy_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_standard_exponential_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_standard_gamma_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_standard_t_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_triangular_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, void * , - const double, - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_uniform_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const int64_t, - void * , - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_vonmises_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_wald_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void *, - const double, - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_weibull_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_rng_zipf_c_1out_t)(c_dpctl.DPCTLSyclQueueRef, - void * , - const double, - const size_t, - const c_dpctl.DPCTLEventVectorRef) except + - +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_beta_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_binomial_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const int, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_chisquare_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const int, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_exponential_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_f_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_gamma_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_geometric_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const float, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_gumbel_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_hypergeometric_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const int, + const int, + const int, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_laplace_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_logistic_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_lognormal_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_multinomial_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void * result, + const int, + void *, + const size_t, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef void( + *fptr_dpnp_rng_multivariate_normal_c_1out_t)( + void *, + const int, + void *, + const size_t, + void *, + const size_t, + const size_t, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_negative_binomial_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_noncentral_chisquare_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_normal_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const int64_t, + void *, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_pareto_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_poisson_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_power_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_rayleigh_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_shuffle_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const size_t, + const size_t, + const size_t, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef void( + *fptr_dpnp_rng_srand_c_1out_t)( + const size_t, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_standard_cauchy_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_standard_exponential_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_standard_gamma_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_standard_t_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_triangular_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_uniform_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const int64_t, + void *, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_vonmises_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_wald_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_weibull_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + +ctypedef c_dpctl.DPCTLSyclEventRef( + *fptr_dpnp_rng_zipf_c_1out_t)( + c_dpctl.DPCTLSyclQueueRef, + void *, + const double, + const size_t, + const c_dpctl.DPCTLEventVectorRef, +) except + cdef extern from "dpnp_random_state.hpp": @@ -280,13 +381,19 @@ cdef extern from "dpnp_random_state.hpp": cdef struct mt19937_struct: pass - void MT19937_InitScalarSeed(mt19937_struct *, c_dpctl.DPCTLSyclQueueRef, uint32_t) - void MT19937_InitVectorSeed(mt19937_struct *, c_dpctl.DPCTLSyclQueueRef, uint32_t *, unsigned int) + void MT19937_InitScalarSeed( + mt19937_struct *, c_dpctl.DPCTLSyclQueueRef, + uint32_t) + void MT19937_InitVectorSeed( + mt19937_struct *, c_dpctl.DPCTLSyclQueueRef, + uint32_t *, unsigned int) void MT19937_Delete(mt19937_struct *) cdef struct mcg59_struct: pass - void MCG59_InitScalarSeed(mcg59_struct *, c_dpctl.DPCTLSyclQueueRef, uint64_t) + void MCG59_InitScalarSeed( + mcg59_struct *, c_dpctl.DPCTLSyclQueueRef, + uint64_t) void MCG59_Delete(mcg59_struct *) @@ -303,7 +410,9 @@ cdef class _Engine: # keep a reference on SYCL queue self.q = sycl_queue - self.q_ref = c_dpctl.DPCTLQueue_Copy((self.q).get_queue_ref()) + self.q_ref = c_dpctl.DPCTLQueue_Copy( + (self.q).get_queue_ref() + ) if self.q_ref is NULL: raise ValueError("SyclQueue copy failed") @@ -313,9 +422,16 @@ cdef class _Engine: cdef bint is_integer(self, value): if isinstance(value, numbers.Number): - return isinstance(value, int) or isinstance(value, dpnp.integer) + return ( + isinstance(value, int) + or isinstance(value, dpnp.integer) + ) # cover an element of dpnp array: - return numpy.ndim(value) == 0 and hasattr(value, "dtype") and dpnp.issubdtype(value, dpnp.integer) + return ( + numpy.ndim(value) == 0 + and hasattr(value, "dtype") + and dpnp.issubdtype(value, dpnp.integer) + ) cdef void set_engine(self, engine_struct* engine): self.engine_base = engine @@ -329,7 +445,9 @@ cdef class _Engine: cdef c_dpctl.DPCTLSyclQueueRef get_queue_ref(self): return self.q_ref - cpdef utils.dpnp_descriptor normal(self, loc, scale, size, dtype, usm_type): + cpdef utils.dpnp_descriptor normal( + self, loc, scale, size, dtype, usm_type + ): cdef shape_type_c result_shape cdef utils.dpnp_descriptor result cdef DPNPFuncType param1_type @@ -339,32 +457,50 @@ cdef class _Engine: result_shape = utils._object_to_tuple(size) if scale == 0.0: - return utils.dpnp_descriptor(dpnp.full(result_shape, loc, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, loc, dtype=dtype) + ) - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_NORMAL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_NORMAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=None, - usm_type=usm_type, - sycl_queue=self.get_queue()) - - func = kernel_data.ptr + result = utils.create_output_descriptor( + result_shape, + kernel_data.return_type, + None, + device=None, + usm_type=usm_type, + sycl_queue=self.get_queue(), + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - event_ref = func(self.get_queue_ref(), result.get_data(), loc, scale, result.size, self.get_engine(), NULL) + event_ref = func( + self.get_queue_ref(), result.get_data(), + loc, scale, result.size, + self.get_engine(), NULL, + ) if event_ref != NULL: - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result - cpdef utils.dpnp_descriptor uniform(self, low, high, size, dtype, usm_type): + cpdef utils.dpnp_descriptor uniform( + self, low, high, size, dtype, usm_type + ): cdef shape_type_c result_shape cdef utils.dpnp_descriptor result cdef DPNPFuncType param1_type @@ -374,35 +510,52 @@ cdef class _Engine: result_shape = utils._object_to_tuple(size) if low == high: - return utils.dpnp_descriptor(dpnp.full(result_shape, low, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, low, dtype=dtype) + ) - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_UNIFORM_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_UNIFORM_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=None, - usm_type=usm_type, - sycl_queue=self.get_queue()) - - func = kernel_data.ptr + result = utils.create_output_descriptor( + result_shape, + kernel_data.return_type, + None, + device=None, + usm_type=usm_type, + sycl_queue=self.get_queue(), + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - event_ref = func(self.get_queue_ref(), result.get_data(), low, high, result.size, self.get_engine(), NULL) + event_ref = func( + self.get_queue_ref(), result.get_data(), + low, high, result.size, + self.get_engine(), NULL, + ) if event_ref != NULL: - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result cdef class MT19937(_Engine): """ - Class storing MKL engine for MT199374x32x10 (The Mersenne Twister pseudorandom number generator). + Class storing MKL engine for MT199374x32x10 + (The Mersenne Twister pseudorandom number generator). """ @@ -419,44 +572,82 @@ cdef class MT19937(_Engine): if self.is_uint_range(seed): scalar_seed = seed else: - raise ValueError("Seed must be between 0 and 2**32 - 1") - elif isinstance(seed, (list, tuple, range, numpy.ndarray, dpnp_array)): + raise ValueError( + "Seed must be between 0 and 2**32 - 1" + ) + elif isinstance( + seed, + (list, tuple, range, numpy.ndarray, dpnp_array), + ): if len(seed) == 0: raise ValueError("Seed must be non-empty") elif numpy.ndim(seed) > 1: - raise ValueError("Seed array must be 1-d") - elif not all([self.is_integer(item) for item in seed]): - raise TypeError("Seed must be a sequence of unsigned int elements") - elif not all([self.is_uint_range(item) for item in seed]): - raise ValueError("Seed must be between 0 and 2**32 - 1") + raise ValueError( + "Seed array must be 1-d" + ) + elif not all( + [self.is_integer(item) for item in seed] + ): + raise TypeError( + "Seed must be a sequence of " + "unsigned int elements" + ) + elif not all( + [self.is_uint_range(item) + for item in seed] + ): + raise ValueError( + "Seed must be between 0 and 2**32 - 1" + ) else: is_vector_seed = True vector_seed_len = len(seed) if vector_seed_len > 3: raise ValueError( - f"{vector_seed_len} length of seed vector isn't supported, " - "the length is limited by 3") - - vector_seed = malloc(vector_seed_len * sizeof(uint32_t)) + f"{vector_seed_len} length of " + "seed vector isn't supported, " + "the length is limited by 3" + ) + + vector_seed = malloc( + vector_seed_len * sizeof(uint32_t) + ) if (not vector_seed): - raise MemoryError(f"Could not allocate memory for seed vector of length {vector_seed_len}") - - # convert input seed's type to uint32_t one (expected in MKL function) + raise MemoryError( + "Could not allocate memory for " + "seed vector of length " + f"{vector_seed_len}" + ) + + # convert input seed's type to uint32_t + # one (expected in MKL function) try: for i in range(vector_seed_len): - vector_seed[i] = seed[i] + vector_seed[i] = ( + seed[i] + ) except Exception as e: free(vector_seed) raise e else: - raise TypeError("Seed must be an unsigned int, or a sequence of unsigned int elements") + raise TypeError( + "Seed must be an unsigned int, or a " + "sequence of unsigned int elements" + ) if is_vector_seed: - MT19937_InitVectorSeed(&self.mt19937, self.q_ref, vector_seed, vector_seed_len) + MT19937_InitVectorSeed( + &self.mt19937, self.q_ref, + vector_seed, vector_seed_len, + ) free(vector_seed) else: - MT19937_InitScalarSeed(&self.mt19937, self.q_ref, scalar_seed) - self.set_engine( &self.mt19937) + MT19937_InitScalarSeed( + &self.mt19937, self.q_ref, scalar_seed, + ) + self.set_engine( + &self.mt19937 + ) def __dealloc__(self): MT19937_Delete(&self.mt19937) @@ -467,14 +658,17 @@ cdef class MT19937(_Engine): max_val = dpnp.iinfo(numpy.uint32).max if isinstance(value, dpnp_array): - max_val = dpnp.array(max_val, dtype=numpy.uint32) + max_val = dpnp.array( + max_val, dtype=numpy.uint32 + ) return value <= max_val cdef class MCG59(_Engine): """ Class storing MKL engine for MCG59 - (the 59-bit multiplicative congruential pseudorandom number generator). + (the 59-bit multiplicative congruential + pseudorandom number generator). """ @@ -488,12 +682,18 @@ cdef class MCG59(_Engine): if self.is_uint64_range(seed): scalar_seed = seed else: - raise ValueError("Seed must be between 0 and 2**64 - 1") + raise ValueError( + "Seed must be between 0 and 2**64 - 1" + ) else: raise TypeError("Seed must be an integer") - MCG59_InitScalarSeed(&self.mcg59, self.q_ref, scalar_seed) - self.set_engine( &self.mcg59) + MCG59_InitScalarSeed( + &self.mcg59, self.q_ref, scalar_seed, + ) + self.set_engine( + &self.mcg59 + ) def __dealloc__(self): MCG59_Delete(&self.mcg59) @@ -504,49 +704,79 @@ cdef class MCG59(_Engine): max_val = dpnp.iinfo(numpy.uint64).max if isinstance(value, dpnp_array): - max_val = dpnp.array(max_val, dtype=numpy.uint64) + max_val = dpnp.array( + max_val, dtype=numpy.uint64 + ) return value <= max_val -cpdef utils.dpnp_descriptor dpnp_rng_beta(double a, double b, size): +cpdef utils.dpnp_descriptor dpnp_rng_beta( + double a, double b, size +): """ - Returns an array populated with samples from beta distribution. - `dpnp_rng_beta` generates a matrix filled with random floats sampled from a - univariate beta distribution. + Returns an array populated with samples from beta + distribution. + `dpnp_rng_beta` generates a matrix filled with random + floats sampled from a univariate beta distribution. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_BETA_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_BETA_EXT, param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_beta_c_1out_t func = kernel_data.ptr + cdef fptr_dpnp_rng_beta_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), a, b, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), a, b, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_binomial(int ntrial, double p, size): +cpdef utils.dpnp_descriptor dpnp_rng_binomial( + int ntrial, double p, size +): """ - Returns an array populated with samples from binomial distribution. - `dpnp_rng_binomial` generates a matrix filled with random floats sampled from a - univariate binomial distribution for a given number of independent trials and - success probability p of a single trial. + Returns an array populated with samples from binomial + distribution. + `dpnp_rng_binomial` generates a matrix filled with + random floats sampled from a univariate binomial + distribution for a given number of independent trials + and success probability p of a single trial. """ @@ -555,137 +785,237 @@ cpdef utils.dpnp_descriptor dpnp_rng_binomial(int ntrial, double p, size): cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_binomial_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_BINOMIAL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_BINOMIAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), ntrial, p, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), ntrial, p, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_chisquare(int df, size): +cpdef utils.dpnp_descriptor dpnp_rng_chisquare( + int df, size +): """ - Returns an array populated with samples from chi-square distribution. - `dpnp_rng_chisquare` generates a matrix filled with random floats sampled from a - univariate chi-square distribution for a given number of degrees of freedom. + Returns an array populated with samples from + chi-square distribution. + `dpnp_rng_chisquare` generates a matrix filled with + random floats sampled from a univariate chi-square + distribution for a given number of degrees of freedom. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.default_float_type()) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.default_float_type()) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_CHISQUARE_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_CHISQUARE_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - - cdef fptr_dpnp_rng_chisquare_c_1out_t func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_chisquare_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), df, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), df, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_exponential(double beta, size): +cpdef utils.dpnp_descriptor dpnp_rng_exponential( + double beta, size +): """ - Returns an array populated with samples from exponential distribution. - `dpnp_rng_exponential` generates a matrix filled with random floats sampled from a - univariate exponential distribution of `beta`. + Returns an array populated with samples from + exponential distribution. + `dpnp_rng_exponential` generates a matrix filled with + random floats sampled from a univariate exponential + distribution of `beta`. """ dtype = dpnp.float64 - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dtype) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_EXPONENTIAL_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_EXPONENTIAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_exponential_c_1out_t func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_exponential_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), beta, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), beta, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_f(double df_num, double df_den, size): +cpdef utils.dpnp_descriptor dpnp_rng_f( + double df_num, double df_den, size +): """ - Returns an array populated with samples from F distribution. - `dpnp_rng_f` generates a matrix filled with random floats sampled from a - univariate F distribution. + Returns an array populated with samples from + F distribution. + `dpnp_rng_f` generates a matrix filled with random + floats sampled from a univariate F distribution. """ dtype = dpnp.float64 - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dtype) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_F_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_F_EXT, param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_f_c_1out_t func = kernel_data.ptr + cdef fptr_dpnp_rng_f_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), df_num, df_den, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), df_num, df_den, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_gamma(double shape, double scale, size): +cpdef utils.dpnp_descriptor dpnp_rng_gamma( + double shape, double scale, size +): """ - Returns an array populated with samples from gamma distribution. - `dpnp_rng_gamma` generates a matrix filled with random floats sampled from a - univariate gamma distribution of `shape` and `scale`. + Returns an array populated with samples from gamma + distribution. + `dpnp_rng_gamma` generates a matrix filled with random + floats sampled from a univariate gamma distribution of + `shape` and `scale`. """ @@ -696,32 +1026,54 @@ cpdef utils.dpnp_descriptor dpnp_rng_gamma(double shape, double scale, size): param1_type = dpnp_dtype_to_DPNPFuncType(dtype) - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_GAMMA_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_GAMMA_EXT, param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - func = kernel_data.ptr + func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), shape, scale, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), shape, scale, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_geometric(float p, size): +cpdef utils.dpnp_descriptor dpnp_rng_geometric( + float p, size +): """ - Returns an array populated with samples from geometric distribution. - `dpnp_rng_geometric` generates a matrix filled with random floats sampled from a - univariate geometric distribution for a success probability p of a single + Returns an array populated with samples from geometric + distribution. + `dpnp_rng_geometric` generates a matrix filled with + random floats sampled from a univariate geometric + distribution for a success probability p of a single trial. """ @@ -731,36 +1083,60 @@ cpdef utils.dpnp_descriptor dpnp_rng_geometric(float p, size): cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_geometric_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_GEOMETRIC_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_GEOMETRIC_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), p, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), p, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_gumbel(double loc, double scale, size): +cpdef utils.dpnp_descriptor dpnp_rng_gumbel( + double loc, double scale, size +): """ - Returns an array populated with samples from gumbel distribution. - `dpnp_rng_gumbel` generates a matrix filled with random floats sampled from a - univariate Gumbel distribution. + Returns an array populated with samples from gumbel + distribution. + `dpnp_rng_gumbel` generates a matrix filled with + random floats sampled from a univariate Gumbel + distribution. """ @@ -770,32 +1146,54 @@ cpdef utils.dpnp_descriptor dpnp_rng_gumbel(double loc, double scale, size): cdef fptr_dpnp_rng_gumbel_c_1out_t func param1_type = dpnp_dtype_to_DPNPFuncType(dtype) - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_GUMBEL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_GUMBEL_EXT, param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - func = kernel_data.ptr + func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), loc, scale, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), loc, scale, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_hypergeometric(int l, int s, int m, size): +cpdef utils.dpnp_descriptor dpnp_rng_hypergeometric( + int l, int s, int m, size +): """ - Returns an array populated with samples from hypergeometric distribution. - `dpnp_rng_hypergeometric` generates a matrix filled with random floats sampled from a - univariate hypergeometric distribution. + Returns an array populated with samples from + hypergeometric distribution. + `dpnp_rng_hypergeometric` generates a matrix filled + with random floats sampled from a univariate + hypergeometric distribution. """ @@ -804,36 +1202,61 @@ cpdef utils.dpnp_descriptor dpnp_rng_hypergeometric(int l, int s, int m, size): cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_hypergeometric_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_HYPERGEOMETRIC_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_HYPERGEOMETRIC_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), l, s, m, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), l, s, m, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_laplace(double loc, double scale, size): +cpdef utils.dpnp_descriptor dpnp_rng_laplace( + double loc, double scale, size +): """ - Returns an array populated with samples from laplace distribution. - `dpnp_rng_laplace` generates a matrix filled with random floats sampled from a - univariate laplace distribution. + Returns an array populated with samples from laplace + distribution. + `dpnp_rng_laplace` generates a matrix filled with + random floats sampled from a univariate laplace + distribution. """ @@ -842,69 +1265,121 @@ cpdef utils.dpnp_descriptor dpnp_rng_laplace(double loc, double scale, size): cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_laplace_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_LAPLACE_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_LAPLACE_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), loc, scale, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), loc, scale, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_logistic(double loc, double scale, size): +cpdef utils.dpnp_descriptor dpnp_rng_logistic( + double loc, double scale, size +): """ - Returns an array populated with samples from logistic distribution. - `dpnp_rng_logistic` generates a matrix filled with random floats sampled from a - univariate logistic distribution. + Returns an array populated with samples from logistic + distribution. + `dpnp_rng_logistic` generates a matrix filled with + random floats sampled from a univariate logistic + distribution. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_LOGISTIC_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_LOGISTIC_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_logistic_c_1out_t func = < fptr_dpnp_rng_logistic_c_1out_t > kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_logistic_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), loc, scale, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), loc, scale, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_lognormal(double mean, double stddev, size): +cpdef utils.dpnp_descriptor dpnp_rng_lognormal( + double mean, double stddev, size +): """ - Returns an array populated with samples from lognormal distribution. - `dpnp_rng_lognormal` generates a matrix filled with random floats sampled from a - univariate lognormal distribution. + Returns an array populated with samples from lognormal + distribution. + `dpnp_rng_lognormal` generates a matrix filled with + random floats sampled from a univariate lognormal + distribution. """ @@ -913,38 +1388,64 @@ cpdef utils.dpnp_descriptor dpnp_rng_lognormal(double mean, double stddev, size) cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_lognormal_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_LOGNORMAL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_LOGNORMAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), mean, stddev, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), mean, stddev, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_multinomial(int ntrial, utils.dpnp_descriptor p, size): +cpdef utils.dpnp_descriptor dpnp_rng_multinomial( + int ntrial, utils.dpnp_descriptor p, size +): """ - Returns an array populated with samples from multinomial distribution. + Returns an array populated with samples from + multinomial distribution. - `dpnp_rng_multinomial` generates a matrix filled with random floats sampled from a - univariate multinomial distribution for a given number of independent trials and - probabilities of each of the ``p`` different outcome. + `dpnp_rng_multinomial` generates a matrix filled with + random floats sampled from a univariate multinomial + distribution for a given number of independent trials + and probabilities of each of the ``p`` different + outcome. """ @@ -955,49 +1456,74 @@ cpdef utils.dpnp_descriptor dpnp_rng_multinomial(int ntrial, utils.dpnp_descript cdef size_t p_size = p.size - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_MULTINOMIAL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_MULTINOMIAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) p_obj = p.get_array() - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=p_obj.device, - usm_type=p_obj.usm_type, - sycl_queue=p_obj.sycl_queue) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, + kernel_data.return_type, + None, + device=p_obj.device, + usm_type=p_obj.usm_type, + sycl_queue=p_obj.sycl_queue, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), ntrial, p.get_data(), p_size, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), ntrial, p.get_data(), + p_size, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_multivariate_normal(utils.dpnp_descriptor mean, utils.dpnp_descriptor cov, size): +cpdef utils.dpnp_descriptor dpnp_rng_multivariate_normal( + utils.dpnp_descriptor mean, + utils.dpnp_descriptor cov, size +): """ - Returns an array populated with samples from multivariate normal distribution. - `dpnp_rng_multivariate_normal` generates a matrix filled with random floats sampled from a + Returns an array populated with samples from multivariate normal distribution. + `dpnp_rng_multivariate_normal` generates a matrix + filled with random floats sampled from a multivariate + normal distribution. """ dtype = dpnp.float64 - cdef int dimen cdef size_t mean_size cdef size_t cov_size @@ -1008,38 +1534,59 @@ cpdef utils.dpnp_descriptor dpnp_rng_multivariate_normal(utils.dpnp_descriptor m mean_size = mean.size cov_size = cov.size - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_MULTIVARIATE_NORMAL, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_MULTIVARIATE_NORMAL, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - result_sycl_device, result_usm_type, result_sycl_queue = utils.get_common_usm_allocation(mean, cov) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=result_sycl_device, - usm_type=result_usm_type, - sycl_queue=result_sycl_queue) - - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + result_sycl_device, result_usm_type, result_sycl_queue = ( + utils.get_common_usm_allocation(mean, cov) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, + kernel_data.return_type, + None, + device=result_sycl_device, + usm_type=result_usm_type, + sycl_queue=result_sycl_queue, + ) + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - func(result.get_data(), mean_size, mean.get_data(), mean_size, cov.get_data(), cov_size, result.size) + func( + result.get_data(), mean_size, mean.get_data(), + mean_size, cov.get_data(), cov_size, result.size, + ) return result -cpdef utils.dpnp_descriptor dpnp_rng_negative_binomial(double a, double p, size): + +cpdef utils.dpnp_descriptor dpnp_rng_negative_binomial( + double a, double p, size +): """ - Returns an array populated with samples from negative binomial distribution. + Returns an array populated with samples from negative + binomial distribution. - `negative_binomial` generates a matrix filled with random floats sampled from a - univariate negative binomial distribution for a given parameter of the distribution - `a` and success probability `p` of a single trial. + `negative_binomial` generates a matrix filled with + random floats sampled from a univariate negative + binomial distribution for a given parameter of the + distribution `a` and success probability `p` of a + single trial. """ @@ -1056,107 +1603,183 @@ cpdef utils.dpnp_descriptor dpnp_rng_negative_binomial(double a, double p, size) result_shape = utils._object_to_tuple(size) if p == 0.0: filled_val = dpnp.iinfo(dtype).min - return utils.dpnp_descriptor(dpnp.full(result_shape, filled_val, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, filled_val, + dtype=dtype) + ) elif p == 1.0: - return utils.dpnp_descriptor(dpnp.full(result_shape, 0, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, 0, dtype=dtype) + ) else: - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_NEGATIVE_BINOMIAL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_NEGATIVE_BINOMIAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + result = utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) result_sycl_queue = result.get_array().sycl_queue q = result_sycl_queue q_ref = q.get_queue_ref() - func = kernel_data.ptr + func = ( + + kernel_data.ptr + ) # call FPTR function - event_ref = func(q_ref, result.get_data(), a, p, result.size, NULL) + event_ref = func( + q_ref, result.get_data(), a, p, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_noncentral_chisquare(double df, double nonc, size): +cpdef utils.dpnp_descriptor dpnp_rng_noncentral_chisquare( + double df, double nonc, size +): """ - Returns an array populated with samples from noncentral chisquare distribution. - `dpnp_rng_noncentral_chisquare` generates a matrix filled with random floats sampled from a - univariate noncentral chisquare distribution. + Returns an array populated with samples from + noncentral chisquare distribution. + `dpnp_rng_noncentral_chisquare` generates a matrix + filled with random floats sampled from a univariate + noncentral chisquare distribution. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_NONCENTRAL_CHISQUARE_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_NONCENTRAL_CHISQUARE_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_noncentral_chisquare_c_1out_t func = < fptr_dpnp_rng_noncentral_chisquare_c_1out_t > kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_noncentral_chisquare_c_1out_t func + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), df, nonc, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), df, nonc, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_pareto(double alpha, size): +cpdef utils.dpnp_descriptor dpnp_rng_pareto( + double alpha, size +): """ - Returns an array populated with samples from Pareto distribution. - `dpnp_rng_pareto` generates a matrix filled with random floats sampled from a - univariate Pareto distribution of `alpha`. + Returns an array populated with samples from Pareto + distribution. + `dpnp_rng_pareto` generates a matrix filled with + random floats sampled from a univariate Pareto + distribution of `alpha`. """ dtype = dpnp.float64 - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dtype) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_PARETO_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_PARETO_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_pareto_c_1out_t func = kernel_data.ptr + cdef fptr_dpnp_rng_pareto_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), alpha, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), alpha, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_poisson(double lam, size): +cpdef utils.dpnp_descriptor dpnp_rng_poisson( + double lam, size +): """ - Returns an array populated with samples from Poisson distribution. - `dpnp_rng_poisson` generates a matrix filled with random floats sampled from a - univariate Poisson distribution for a given number of independent trials and - success probability p of a single trial. + Returns an array populated with samples from Poisson + distribution. + `dpnp_rng_poisson` generates a matrix filled with + random floats sampled from a univariate Poisson + distribution for a given number of independent trials + and success probability p of a single trial. """ @@ -1172,70 +1795,115 @@ cpdef utils.dpnp_descriptor dpnp_rng_poisson(double lam, size): result_shape = utils._object_to_tuple(size) if lam == 0: - return utils.dpnp_descriptor(dpnp.full(result_shape, 0, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, 0, dtype=dtype) + ) else: - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_POISSON_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_POISSON_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + result = utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) result_sycl_queue = result.get_array().sycl_queue q = result_sycl_queue q_ref = q.get_queue_ref() - func = kernel_data.ptr + func = ( + + kernel_data.ptr + ) # call FPTR function - event_ref = func(q_ref, result.get_data(), lam, result.size, NULL) + event_ref = func( + q_ref, result.get_data(), lam, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_power(double alpha, size): +cpdef utils.dpnp_descriptor dpnp_rng_power( + double alpha, size +): """ - Returns an array populated with samples from power distribution. - `dpnp_rng_power` generates a matrix filled with random floats sampled from a - univariate power distribution of `alpha`. + Returns an array populated with samples from power + distribution. + `dpnp_rng_power` generates a matrix filled with random + floats sampled from a univariate power distribution of + `alpha`. """ dtype = dpnp.float64 - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dtype) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_POWER_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_POWER_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_power_c_1out_t func = kernel_data.ptr + cdef fptr_dpnp_rng_power_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), alpha, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), alpha, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_rayleigh(double scale, size): +cpdef utils.dpnp_descriptor dpnp_rng_rayleigh( + double scale, size +): """ - Returns an array populated with samples from Rayleigh distribution. - `dpnp_rayleigh` generates a matrix filled with random floats sampled from a - univariate Rayleigh distribution of `scale`. + Returns an array populated with samples from Rayleigh + distribution. + `dpnp_rayleigh` generates a matrix filled with random + floats sampled from a univariate Rayleigh distribution + of `scale`. """ @@ -1251,57 +1919,90 @@ cpdef utils.dpnp_descriptor dpnp_rng_rayleigh(double scale, size): result_shape = utils._object_to_tuple(size) if scale == 0.0: - return utils.dpnp_descriptor(dpnp.full(result_shape, 0.0, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, 0.0, dtype=dtype) + ) else: - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_RAYLEIGH_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_RAYLEIGH_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + result = utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) result_sycl_queue = result.get_array().sycl_queue q = result_sycl_queue q_ref = q.get_queue_ref() - func = kernel_data.ptr + func = ( + + kernel_data.ptr + ) # call FPTR function - event_ref = func(q_ref, result.get_data(), scale, result.size, NULL) + event_ref = func( + q_ref, result.get_data(), scale, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_shuffle(utils.dpnp_descriptor x1): +cpdef utils.dpnp_descriptor dpnp_rng_shuffle( + utils.dpnp_descriptor x1 +): """ Modify a sequence in-place by shuffling its contents. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype.type) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(x1.dtype.type) + ) cdef size_t itemsize = x1.dtype.itemsize cdef size_t ndim = x1.ndim cdef size_t high_dim_size = x1.get_pyobj().size # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_SHUFFLE_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_SHUFFLE_EXT, + param1_type, param1_type, + ) x1_sycl_queue = x1.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = x1_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + x1_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_shuffle_c_1out_t func = < fptr_dpnp_rng_shuffle_c_1out_t > kernel_data.ptr + cdef fptr_dpnp_rng_shuffle_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), itemsize, ndim, high_dim_size, x1.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, x1.get_data(), itemsize, ndim, + high_dim_size, x1.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return x1 @@ -1313,90 +2014,153 @@ cpdef dpnp_rng_srand(seed): """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_SRAND, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_SRAND, param1_type, param1_type, + ) - cdef fptr_dpnp_rng_srand_c_1out_t func = < fptr_dpnp_rng_srand_c_1out_t > kernel_data.ptr + cdef fptr_dpnp_rng_srand_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function func(seed) -cpdef utils.dpnp_descriptor dpnp_rng_standard_cauchy(size): +cpdef utils.dpnp_descriptor dpnp_rng_standard_cauchy( + size, +): """ - Returns an array populated with samples from standard cauchy distribution. - `dpnp_standard_cauchy` generates a matrix filled with random floats sampled from a - univariate standard cauchy distribution. + Returns an array populated with samples from standard + cauchy distribution. + `dpnp_standard_cauchy` generates a matrix filled with + random floats sampled from a univariate standard cauchy + distribution. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.default_float_type()) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.default_float_type()) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_CAUCHY_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_STANDARD_CAUCHY_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_standard_cauchy_c_1out_t func = < fptr_dpnp_rng_standard_cauchy_c_1out_t > kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_standard_cauchy_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_standard_exponential(size): +cpdef utils.dpnp_descriptor dpnp_rng_standard_exponential( + size, +): """ - Returns an array populated with samples from standard exponential distribution. - `dpnp_standard_exponential` generates a matrix filled with random floats sampled from a - standard exponential distribution. + Returns an array populated with samples from standard + exponential distribution. + `dpnp_standard_exponential` generates a matrix filled + with random floats sampled from a standard exponential + distribution. """ cdef fptr_dpnp_rng_standard_exponential_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.default_float_type()) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.default_float_type()) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_EXPONENTIAL_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_STANDARD_EXPONENTIAL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = < fptr_dpnp_rng_standard_exponential_c_1out_t > kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_standard_gamma(double shape, size): +cpdef utils.dpnp_descriptor dpnp_rng_standard_gamma( + double shape, size +): """ - Returns an array populated with samples from standard gamma distribution. - `dpnp_standard_gamma` generates a matrix filled with random floats sampled from a - univariate standard gamma distribution. + Returns an array populated with samples from standard + gamma distribution. + `dpnp_standard_gamma` generates a matrix filled with + random floats sampled from a univariate standard gamma + distribution. """ @@ -1412,232 +2176,396 @@ cpdef utils.dpnp_descriptor dpnp_rng_standard_gamma(double shape, size): result_shape = utils._object_to_tuple(size) if shape == 0.0: - return utils.dpnp_descriptor(dpnp.full(result_shape, 0.0, dtype=dtype)) + return utils.dpnp_descriptor( + dpnp.full(result_shape, 0.0, dtype=dtype) + ) else: - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_GAMMA_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_STANDARD_GAMMA_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + result = utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) result_sycl_queue = result.get_array().sycl_queue q = result_sycl_queue q_ref = q.get_queue_ref() - func = kernel_data.ptr + func = ( + + kernel_data.ptr + ) # call FPTR function - event_ref = func(q_ref, result.get_data(), shape, result.size, NULL) + event_ref = func( + q_ref, result.get_data(), shape, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_standard_t(double df, size): +cpdef utils.dpnp_descriptor dpnp_rng_standard_t( + double df, size +): """ - Returns an array populated with samples from standard t distribution. - `dpnp_standard_t` generates a matrix filled with random floats sampled from a - univariate standard t distribution for a given number of degrees of freedom. + Returns an array populated with samples from standard + t distribution. + `dpnp_standard_t` generates a matrix filled with + random floats sampled from a univariate standard t + distribution for a given number of degrees of freedom. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_T_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_STANDARD_T_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_standard_t_c_1out_t func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_standard_t_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), df, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), df, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_triangular(double left, double mode, double right, size): +cpdef utils.dpnp_descriptor dpnp_rng_triangular( + double left, double mode, double right, size +): """ - Returns an array populated with samples from triangular distribution. - `dpnp_rng_triangular` generates a matrix filled with random floats sampled from a - univariate triangular distribution. + Returns an array populated with samples from + triangular distribution. + `dpnp_rng_triangular` generates a matrix filled with + random floats sampled from a univariate triangular + distribution. """ dtype = dpnp.float64 - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dtype) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_TRIANGULAR_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_TRIANGULAR_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_triangular_c_1out_t func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_triangular_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), left, mode, right, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), left, mode, right, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_vonmises(double mu, double kappa, size): +cpdef utils.dpnp_descriptor dpnp_rng_vonmises( + double mu, double kappa, size +): """ - Returns an array populated with samples from Vonmises distribution. - `dpnp_rng_vonmises` generates a matrix filled with random floats sampled from a - univariate Vonmises distribution. + Returns an array populated with samples from Vonmises + distribution. + `dpnp_rng_vonmises` generates a matrix filled with + random floats sampled from a univariate Vonmises + distribution. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_VONMISES_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_VONMISES_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_rng_vonmises_c_1out_t func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + cdef fptr_dpnp_rng_vonmises_c_1out_t func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), mu, kappa, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), mu, kappa, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_wald(double mean, double scale, size): +cpdef utils.dpnp_descriptor dpnp_rng_wald( + double mean, double scale, size +): """ - Returns an array populated with samples from Wald's distribution. - `dpnp_rng_wald` generates a matrix filled with random floats sampled from a - univariate Wald's distribution. + Returns an array populated with samples from Wald's + distribution. + `dpnp_rng_wald` generates a matrix filled with random + floats sampled from a univariate Wald's distribution. """ dtype = dpnp.float64 - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dtype) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_WALD_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_WALD_EXT, param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_wald_c_1out_t func = kernel_data.ptr + cdef fptr_dpnp_rng_wald_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), mean, scale, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), mean, scale, + result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_weibull(double a, size): +cpdef utils.dpnp_descriptor dpnp_rng_weibull( + double a, size +): """ - Returns an array populated with samples from weibull distribution. - `dpnp_weibull` generates a matrix filled with random floats sampled from a - univariate weibull distribution. + Returns an array populated with samples from weibull + distribution. + `dpnp_weibull` generates a matrix filled with random + floats sampled from a univariate weibull distribution. """ - dtype = dpnp.float64 cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_weibull_c_1out_t func - # convert string type names (array.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to + # C enum DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) # get the FPTR data structure - kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_WEIBULL_EXT, param1_type, param1_type) + kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_WEIBULL_EXT, + param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - func = kernel_data.ptr + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) + + func = ( + + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), a, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), a, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result -cpdef utils.dpnp_descriptor dpnp_rng_zipf(double a, size): +cpdef utils.dpnp_descriptor dpnp_rng_zipf( + double a, size +): """ - Returns an array populated with samples from Zipf distribution. - `dpnp_rng_zipf` generates a matrix filled with random floats sampled from a - univariate Zipf distribution. + Returns an array populated with samples from Zipf + distribution. + `dpnp_rng_zipf` generates a matrix filled with random + floats sampled from a univariate Zipf distribution. """ - # convert string type names (array.dtype) to C enum DPNPFuncType - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dpnp.float64) + # convert string type names (array.dtype) to + # C enum DPNPFuncType + cdef DPNPFuncType param1_type = ( + dpnp_dtype_to_DPNPFuncType(dpnp.float64) + ) # get the FPTR data structure - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_ZIPF_EXT, param1_type, param1_type) + cdef DPNPFuncData kernel_data = get_dpnp_function_ptr( + DPNP_FN_RNG_ZIPF_EXT, param1_type, param1_type, + ) # create result array with type given by FPTR data - cdef shape_type_c result_shape = utils._object_to_tuple(size) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) + cdef shape_type_c result_shape = ( + utils._object_to_tuple(size) + ) + cdef utils.dpnp_descriptor result = ( + utils.create_output_descriptor( + result_shape, kernel_data.return_type, None, + ) + ) result_sycl_queue = result.get_array().sycl_queue - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() + cdef c_dpctl.SyclQueue q = ( + result_sycl_queue + ) + cdef c_dpctl.DPCTLSyclQueueRef q_ref = ( + q.get_queue_ref() + ) - cdef fptr_dpnp_rng_zipf_c_1out_t func = kernel_data.ptr + cdef fptr_dpnp_rng_zipf_c_1out_t func = ( + kernel_data.ptr + ) # call FPTR function - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), a, result.size, NULL) + cdef c_dpctl.DPCTLSyclEventRef event_ref = func( + q_ref, result.get_data(), a, result.size, NULL, + ) - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) + with nogil: + c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) c_dpctl.DPCTLEvent_Delete(event_ref) return result diff --git a/dpnp/tensor/_compute_follows_data.pyx b/dpnp/tensor/_compute_follows_data.pyx index 70e6bdfaeb7..c5028c55090 100644 --- a/dpnp/tensor/_compute_follows_data.pyx +++ b/dpnp/tensor/_compute_follows_data.pyx @@ -32,8 +32,8 @@ """Compute-follows-data utilities for execution queue and USM type management. -This module provides utilities to determine execution placement and USM allocation -types when combining arrays under the compute-follows-data paradigm. +This module provides utilities to determine execution placement and USM +allocation types when combining arrays under the compute-follows-data paradigm. """ diff --git a/pyproject.toml b/pyproject.toml index 02567d2f25a..773d3cb4590 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,6 +130,9 @@ source = [ "dpnp" ] +[tool.cython-lint] +max-line-length = 80 + [tool.isort] ensure_newline_before_comments = true force_grid_wrap = 0