Skip to content

Commit cb31bbd

Browse files
committed
Merge branch 'multiply_by_scalar' of https://github.com/antonwolfy/dpnp into multiply_by_scalar
2 parents ccd9cbd + de9c084 commit cb31bbd

14 files changed

+158
-96
lines changed

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ enum class DPNPFuncName : size_t
373373
DPNP_FN_VAR, /**< Used in numpy.var() impl */
374374
DPNP_FN_VAR_EXT, /**< Used in numpy.var() impl, requires extra parameters */
375375
DPNP_FN_ZEROS, /**< Used in numpy.zeros() impl */
376-
DPNP_FN_ZEROS_EXT, /**< Used in numpy.zeros() impl, requires extra parameters */
377376
DPNP_FN_ZEROS_LIKE, /**< Used in numpy.zeros_like() impl */
378-
DPNP_FN_ZEROS_LIKE_EXT, /**< Used in numpy.zeros_like() impl, requires extra parameters */
379377
DPNP_FN_LAST, /**< The latest element of the enumeration */
380378
};
381379

dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,17 +1250,12 @@ void dpnp_zeros_c(void* result, size_t size)
12501250
size,
12511251
dep_event_vec_ref);
12521252
DPCTLEvent_WaitAndThrow(event_ref);
1253+
DPCTLEvent_Delete(event_ref);
12531254
}
12541255

12551256
template <typename _DataType>
12561257
void (*dpnp_zeros_default_c)(void*, size_t) = dpnp_zeros_c<_DataType>;
12571258

1258-
template <typename _DataType>
1259-
DPCTLSyclEventRef (*dpnp_zeros_ext_c)(DPCTLSyclQueueRef,
1260-
void*,
1261-
size_t,
1262-
const DPCTLEventVectorRef) = dpnp_zeros_c<_DataType>;
1263-
12641259
template <typename _DataType>
12651260
DPCTLSyclEventRef dpnp_zeros_like_c(DPCTLSyclQueueRef q_ref,
12661261
void* result,
@@ -1280,17 +1275,12 @@ void dpnp_zeros_like_c(void* result, size_t size)
12801275
size,
12811276
dep_event_vec_ref);
12821277
DPCTLEvent_WaitAndThrow(event_ref);
1278+
DPCTLEvent_Delete(event_ref);
12831279
}
12841280

12851281
template <typename _DataType>
12861282
void (*dpnp_zeros_like_default_c)(void*, size_t) = dpnp_zeros_like_c<_DataType>;
12871283

1288-
template <typename _DataType>
1289-
DPCTLSyclEventRef (*dpnp_zeros_like_ext_c)(DPCTLSyclQueueRef,
1290-
void*,
1291-
size_t,
1292-
const DPCTLEventVectorRef) = dpnp_zeros_like_c<_DataType>;
1293-
12941284
void func_map_init_arraycreation(func_map_t& fmap)
12951285
{
12961286
fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_arange_default_c<int32_t>};
@@ -1480,14 +1470,6 @@ void func_map_init_arraycreation(func_map_t& fmap)
14801470
fmap[DPNPFuncName::DPNP_FN_ZEROS][eft_C128][eft_C128] = {eft_C128,
14811471
(void*)dpnp_zeros_default_c<std::complex<double>>};
14821472

1483-
fmap[DPNPFuncName::DPNP_FN_ZEROS_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_zeros_ext_c<int32_t>};
1484-
fmap[DPNPFuncName::DPNP_FN_ZEROS_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_zeros_ext_c<int64_t>};
1485-
fmap[DPNPFuncName::DPNP_FN_ZEROS_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_zeros_ext_c<float>};
1486-
fmap[DPNPFuncName::DPNP_FN_ZEROS_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_zeros_ext_c<double>};
1487-
fmap[DPNPFuncName::DPNP_FN_ZEROS_EXT][eft_BLN][eft_BLN] = {eft_BLN, (void*)dpnp_zeros_ext_c<bool>};
1488-
fmap[DPNPFuncName::DPNP_FN_ZEROS_EXT][eft_C128][eft_C128] = {eft_C128,
1489-
(void*)dpnp_zeros_ext_c<std::complex<double>>};
1490-
14911473
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_zeros_like_default_c<int32_t>};
14921474
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_zeros_like_default_c<int64_t>};
14931475
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_zeros_like_default_c<float>};
@@ -1496,13 +1478,5 @@ void func_map_init_arraycreation(func_map_t& fmap)
14961478
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE][eft_C128][eft_C128] = {
14971479
eft_C128, (void*)dpnp_zeros_like_default_c<std::complex<double>>};
14981480

