Skip to content

Commit a32911d

Browse files
committed
Get rid of unsupported types in array creation tests
1 parent 20defc5 commit a32911d

File tree

6 files changed

+137
-258
lines changed

6 files changed

+137
-258
lines changed

dpnp/dpnp_iface.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# distutils: language = c++
33
# -*- coding: utf-8 -*-
44
# *****************************************************************************
5-
# Copyright (c) 2016-2022, Intel Corporation
5+
# Copyright (c) 2016-2023, Intel Corporation
66
# All rights reserved.
77
#
88
# Redistribution and use in source and binary forms, with or without
@@ -61,6 +61,7 @@
6161
"asnumpy",
6262
"astype",
6363
"convert_single_elem_array_to_scalar",
64+
"default_float_type",
6465
"dpnp_queue_initialize",
6566
"dpnp_queue_is_cpu",
6667
"get_dpnp_descriptor",
@@ -69,7 +70,8 @@
6970
]
7071

7172
from dpnp import (
72-
isscalar
73+
isscalar,
74+
float64
7375
)
7476

7577
from dpnp.dpnp_iface_arraycreation import *
@@ -191,6 +193,35 @@ def convert_single_elem_array_to_scalar(obj, keepdims=False):
191193
return obj
192194

193195

196+
def default_float_type(device=None, sycl_queue=None):
197+
"""
198+
Return a floating type used by default in DPNP depending on device capabilities.
199+
200+
Parameters
201+
----------
202+
device : {None, string, SyclDevice, SyclQueue}, optional
203+
An array API concept of device where an array of default floating type might be created.
204+
The `device` can be ``None`` (the default), an OneAPI filter selector string,
205+
an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
206+
an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
207+
:obj:`dpnp.dpnp_array.dpnp_array.device` property.
208+
The value ``None`` is interpreted as to use a default device.
209+
sycl_queue : {None, SyclQueue}, optional
210+
A SYCL queue which might be used to create an array of default floating type.
211+
The `sycl_queue` can be ``None`` (the default), which is interpreted as
212+
to get the SYCL queue from `device` keyword if present or to use a default queue.
213+
214+
Returns
215+
-------
216+
dt : dtype
217+
A default DPNP floating type.
218+
219+
"""
220+
221+
_sycl_queue = get_normalized_queue_device(device=device, sycl_queue=sycl_queue)
222+
return map_dtype_to_device(float64, _sycl_queue.sycl_device)
223+
224+
194225
def get_dpnp_descriptor(ext_obj,
195226
copy_when_strides=True,
196227
copy_when_nondefault_queue=True,

dpnp/dpnp_iface_arraycreation.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,8 @@ def identity(n, dtype=None, *, like=None):
871871
elif n < 0:
872872
pass
873873
else:
874-
if dtype is None:
875-
sycl_queue = dpnp.get_normalized_queue_device(sycl_queue=None, device=None)
876-
dtype = map_dtype_to_device(dpnp.float64, sycl_queue.sycl_device)
877-
return dpnp_identity(n, dtype).get_pyobj()
874+
_dtype = dpnp.default_float_type() if dtype is None else dtype
875+
return dpnp_identity(n, _dtype).get_pyobj()
878876

879877
return call_origin(numpy.identity, n, dtype=dtype, like=like)
880878

@@ -1327,10 +1325,8 @@ def tri(N, M=None, k=0, dtype=dpnp.float, **kwargs):
13271325
elif not isinstance(k, int):
13281326
pass
13291327
else:
1330-
if dtype is dpnp.float:
1331-
sycl_queue = dpnp.get_normalized_queue_device(sycl_queue=None, device=None)
1332-
dtype = map_dtype_to_device(dpnp.float64, sycl_queue.sycl_device)
1333-
return dpnp_tri(N, M, k, dtype).get_pyobj()
1328+
_dtype = dpnp.default_float_type() if dtype in (dpnp.float, None) else dtype
1329+
return dpnp_tri(N, M, k, _dtype).get_pyobj()
13341330

13351331
return call_origin(numpy.tri, N, M, k, dtype, **kwargs)
13361332

dpnp/dpnp_iface_types.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636

3737
import numpy
3838

39+
3940
__all__ = [
4041
"bool",
4142
"bool_",
4243
"complex128",
4344
"complex64",
44-
"default_float_type",
4545
"dtype",
4646
"float",
4747
"float16",
@@ -75,10 +75,6 @@
7575
longcomplex = numpy.longcomplex
7676

7777

78-
def default_float_type():
79-
return float64
80-
81-
8278
def isscalar(obj):
8379
"""
8480
Returns True if the type of `obj` is a scalar type.

dpnp/dpnp_utils/dpnp_algo_utils.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def call_origin(function, *args, **kwargs):
165165

166166
exec_q = dpctl.utils.get_execution_queue(alloc_queues)
167167
if exec_q is None:
168-
exec_q = sycl_queue
168+
exec_q = dpnp.get_normalized_queue_device(sycl_queue=sycl_queue)
169169
# print(f"DPNP call_origin(): bakend called. \n\t function={function}, \n\t args_new={args_new}, \n\t kwargs_new={kwargs_new}, \n\t dpnp_inplace={dpnp_inplace}")
170170
# TODO need to put array memory into NumPy call
171171
result_origin = function(*args_new, **kwargs_new)

tests/helper.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import dpctl
2+
import dpnp
3+
4+
5+
def get_all_dtypes(no_bool=False,
6+
no_float16=True,
7+
no_complex=False,
8+
no_none=False,
9+
device=None):
10+
"""
11+
Build a list of types supported by DPNP based on input flags and device capabilities.
12+
"""
13+
14+
dev = dpctl.select_default_device() if device is None else device
15+
16+
# add boolean type
17+
dtypes = [dpnp.bool] if not no_bool else []
18+
19+
# add integer types
20+
dtypes.extend([dpnp.int32, dpnp.int64])
21+
22+
# add floating types
23+
if not no_float16 and dev.has_aspect_fp16:
24+
dtypes.append(dpnp.float16)
25+
26+
dtypes.append(dpnp.float32)
27+
if dev.has_aspect_fp64:
28+
dtypes.append(dpnp.float64)
29+
30+
# add complex types
31+
if not no_complex:
32+
dtypes.append(dpnp.complex64)
33+
if dev.has_aspect_fp64:
34+
dtypes.append(dpnp.complex128)
35+
36+
# add None value to validate a default dtype
37+
if not no_none:
38+
dtypes.append(None)
39+
return dtypes

0 commit comments

Comments
 (0)