diff --git a/dpnp/backend/include/dpnp_iface_fptr.hpp b/dpnp/backend/include/dpnp_iface_fptr.hpp index 7a3564fa1d35..31347ceaeb58 100644 --- a/dpnp/backend/include/dpnp_iface_fptr.hpp +++ b/dpnp/backend/include/dpnp_iface_fptr.hpp @@ -155,7 +155,6 @@ enum class DPNPFuncName : size_t DPNP_FN_ERF, /**< Used in scipy.special.erf impl */ DPNP_FN_ERF_EXT, /**< Used in scipy.special.erf impl, requires extra parameters */ DPNP_FN_EYE, /**< Used in numpy.eye() impl */ - DPNP_FN_EYE_EXT, /**< Used in numpy.eye() impl, requires extra parameters */ DPNP_FN_EXP, /**< Used in numpy.exp() impl */ DPNP_FN_EXP_EXT, /**< Used in numpy.exp() impl, requires extra parameters */ DPNP_FN_EXP2, /**< Used in numpy.exp2() impl */ diff --git a/dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp b/dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp index 71d93842feb0..8727e37fafc2 100644 --- a/dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp @@ -1,5 +1,5 @@ //***************************************************************************** -// Copyright (c) 2016-2022, Intel Corporation +// Copyright (c) 2016-2023, Intel Corporation // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -292,13 +292,6 @@ void dpnp_eye_c(void* result1, int k, const shape_elem_type* res_shape) template void (*dpnp_eye_default_c)(void*, int, const shape_elem_type*) = dpnp_eye_c<_DataType>; -template -DPCTLSyclEventRef (*dpnp_eye_ext_c)(DPCTLSyclQueueRef, - void*, - int, - const shape_elem_type*, - const DPCTLEventVectorRef) = dpnp_eye_c<_DataType>; - template DPCTLSyclEventRef dpnp_full_c(DPCTLSyclQueueRef q_ref, void* array_in, @@ -1319,11 +1312,6 @@ void func_map_init_arraycreation(func_map_t& fmap) fmap[DPNPFuncName::DPNP_FN_EYE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_eye_default_c}; fmap[DPNPFuncName::DPNP_FN_EYE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eye_default_c}; - fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_eye_ext_c}; - fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_eye_ext_c}; - fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_eye_ext_c}; - fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eye_ext_c}; - fmap[DPNPFuncName::DPNP_FN_FULL][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_full_default_c}; fmap[DPNPFuncName::DPNP_FN_FULL][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_full_default_c}; fmap[DPNPFuncName::DPNP_FN_FULL][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_full_default_c}; diff --git a/dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx b/dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx index 1ec69c55311f..6986bf0ec702 100644 --- a/dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx +++ b/dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx @@ -37,7 +37,6 @@ and the rest of the library __all__ += [ "dpnp_copy", "dpnp_diag", - "dpnp_eye", "dpnp_geomspace", "dpnp_identity", "dpnp_linspace", @@ -84,9 +83,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*custom_indexing_1out_func_ptr_t)(c_dpctl.DPC const size_t , const int, const c_dpctl.DPCTLEventVectorRef) except + -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_eye_t)(c_dpctl.DPCTLSyclQueueRef, - void *, int , const shape_elem_type * , - const c_dpctl.DPCTLEventVectorRef) ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_trace_t)(c_dpctl.DPCTLSyclQueueRef, const void *, void * , @@ -146,36 +142,6 @@ cpdef utils.dpnp_descriptor dpnp_diag(utils.dpnp_descriptor v, int k): return result -cpdef utils.dpnp_descriptor dpnp_eye(N, M=None, k=0, dtype=None): - if dtype is None: - dtype = dpnp.float64 - - if M is None: - M = N - - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype) - - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_EYE_EXT, param1_type, param1_type) - - cdef utils.dpnp_descriptor result = utils.create_output_descriptor((N, M), 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_eye_t func = kernel_data.ptr - - cdef shape_type_c result_shape = result.shape - - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, result.get_data(), k, result_shape.data(), NULL) - - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) - c_dpctl.DPCTLEvent_Delete(event_ref) - - return result - - cpdef utils.dpnp_descriptor dpnp_geomspace(start, stop, num, endpoint, dtype, axis): cdef shape_type_c obj_shape = utils._object_to_tuple(num) cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(obj_shape, dtype, None) diff --git a/dpnp/dpnp_container.py b/dpnp/dpnp_container.py index 93ab716eb59a..7065e497652d 100644 --- a/dpnp/dpnp_container.py +++ b/dpnp/dpnp_container.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # ***************************************************************************** -# Copyright (c) 2016-2022, Intel Corporation +# Copyright (c) 2016-2023, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ "arange", "asarray", "empty", + "eye", "full", "ones" "zeros", @@ -150,6 +151,33 @@ def full(shape, return dpnp_array(array_obj.shape, buffer=array_obj, order=order) +def eye(N, + M=None, + /, + *, + k=0, + dtype=None, + order="C", + device=None, + usm_type="device", + sycl_queue=None): + """Validate input parameters before passing them into `dpctl.tensor` module""" + dpu.validate_usm_type(usm_type, allow_none=False) + sycl_queue_normalized = dpnp.get_normalized_queue_device(sycl_queue=sycl_queue, device=device) + if order is None: + order = 'C' + + """Creates `dpnp_array` with ones on the `k`th diagonal.""" + array_obj = dpt.eye(N, + M, + k=k, + dtype=dtype, + order=order, + usm_type=usm_type, + sycl_queue=sycl_queue_normalized) + return dpnp_array(array_obj.shape, buffer=array_obj, order=order) + + def ones(shape, *, dtype=None, diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 03d8b8185200..c0ed49316b8a 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -572,31 +572,43 @@ def empty_like(x1, return call_origin(numpy.empty_like, x1, dtype, order, subok, shape) -def eye(N, M=None, k=0, dtype=None, order='C', **kwargs): +def eye(N, + M=None, + /, + *, + k=0, + dtype=None, + order="C", + like=None, + device=None, + usm_type="device", + sycl_queue=None): """ Return a 2-D array with ones on the diagonal and zeros elsewhere. For full documentation refer to :obj:`numpy.eye`. Limitations ----------- - Input array is supported as :obj:`dpnp.ndarray`. - Parameters ``order`` is supported only with default value. - """ - if (not use_origin_backend()): - if not isinstance(N, (int, dpnp.int, dpnp.int32, dpnp.int64)): - pass - elif M is not None and not isinstance(M, (int, dpnp.int, dpnp.int32, dpnp.int64)): - pass - elif not isinstance(k, (int, dpnp.int, dpnp.int32, dpnp.int64)): - pass - elif order != 'C': - pass - elif len(kwargs) != 0: - pass - else: - return dpnp_eye(N, M=M, k=k, dtype=dtype).get_pyobj() + Parameter ``order`` is supported only with values ``"C"`` and ``"F"``. + Parameter ``like`` is supported only with default value ``None``. + Otherwise the function will be executed sequentially on CPU. - return call_origin(numpy.eye, N, M=M, k=k, dtype=dtype, order=order, **kwargs) + """ + if order not in ('C', 'c', 'F', 'f', None): + pass + elif like is not None: + pass + else: + return dpnp_container.eye(N, + M, + k=k, + dtype=dtype, + order=order, + device=device, + usm_type=usm_type, + sycl_queue=sycl_queue) + + return call_origin(numpy.eye, N, M, k=k, dtype=dtype, order=order, like=None) def frombuffer(buffer, **kwargs): diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index df4a14236509..63c6cbd0d133 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -330,7 +330,6 @@ tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_ tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_K_strides tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_subok tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_zero_sized_array_strides -tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_eye tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_full_like_subok tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_ones_like_subok tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_zeros_like_subok diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index e0500848e9b9..e41979efe050 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -101,21 +101,29 @@ def test_diag(v, k): @pytest.mark.parametrize("N", - [0, 1, 2, 3, 4], - ids=['0', '1', '2', '3', '4']) + [0, 1, 2, 3], + ids=['0', '1', '2', '3']) @pytest.mark.parametrize("M", - [None, 0, 1, 2, 3, 4], - ids=['None', '0', '1', '2', '3', '4']) + [None, 0, 1, 2, 3], + ids=['None', '0', '1', '2', '3']) @pytest.mark.parametrize("k", - [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], - ids=['-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5']) + [-4, -3, -2, -1, 0, 1, 2, 3, 4], + ids=['-4', '-3', '-2', '-1', '0', '1', '2', '3', '4']) @pytest.mark.parametrize("dtype", - [numpy.float64, numpy.float32, numpy.int64, numpy.int32], - ids=['float64', 'float32', 'int64', 'int32']) -def test_eye(N, M, k, dtype): - expected = numpy.eye(N, M=M, k=k, dtype=dtype) - result = dpnp.eye(N, M=M, k=k, dtype=dtype) - assert_array_equal(expected, result) + [None, numpy.complex128, numpy.complex64, numpy.float64, numpy.float32, + numpy.float16, numpy.int64, numpy.int32, numpy.bool], + ids=['None', 'complex128', 'complex64', 'float64', 'float32', + 'float16', 'int64', 'int32', 'bool']) +@pytest.mark.parametrize("order", + [None, "C", "F"], + ids=['None', 'C', 'F']) +def test_eye(N, M, k, dtype, order): + func = lambda xp: xp.eye(N, M, k=k, dtype=dtype, order=order) + if not is_dtype_supported(dtype, no_complex_check=True): + assert_raises(RuntimeError, func, dpnp) + return + + assert_array_equal(func(numpy), func(dpnp)) @pytest.mark.usefixtures("allow_fall_back_on_numpy") diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index a184ec51c253..1eae3df9393f 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -76,27 +76,30 @@ def vvsort(val, vec, size, xp): "func, arg, kwargs", [ pytest.param("arange", - -25.7, + [-25.7], {'stop': 10**8, 'step': 15}), pytest.param("full", - (2,2), + [(2,2)], {'fill_value': 5}), + pytest.param("eye", + [4, 2], + {}), pytest.param("ones", - (2,2), + [(2,2)], {}), pytest.param("zeros", - (2,2), + [(2,2)], {}) ]) @pytest.mark.parametrize("device", valid_devices, ids=[device.filter_string for device in valid_devices]) def test_array_creation(func, arg, kwargs, device): - numpy_array = getattr(numpy, func)(arg, **kwargs) + numpy_array = getattr(numpy, func)(*arg, **kwargs) dpnp_kwargs = dict(kwargs) dpnp_kwargs['device'] = device - dpnp_array = getattr(dpnp, func)(arg, **dpnp_kwargs) + dpnp_array = getattr(dpnp, func)(*arg, **dpnp_kwargs) numpy.testing.assert_array_equal(numpy_array, dpnp_array) assert dpnp_array.sycl_device == device diff --git a/tests/third_party/cupy/creation_tests/test_basic.py b/tests/third_party/cupy/creation_tests/test_basic.py index 337718d3caf3..1adcf98f969b 100644 --- a/tests/third_party/cupy/creation_tests/test_basic.py +++ b/tests/third_party/cupy/creation_tests/test_basic.py @@ -164,7 +164,7 @@ def test_empty_zero_sized_array_strides(self, order): @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_eye(self, xp, dtype): - return xp.eye(5, 4, 1, dtype) + return xp.eye(5, 4, k=1, dtype=dtype) @testing.for_all_dtypes() @testing.numpy_cupy_array_equal()