1499-
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_zeros_like_ext_c<int32_t>};
1500-
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_zeros_like_ext_c<int64_t>};
1501-
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_zeros_like_ext_c<float>};
1502-
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_zeros_like_ext_c<double>};
1503-
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE_EXT][eft_BLN][eft_BLN] = {eft_BLN, (void*)dpnp_zeros_like_ext_c<bool>};
1504-
fmap[DPNPFuncName::DPNP_FN_ZEROS_LIKE_EXT][eft_C128][eft_C128] = {
1505-
eft_C128, (void*)dpnp_zeros_like_ext_c<std::complex<double>>};
1506-
15071481
return;
15081482
}

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
349349
DPNP_FN_VAR
350350
DPNP_FN_VAR_EXT
351351
DPNP_FN_ZEROS
352-
DPNP_FN_ZEROS_EXT
353352
DPNP_FN_ZEROS_LIKE
354-
DPNP_FN_ZEROS_LIKE_EXT
355353

356354
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType": # need this namespace for Enum import
357355
cdef enum DPNPFuncType "DPNPFuncType":

dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ __all__ += [
5151
"dpnp_tril",
5252
"dpnp_triu",
5353
"dpnp_vander",
54-
"dpnp_zeros",
55-
"dpnp_zeros_like"
5654
]
5755

5856

@@ -120,8 +118,7 @@ cpdef utils.dpnp_descriptor dpnp_diag(utils.dpnp_descriptor v, int k):
120118

121119
v_obj = v.get_array()
122120

123-
# TODO need to call dpnp_container.zeros instead
124-
result_obj = dpnp.zeros(result_shape, dtype=v.dtype).to_device(v_obj.sycl_device)
121+
result_obj = dpnp_container.zeros(result_shape, dtype=v.dtype, device=v_obj.sycl_device)
125122
cdef utils.dpnp_descriptor result = dpnp_descriptor(result_obj)
126123

127124
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(v.dtype)
@@ -597,11 +594,3 @@ cpdef utils.dpnp_descriptor dpnp_vander(utils.dpnp_descriptor x1, int N, int inc
597594
c_dpctl.DPCTLEvent_Delete(event_ref)
598595

599596
return result
600-
601-
602-
cpdef utils.dpnp_descriptor dpnp_zeros(result_shape, result_dtype):
603-
return call_fptr_1out(DPNP_FN_ZEROS_EXT, utils._object_to_tuple(result_shape), result_dtype)
604-
605-
606-
cpdef utils.dpnp_descriptor dpnp_zeros_like(result_shape, result_dtype):
607-
return call_fptr_1out(DPNP_FN_ZEROS_LIKE_EXT, utils._object_to_tuple(result_shape), result_dtype)

dpnp/dpnp_container.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"asarray",
4747
"empty",
4848
"full",
49+
"zeros",
4950
]
5051

5152

