Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 1 addition & 13 deletions dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -292,13 +292,6 @@ void dpnp_eye_c(void* result1, int k, const shape_elem_type* res_shape)
template <typename _DataType>
void (*dpnp_eye_default_c)(void*, int, const shape_elem_type*) = dpnp_eye_c<_DataType>;

template <typename _DataType>
DPCTLSyclEventRef (*dpnp_eye_ext_c)(DPCTLSyclQueueRef,
void*,
int,
const shape_elem_type*,
const DPCTLEventVectorRef) = dpnp_eye_c<_DataType>;

template <typename _DataType>
DPCTLSyclEventRef dpnp_full_c(DPCTLSyclQueueRef q_ref,
void* array_in,
Expand Down Expand Up @@ -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<float>};
fmap[DPNPFuncName::DPNP_FN_EYE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eye_default_c<double>};

fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_eye_ext_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_eye_ext_c<int64_t>};
fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_eye_ext_c<float>};
fmap[DPNPFuncName::DPNP_FN_EYE_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eye_ext_c<double>};

fmap[DPNPFuncName::DPNP_FN_FULL][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_full_default_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_FULL][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_full_default_c<int64_t>};
fmap[DPNPFuncName::DPNP_FN_FULL][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_full_default_c<float>};
Expand Down
34 changes: 0 additions & 34 deletions dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ and the rest of the library
__all__ += [
"dpnp_copy",
"dpnp_diag",
"dpnp_eye",
"dpnp_geomspace",
"dpnp_identity",
"dpnp_linspace",
Expand Down Expand Up @@ -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 * ,
Expand Down Expand Up @@ -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 = <c_dpctl.SyclQueue> result_sycl_queue
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()

cdef fptr_dpnp_eye_t func = <fptr_dpnp_eye_t > 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)
Expand Down
30 changes: 29 additions & 1 deletion dpnp/dpnp_container.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,6 +45,7 @@
"arange",
"asarray",
"empty",
"eye",
"full",
"ones"
"zeros",
Expand Down Expand Up @@ -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,
Expand Down
52 changes: 34 additions & 18 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,31 +572,47 @@ 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,
**kwargs):
"""
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``.
Additional ``kwards`` are not supported.
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
elif len(kwargs) != 0:
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, **kwargs)


def frombuffer(buffer, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion tests/skipped_tests.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 20 additions & 12 deletions tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 9 additions & 6 deletions tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/third_party/cupy/creation_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down