diff --git a/dpnp/random/dpnp_algo_random.pyx b/dpnp/random/dpnp_algo_random.pyx index 8d42fa86be4..e7fdcdd02f2 100644 --- a/dpnp/random/dpnp_algo_random.pyx +++ b/dpnp/random/dpnp_algo_random.pyx @@ -37,7 +37,9 @@ import dpnp.config as config from dpnp.dpnp_algo cimport * from dpnp.dparray cimport dparray -from dpnp.dpnp_utils cimport * + +cimport dpnp.dpnp_utils as utils + import numpy cimport numpy @@ -137,7 +139,7 @@ ctypedef void(*fptr_dpnp_rng_weibull_c_1out_t)(void * , const double, const size ctypedef void(*fptr_dpnp_rng_zipf_c_1out_t)(void * , const double, const size_t) except + -cpdef dparray 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 @@ -151,9 +153,9 @@ cpdef dparray dpnp_rng_beta(double a, double b, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_BETA, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_beta_c_1out_t func = kernel_data.ptr # call FPTR function @@ -162,7 +164,7 @@ cpdef dparray dpnp_rng_beta(double a, double b, size): return result -cpdef dparray 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 @@ -172,7 +174,6 @@ cpdef dparray dpnp_rng_binomial(int ntrial, double p, size): """ dtype = numpy.int32 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_binomial_c_1out_t func @@ -183,9 +184,9 @@ cpdef dparray dpnp_rng_binomial(int ntrial, double p, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_BINOMIAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -194,7 +195,7 @@ cpdef dparray dpnp_rng_binomial(int ntrial, double p, size): return result -cpdef dparray 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 @@ -208,9 +209,9 @@ cpdef dparray dpnp_rng_chisquare(int df, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_CHISQUARE, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_chisquare_c_1out_t func = kernel_data.ptr # call FPTR function @@ -219,7 +220,7 @@ cpdef dparray dpnp_rng_chisquare(int df, size): return result -cpdef dparray 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 @@ -234,9 +235,9 @@ cpdef dparray dpnp_rng_exponential(double beta, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_EXPONENTIAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=dtype) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_exponential_c_1out_t func = kernel_data.ptr # call FPTR function @@ -245,7 +246,7 @@ cpdef dparray dpnp_rng_exponential(double beta, size): return result -cpdef dparray 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 @@ -259,9 +260,9 @@ cpdef dparray dpnp_rng_f(double df_num, double df_den, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_F, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=dtype) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_f_c_1out_t func = kernel_data.ptr # call FPTR function @@ -270,7 +271,7 @@ cpdef dparray dpnp_rng_f(double df_num, double df_den, size): return result -cpdef dparray 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 @@ -279,7 +280,6 @@ cpdef dparray dpnp_rng_gamma(double shape, double scale, size): """ dtype = numpy.float64 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_gamma_c_1out_t func @@ -287,8 +287,10 @@ cpdef dparray 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, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) - result = dparray(size, dtype=result_type) + + # ceate result array with type given by FPTR data + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -297,7 +299,7 @@ cpdef dparray dpnp_rng_gamma(double shape, double scale, size): return result -cpdef dparray 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 @@ -307,7 +309,6 @@ cpdef dparray dpnp_rng_geometric(float p, size): """ dtype = numpy.int32 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_geometric_c_1out_t func @@ -318,9 +319,9 @@ cpdef dparray dpnp_rng_geometric(float p, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_GEOMETRIC, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -329,7 +330,7 @@ cpdef dparray dpnp_rng_geometric(float p, size): return result -cpdef dparray 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 @@ -338,15 +339,16 @@ cpdef dparray dpnp_rng_gumbel(double loc, double scale, size): """ dtype = numpy.float64 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data 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, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) - result = dparray(size, dtype=result_type) + + # ceate result array with type given by FPTR data + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -355,7 +357,7 @@ cpdef dparray dpnp_rng_gumbel(double loc, double scale, size): return result -cpdef dparray 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 @@ -364,7 +366,6 @@ cpdef dparray dpnp_rng_hypergeometric(int l, int s, int m, size): """ dtype = numpy.int32 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_hypergeometric_c_1out_t func @@ -375,9 +376,9 @@ cpdef dparray dpnp_rng_hypergeometric(int l, int s, int m, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_HYPERGEOMETRIC, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -386,7 +387,7 @@ cpdef dparray dpnp_rng_hypergeometric(int l, int s, int m, size): return result -cpdef dparray 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 @@ -395,7 +396,6 @@ cpdef dparray dpnp_rng_laplace(double loc, double scale, size): """ dtype = numpy.float64 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_laplace_c_1out_t func @@ -406,9 +406,9 @@ cpdef dparray dpnp_rng_laplace(double loc, double scale, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_LAPLACE, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -417,7 +417,7 @@ cpdef dparray dpnp_rng_laplace(double loc, double scale, size): return result -cpdef dparray 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 @@ -431,9 +431,9 @@ cpdef dparray dpnp_rng_logistic(double loc, double scale, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_LOGISTIC, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_logistic_c_1out_t func = < fptr_dpnp_rng_logistic_c_1out_t > kernel_data.ptr # call FPTR function @@ -442,7 +442,7 @@ cpdef dparray dpnp_rng_logistic(double loc, double scale, size): return result -cpdef dparray 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 @@ -451,7 +451,6 @@ cpdef dparray dpnp_rng_lognormal(double mean, double stddev, size): """ dtype = numpy.float64 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_lognormal_c_1out_t func @@ -462,9 +461,9 @@ cpdef dparray dpnp_rng_lognormal(double mean, double stddev, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_LOGNORMAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -473,7 +472,7 @@ cpdef dparray dpnp_rng_lognormal(double mean, double stddev, size): return result -cpdef dparray dpnp_rng_multinomial(int ntrial, p, size): +cpdef utils.dpnp_descriptor dpnp_rng_multinomial(int ntrial, p, size): """ Returns an array populated with samples from multinomial distribution. @@ -484,7 +483,6 @@ cpdef dparray dpnp_rng_multinomial(int ntrial, p, size): """ dtype = numpy.int32 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_multinomial_c_1out_t func @@ -499,9 +497,9 @@ cpdef dparray dpnp_rng_multinomial(int ntrial, p, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_MULTINOMIAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -510,7 +508,7 @@ cpdef dparray dpnp_rng_multinomial(int ntrial, p, size): return result -cpdef dparray dpnp_rng_multivariate_normal(numpy.ndarray mean, numpy.ndarray cov, size): +cpdef utils.dpnp_descriptor dpnp_rng_multivariate_normal(numpy.ndarray mean, numpy.ndarray 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 @@ -519,7 +517,6 @@ cpdef dparray dpnp_rng_multivariate_normal(numpy.ndarray mean, numpy.ndarray cov """ dtype = numpy.float64 - cdef dparray result cdef int dimen cdef double * mean_vector cdef double * cov_vector @@ -543,9 +540,9 @@ cpdef dparray dpnp_rng_multivariate_normal(numpy.ndarray mean, numpy.ndarray cov # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_MULTIVARIATE_NORMAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) dimen = len(mean) @@ -597,7 +594,7 @@ cpdef dparray dpnp_rng_negative_binomial(double a, double p, size): return result -cpdef dparray 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 @@ -611,9 +608,9 @@ cpdef dparray dpnp_rng_noncentral_chisquare(double df, double nonc, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_NONCENTRAL_CHISQUARE, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_noncentral_chisquare_c_1out_t func = < fptr_dpnp_rng_noncentral_chisquare_c_1out_t > kernel_data.ptr # call FPTR function @@ -657,7 +654,7 @@ cpdef dparray dpnp_rng_normal(double loc, double scale, size): return result -cpdef dparray 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 @@ -672,9 +669,9 @@ cpdef dparray dpnp_rng_pareto(double alpha, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_PARETO, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=dtype) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_pareto_c_1out_t func = kernel_data.ptr # call FPTR function @@ -719,7 +716,7 @@ cpdef dparray dpnp_rng_poisson(double lam, size): return result -cpdef dparray 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 @@ -733,9 +730,9 @@ cpdef dparray dpnp_rng_power(double alpha, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_POWER, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=dtype) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_power_c_1out_t func = kernel_data.ptr # call FPTR function @@ -744,7 +741,7 @@ cpdef dparray dpnp_rng_power(double alpha, size): return result -cpdef dparray dpnp_rng_randn(dims): +cpdef utils.dpnp_descriptor dpnp_rng_randn(dims): """ Returns an array populated with samples from standard normal distribution. `dpnp_rng_randn` generates a matrix filled with random floats sampled from a @@ -760,9 +757,9 @@ cpdef dparray dpnp_rng_randn(dims): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_GAUSSIAN, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(dims, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(dims) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_gaussian_c_1out_t func = kernel_data.ptr # call FPTR function @@ -771,7 +768,7 @@ cpdef dparray dpnp_rng_randn(dims): return result -cpdef dparray dpnp_rng_random(dims): +cpdef utils.dpnp_descriptor dpnp_rng_random(dims): """ Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1). @@ -786,9 +783,9 @@ cpdef dparray dpnp_rng_random(dims): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_UNIFORM, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(dims, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(dims) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_uniform_c_1out_t func = kernel_data.ptr # call FPTR function @@ -871,7 +868,7 @@ cpdef dpnp_rng_srand(seed): func(seed) -cpdef dparray 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 @@ -885,9 +882,9 @@ cpdef dparray dpnp_rng_standard_cauchy(size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_CAUCHY, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_standard_cauchy_c_1out_t func = < fptr_dpnp_rng_standard_cauchy_c_1out_t > kernel_data.ptr # call FPTR function @@ -896,7 +893,7 @@ cpdef dparray dpnp_rng_standard_cauchy(size): return result -cpdef dparray 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 @@ -912,9 +909,9 @@ cpdef dparray dpnp_rng_standard_exponential(size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_EXPONENTIAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = < fptr_dpnp_rng_standard_exponential_c_1out_t > kernel_data.ptr # call FPTR function @@ -958,7 +955,7 @@ cpdef dparray dpnp_rng_standard_gamma(double shape, size): return result -cpdef dparray dpnp_rng_standard_normal(size): +cpdef utils.dpnp_descriptor dpnp_rng_standard_normal(size): """ Returns an array populated with samples from standard normal(Gaussian) distribution. `dpnp_standard_normal` generates a matrix filled with random floats sampled from a @@ -972,9 +969,9 @@ cpdef dparray dpnp_rng_standard_normal(size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_NORMAL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_standard_normal_c_1out_t func = < fptr_dpnp_rng_standard_normal_c_1out_t > kernel_data.ptr # call FPTR function @@ -982,7 +979,7 @@ cpdef dparray dpnp_rng_standard_normal(size): return result -cpdef dparray 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 @@ -996,9 +993,9 @@ cpdef dparray dpnp_rng_standard_t(double df, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_STANDARD_T, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_standard_t_c_1out_t func = kernel_data.ptr # call FPTR function @@ -1007,7 +1004,7 @@ cpdef dparray dpnp_rng_standard_t(double df, size): return result -cpdef dparray 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 @@ -1022,9 +1019,9 @@ cpdef dparray dpnp_rng_triangular(double left, double mode, double right, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_TRIANGULAR, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=dtype) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_triangular_c_1out_t func = kernel_data.ptr # call FPTR function @@ -1068,7 +1065,7 @@ cpdef dparray dpnp_rng_uniform(long low, long high, size, dtype): return result -cpdef dparray 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 @@ -1082,9 +1079,9 @@ cpdef dparray dpnp_rng_vonmises(double mu, double kappa, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_VONMISES, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_vonmises_c_1out_t func = kernel_data.ptr # call FPTR function @@ -1093,7 +1090,7 @@ cpdef dparray dpnp_rng_vonmises(double mu, double kappa, size): return result -cpdef dparray 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 @@ -1108,9 +1105,9 @@ cpdef dparray dpnp_rng_wald(double mean, double scale, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_WALD, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=dtype) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_wald_c_1out_t func = kernel_data.ptr # call FPTR function @@ -1119,7 +1116,7 @@ cpdef dparray dpnp_rng_wald(double mean, double scale, size): return result -cpdef dparray 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 @@ -1128,7 +1125,6 @@ cpdef dparray dpnp_rng_weibull(double a, size): """ dtype = numpy.float64 - cdef dparray result cdef DPNPFuncType param1_type cdef DPNPFuncData kernel_data cdef fptr_dpnp_rng_weibull_c_1out_t func @@ -1139,9 +1135,9 @@ cpdef dparray dpnp_rng_weibull(double a, size): # get the FPTR data structure kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_WEIBULL, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) func = kernel_data.ptr # call FPTR function @@ -1150,7 +1146,7 @@ cpdef dparray dpnp_rng_weibull(double a, size): return result -cpdef dparray 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 @@ -1164,9 +1160,9 @@ cpdef dparray dpnp_rng_zipf(double a, size): # get the FPTR data structure cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_RNG_ZIPF, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) # ceate result array with type given by FPTR data - cdef dparray result = dparray(size, dtype=result_type) + cdef dparray_shape_type result_shape = utils._object_to_tuple(size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_dpnp_rng_zipf_c_1out_t func = kernel_data.ptr # call FPTR function diff --git a/dpnp/random/dpnp_iface_random.py b/dpnp/random/dpnp_iface_random.py index a55626d6402..789bff8ae2e 100644 --- a/dpnp/random/dpnp_iface_random.py +++ b/dpnp/random/dpnp_iface_random.py @@ -138,7 +138,7 @@ def beta(a, b, size=None): elif b <= 0: pass else: - return dpnp_rng_beta(a, b, size) + return dpnp_rng_beta(a, b, size).get_pyobj() return call_origin(numpy.random.beta, a, b, size) @@ -184,7 +184,7 @@ def binomial(n, p, size=None): elif n < 0: pass else: - return dpnp_rng_binomial(int(n), p, size) + return dpnp_rng_binomial(int(n), p, size).get_pyobj() return call_origin(numpy.random.binomial, n, p, size) @@ -236,7 +236,7 @@ def chisquare(df, size=None): else: # TODO: # float to int, safe - return dpnp_rng_chisquare(int(df), size) + return dpnp_rng_chisquare(int(df), size).get_pyobj() return call_origin(numpy.random.chisquare, df, size) @@ -303,7 +303,7 @@ def exponential(scale=1.0, size=None): elif scale < 0: pass else: - return dpnp_rng_exponential(scale, size) + return dpnp_rng_exponential(scale, size).get_pyobj() return call_origin(numpy.random.exponential, scale, size) @@ -339,7 +339,7 @@ def f(dfnum, dfden, size=None): elif dfden <= 0: pass else: - return dpnp_rng_f(dfnum, dfden, size) + return dpnp_rng_f(dfnum, dfden, size).get_pyobj() return call_origin(numpy.random.f, dfnum, dfden, size) @@ -377,7 +377,7 @@ def gamma(shape, scale=1.0, size=None): elif shape < 0: pass else: - return dpnp_rng_gamma(shape, scale, size) + return dpnp_rng_gamma(shape, scale, size).get_pyobj() return call_origin(numpy.random.gamma, shape, scale, size) @@ -411,7 +411,7 @@ def geometric(p, size=None): elif p > 1 or p <= 0: pass else: - return dpnp_rng_geometric(p, size) + return dpnp_rng_geometric(p, size).get_pyobj() return call_origin(numpy.random.geometric, p, size) @@ -447,7 +447,7 @@ def gumbel(loc=0.0, scale=1.0, size=None): elif scale < 0: pass else: - return dpnp_rng_gumbel(loc, scale, size) + return dpnp_rng_gumbel(loc, scale, size).get_pyobj() return call_origin(numpy.random.gumbel, loc, scale, size) @@ -498,7 +498,7 @@ def hypergeometric(ngood, nbad, nsample, size=None): m = int(ngood) l = int(ngood) + int(nbad) s = int(nsample) - return dpnp_rng_hypergeometric(l, s, m, size) + return dpnp_rng_hypergeometric(l, s, m, size).get_pyobj() return call_origin(numpy.random.hypergeometric, ngood, nbad, nsample, size) @@ -534,7 +534,7 @@ def laplace(loc=0.0, scale=1.0, size=None): elif scale < 0: pass else: - return dpnp_rng_laplace(loc, scale, size) + return dpnp_rng_laplace(loc, scale, size).get_pyobj() return call_origin(numpy.random.laplace, loc, scale, size) @@ -569,10 +569,11 @@ def logistic(loc=0.0, scale=1.0, size=None): elif scale < 0: pass else: + result = dpnp_rng_logistic(loc, scale, size).get_pyobj() if size == None or size == 1: - return dpnp_rng_logistic(loc, scale, size)[0] + return result[0] else: - return dpnp_rng_logistic(loc, scale, size) + return result return call_origin(numpy.random.logistic, loc, scale, size) @@ -609,7 +610,7 @@ def lognormal(mean=0.0, sigma=1.0, size=None): elif sigma < 0: pass else: - return dpnp_rng_lognormal(mean, sigma, size) + return dpnp_rng_lognormal(mean, sigma, size).get_pyobj() return call_origin(numpy.random.lognormal, mean, sigma, size) @@ -674,7 +675,7 @@ def multinomial(n, pvals, size=None): except: shape = tuple(size) + (d,) - return dpnp_rng_multinomial(int(n), pvals, shape) + return dpnp_rng_multinomial(int(n), pvals, shape).get_pyobj() return call_origin(numpy.random.multinomial, n, pvals, size) @@ -720,7 +721,7 @@ def multivariate_normal(mean, cov, size=None, check_valid='warn', tol=1e-8): else: final_shape = list(shape[:]) final_shape.append(mean_.shape[0]) - return dpnp_rng_multivariate_normal(mean_, cov_, final_shape) + return dpnp_rng_multivariate_normal(mean_, cov_, final_shape).get_pyobj() return call_origin(numpy.random.multivariate_normal, mean, cov, size, check_valid, tol) @@ -831,7 +832,7 @@ def noncentral_chisquare(df, nonc, size=None): elif nonc < 0: pass else: - return dpnp_rng_noncentral_chisquare(df, nonc, size) + return dpnp_rng_noncentral_chisquare(df, nonc, size).get_pyobj() return call_origin(numpy.random.noncentral_chisquare, df, nonc, size) @@ -882,7 +883,7 @@ def pareto(a, size=None): elif a <= 0: pass else: - return dpnp_rng_pareto(a, size) + return dpnp_rng_pareto(a, size).get_pyobj() return call_origin(numpy.random.pareto, a, size) @@ -986,7 +987,7 @@ def power(a, size=None): elif a <= 0: pass else: - return dpnp_rng_power(a, size) + return dpnp_rng_power(a, size).get_pyobj() return call_origin(numpy.random.power, a, size) @@ -1018,7 +1019,7 @@ def rand(d0, *dn): if not _check_dims(dims): pass else: - return dpnp_rng_random(dims) + return dpnp_rng_random(dims).get_pyobj() return call_origin(numpy.random.rand, d0, *dn) @@ -1109,7 +1110,7 @@ def randn(d0, *dn): if not _check_dims(dims): pass else: - return dpnp_rng_randn(dims) + return dpnp_rng_randn(dims).get_pyobj() return call_origin(numpy.random.randn, d0, *dn) @@ -1136,7 +1137,7 @@ def random(size): """ if not use_origin_backend(size): - return dpnp_rng_random(size) + return dpnp_rng_random(size).get_pyobj() return call_origin(numpy.random.random, size) @@ -1196,7 +1197,7 @@ def random_sample(size): """ if not use_origin_backend(size): - return dpnp_rng_random(size) + return dpnp_rng_random(size).get_pyobj() return call_origin(numpy.random.random_sample, size) @@ -1223,7 +1224,7 @@ def ranf(size): """ if not use_origin_backend(size): - return dpnp_rng_random(size) + return dpnp_rng_random(size).get_pyobj() return call_origin(numpy.random.ranf, size) @@ -1284,7 +1285,7 @@ def sample(size): """ if not use_origin_backend(size): - return dpnp_rng_random(size) + return dpnp_rng_random(size).get_pyobj() return call_origin(numpy.random.sample, size) @@ -1362,7 +1363,7 @@ def standard_cauchy(size=None): """ if not use_origin_backend(size): - return dpnp_rng_standard_cauchy(size) + return dpnp_rng_standard_cauchy(size).get_pyobj() return call_origin(numpy.random.standard_cauchy, size) @@ -1387,7 +1388,7 @@ def standard_exponential(size=None): """ if not use_origin_backend(size): - return dpnp_rng_standard_exponential(size) + return dpnp_rng_standard_exponential(size).get_pyobj() return call_origin(numpy.random.standard_exponential, size) @@ -1446,7 +1447,7 @@ def standard_normal(size=None): """ if not use_origin_backend(size): - return dpnp_rng_standard_normal(size) + return dpnp_rng_standard_normal(size).get_pyobj() return call_origin(numpy.random.standard_normal, size) @@ -1482,7 +1483,8 @@ def standard_t(df, size=None): elif df <= 0: pass else: - return dpnp_rng_standard_t(df, size) + return dpnp_rng_standard_t(df, size).get_pyobj() + return call_origin(numpy.random.standard_t, df, size) @@ -1525,7 +1527,7 @@ def triangular(left, mode, right, size=None): elif left == right: pass else: - return dpnp_rng_triangular(left, mode, right, size) + return dpnp_rng_triangular(left, mode, right, size).get_pyobj() return call_origin(numpy.random.triangular, left, mode, right, size) @@ -1602,7 +1604,7 @@ def vonmises(mu, kappa, size=None): elif kappa < 0: pass else: - return dpnp_rng_vonmises(mu, kappa, size) + return dpnp_rng_vonmises(mu, kappa, size).get_pyobj() return call_origin(numpy.random.vonmises, mu, kappa, size) @@ -1639,7 +1641,7 @@ def wald(mean, scale, size=None): elif scale <= 0: pass else: - return dpnp_rng_wald(mean, scale, size) + return dpnp_rng_wald(mean, scale, size).get_pyobj() return call_origin(numpy.random.wald, mean, scale, size) @@ -1672,7 +1674,7 @@ def weibull(a, size=None): elif a < 0: pass else: - return dpnp_rng_weibull(a, size) + return dpnp_rng_weibull(a, size).get_pyobj() return call_origin(numpy.random.weibull, a, size) @@ -1705,6 +1707,6 @@ def zipf(a, size=None): elif a <= 1: pass else: - return dpnp_rng_zipf(a, size) + return dpnp_rng_zipf(a, size).get_pyobj() return call_origin(numpy.random.zipf, a, size)