@@ -86,6 +87,8 @@ def asarray(x1,
8687
x1_obj = x1
8788

8889
sycl_queue_normalized = dpnp.get_normalized_queue_device(x1_obj, device=device, sycl_queue=sycl_queue)
90+
if order is None:
91+
order = 'C'
8992

9093
"""Converts incoming 'x1' object to 'dpnp_array'."""
9194
array_obj = dpt.asarray(x1_obj,
@@ -125,6 +128,8 @@ def full(shape,
125128
"""Validate input parameters before passing them into `dpctl.tensor` module"""
126129
dpu.validate_usm_type(usm_type, allow_none=True)
127130
sycl_queue_normalized = dpnp.get_normalized_queue_device(fill_value, sycl_queue=sycl_queue, device=device)
131+
if order is None:
132+
order = 'C'
128133

129134
if isinstance(fill_value, dpnp_array):
130135
fill_value = fill_value.get_array()
@@ -137,3 +142,25 @@ def full(shape,
137142
usm_type=usm_type,
138143
sycl_queue=sycl_queue_normalized)
139144
return dpnp_array(array_obj.shape, buffer=array_obj, order=order)
145+
146+
147+
def zeros(shape,
148+
*,
149+
dtype=None,
150+
order="C",
151+
device=None,
152+
usm_type="device",
153+
sycl_queue=None):
154+
"""Validate input parameters before passing them into `dpctl.tensor` module"""
155+
dpu.validate_usm_type(usm_type, allow_none=False)
156+
sycl_queue_normalized = dpnp.get_normalized_queue_device(sycl_queue=sycl_queue, device=device)
157+
if order is None:
158+
order = 'C'
159+
160+
"""Creates `dpnp_array` of zeros with the given shape, dtype, and order."""
161+
array_obj = dpt.zeros(shape,
162+
dtype=dtype,
163+
order=order,
164+
usm_type=usm_type,
165+
sycl_queue=sycl_queue_normalized)
166+
return dpnp_array(array_obj.shape, buffer=array_obj, order=order)

dpnp/dpnp_iface_arraycreation.py

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def full(shape,
697697
"""
698698
if like is not None:
699699
pass
700-
elif not isinstance(order, str) or len(order) != 1 or order not in "CcFf":
700+
elif order not in ('C', 'c', 'F', 'f', None):
701701
pass
702702
else:
703703
return dpnp_container.full(shape,
@@ -752,14 +752,14 @@ def full_like(x1,
752752
"""
753753
if not isinstance(x1, dpnp.ndarray):
754754
pass
755-
elif not isinstance(order, str) or len(order) != 1 or order not in "CcFf":
755+
elif order not in ('C', 'c', 'F', 'f', None):
756756
pass
757757
elif subok is not False:
758758
pass
759759
else:
760-
_shape = shape if shape is not None else x1.shape
761-
_dtype = dtype if dtype is not None else x1.dtype
762-
_usm_type = usm_type if usm_type is not None else x1.usm_type
760+
_shape = x1.shape if shape is None else shape
761+
_dtype = x1.dtype if dtype is None else dtype
762+
_usm_type = x1.usm_type if usm_type is None else usm_type
763763
_sycl_queue = dpnp.get_normalized_queue_device(x1, sycl_queue=sycl_queue, device=device)
764764

765765
return dpnp_container.full(_shape,
@@ -1372,15 +1372,24 @@ def vander(x1, N=None, increasing=False):
13721372
return call_origin(numpy.vander, x1, N=N, increasing=increasing)
13731373

13741374

1375-
def zeros(shape, dtype=None, order='C'):
1375+
def zeros(shape,
1376+
*,
1377+
dtype=None,
1378+
order="C",
1379+
like=None,
1380+
device=None,
1381+
usm_type="device",
1382+
sycl_queue=None):
13761383
"""
13771384
Return a new array of given shape and type, filled with zeros.
13781385
13791386
For full documentation refer to :obj:`numpy.zeros`.
13801387
13811388
Limitations
13821389
-----------
1383-
Parameter ``order`` is supported only with default value ``"C"``.
1390+
Parameter ``order`` is supported only with values ``"C"`` and ``"F"``.
1391+
Parameter ``like`` is supported only with default value ``None``.
1392+
Otherwise the function will be executed sequentially on CPU.
13841393
13851394
See Also
13861395
--------
@@ -1401,30 +1410,41 @@ def zeros(shape, dtype=None, order='C'):
14011410
[0.0, 0.0]
14021411
14031412
"""
1413+
if like is not None:
1414+
pass
1415+
elif order not in ('C', 'c', 'F', 'f', None):
1416+
pass
1417+
else:
1418+
return dpnp_container.zeros(shape,
1419+
dtype=dtype,
1420+
order=order,
1421+
device=device,
1422+
usm_type=usm_type,
1423+
sycl_queue=sycl_queue)
14041424

1405-
if (not use_origin_backend()):
1406-
if order not in ('C', 'c', None):
1407-
pass
1408-
else:
1409-
_dtype = dtype if dtype is not None else dpnp.float64
1410-
result = dpnp_zeros(shape, _dtype).get_pyobj()
1411-
1412-
return result
1413-
1414-
return call_origin(numpy.zeros, shape, dtype=dtype, order=order)
1425+
return call_origin(numpy.zeros, shape, dtype=dtype, order=order, like=like)
14151426

14161427

1417-
# numpy.zeros_like(a, dtype=None, order='K', subok=True, shape=None)
1418-
def zeros_like(x1, dtype=None, order='C', subok=False, shape=None):
1428+
def zeros_like(x1,
1429+
*,
1430+
dtype=None,
1431+
order="C",
1432+
subok=False,
1433+
shape=None,
1434+
device=None,
1435+
usm_type=None,
1436+
sycl_queue=None):
14191437
"""
14201438
Return an array of zeros with the same shape and type as a given array.
14211439
14221440
For full documentation refer to :obj:`numpy.zeros_like`.
14231441
14241442
Limitations
14251443
-----------
1426-
Parameter ``order`` is supported only with default value ``"C"``.
1444+
Parameters ``x1`` is supported only as :class:`dpnp.dpnp_array`.
1445+
Parameter ``order`` is supported with values ``"C"`` or ``"F"``.
14271446
Parameter ``subok`` is supported only with default value ``False``.
1447+
Otherwise the function will be executed sequentially on CPU.
14281448
14291449
See Also
14301450
--------
@@ -1442,19 +1462,22 @@ def zeros_like(x1, dtype=None, order='C', subok=False, shape=None):
14421462
>>> [i for i in np.zeros_like(x)]
14431463
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
14441464
1445-
"""
1446-
1447-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
1448-
if x1_desc:
1449-
if order not in ('C', 'c', None):
1450-
pass
1451-
elif subok is not False:
1452-
pass
1453-
else:
1454-
_shape = shape if shape is not None else x1_desc.shape
1455-
_dtype = dtype if dtype is not None else x1_desc.dtype
1456-
result = dpnp_zeros_like(_shape, _dtype).get_pyobj()
1457-
1458-
return result
1465+
"""
1466+
if not isinstance(x1, dpnp.ndarray):
1467+
pass
1468+
elif order not in ('C', 'c', 'F', 'f', None):
1469+
pass
1470+
elif subok is not False:
1471+
pass
1472+
else:
1473+
_shape = x1.shape if shape is None else shape
1474+
_dtype = x1.dtype if dtype is None else dtype
1475+
_usm_type = x1.usm_type if usm_type is None else usm_type
1476+
_sycl_queue = dpnp.get_normalized_queue_device(x1, sycl_queue=sycl_queue, device=device)
1477+
return dpnp_container.zeros(_shape,
1478+
dtype=_dtype,
1479+
order=order,
1480+
usm_type=_usm_type,
1481+
sycl_queue=_sycl_queue)
14591482

14601483
return call_origin(numpy.zeros_like, x1, dtype, order, subok, shape)

dpnp/dpnp_iface_mathematical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def multiply(x1,
10981098
Limitations
10991099
-----------
11001100
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar.
1101-
Parameters ``out``, ``where``, ``dtype`` and ``subok`` are supported with their default values.
1101+
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
11021102
Keyword arguments ``kwargs`` are currently unsupported.
11031103
Otherwise the functions will be executed sequentially on CPU.
11041104
Input array data types are limited by supported DPNP :ref:`Data types`.

tests/skipped_tests.tbl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_int
287287
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like
288288
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity
289289
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_scalar
290-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_zeros_scalar
291290
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape
292291
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity
293292
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_int
463463
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like
464464
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity
465465
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_scalar
466-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_zeros_scalar
467466
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape
468467
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity
469468
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape

0 commit comments

Comments
 (0)