Skip to content

Get rid of testing the array creation functions with unsupported types by a default device in positive scenarios #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 33 additions & 2 deletions dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# distutils: language = c++
# -*- 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 @@ -61,6 +61,7 @@
"asnumpy",
"astype",
"convert_single_elem_array_to_scalar",
"default_float_type",
"dpnp_queue_initialize",
"dpnp_queue_is_cpu",
"get_dpnp_descriptor",
Expand All @@ -69,7 +70,8 @@
]

from dpnp import (
isscalar
isscalar,
float64
)

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


def default_float_type(device=None, sycl_queue=None):
"""
Return a floating type used by default in DPNP depending on device capabilities.

Parameters
----------
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where an array of default floating type might be created.
The `device` can be ``None`` (the default), an OneAPI filter selector string,
an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
:obj:`dpnp.dpnp_array.dpnp_array.device` property.
The value ``None`` is interpreted as to use a default device.
sycl_queue : {None, SyclQueue}, optional
A SYCL queue which might be used to create an array of default floating type.
The `sycl_queue` can be ``None`` (the default), which is interpreted as
to get the SYCL queue from `device` keyword if present or to use a default queue.

Returns
-------
dt : dtype
A default DPNP floating type.

"""

_sycl_queue = get_normalized_queue_device(device=device, sycl_queue=sycl_queue)
return map_dtype_to_device(float64, _sycl_queue.sycl_device)


def get_dpnp_descriptor(ext_obj,
copy_when_strides=True,
copy_when_nondefault_queue=True,
Expand Down
12 changes: 4 additions & 8 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,8 @@ def identity(n, dtype=None, *, like=None):
elif n < 0:
pass
else:
if dtype is None:
sycl_queue = dpnp.get_normalized_queue_device(sycl_queue=None, device=None)
dtype = map_dtype_to_device(dpnp.float64, sycl_queue.sycl_device)
return dpnp_identity(n, dtype).get_pyobj()
_dtype = dpnp.default_float_type() if dtype is None else dtype
return dpnp_identity(n, _dtype).get_pyobj()

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

Expand Down Expand Up @@ -1327,10 +1325,8 @@ def tri(N, M=None, k=0, dtype=dpnp.float, **kwargs):
elif not isinstance(k, int):
pass
else:
if dtype is dpnp.float:
sycl_queue = dpnp.get_normalized_queue_device(sycl_queue=None, device=None)
dtype = map_dtype_to_device(dpnp.float64, sycl_queue.sycl_device)
return dpnp_tri(N, M, k, dtype).get_pyobj()
_dtype = dpnp.default_float_type() if dtype in (dpnp.float, None) else dtype
return dpnp_tri(N, M, k, _dtype).get_pyobj()

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

Expand Down
6 changes: 1 addition & 5 deletions dpnp/dpnp_iface_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

import numpy


__all__ = [
"bool",
"bool_",
"complex128",
"complex64",
"default_float_type",
"dtype",
"float",
"float16",
Expand Down Expand Up @@ -75,10 +75,6 @@
longcomplex = numpy.longcomplex


def default_float_type():
return float64


def isscalar(obj):
"""
Returns True if the type of `obj` is a scalar type.
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_utils/dpnp_algo_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def call_origin(function, *args, **kwargs):

exec_q = dpctl.utils.get_execution_queue(alloc_queues)
if exec_q is None:
exec_q = sycl_queue
exec_q = dpnp.get_normalized_queue_device(sycl_queue=sycl_queue)
# 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}")
# TODO need to put array memory into NumPy call
result_origin = function(*args_new, **kwargs_new)
Expand Down
39 changes: 39 additions & 0 deletions tests/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import dpctl
import dpnp


def get_all_dtypes(no_bool=False,
no_float16=True,
no_complex=False,
no_none=False,
device=None):
"""
Build a list of types supported by DPNP based on input flags and device capabilities.
"""

dev = dpctl.select_default_device() if device is None else device

# add boolean type
dtypes = [dpnp.bool] if not no_bool else []

# add integer types
dtypes.extend([dpnp.int32, dpnp.int64])

# add floating types
if not no_float16 and dev.has_aspect_fp16:
dtypes.append(dpnp.float16)

dtypes.append(dpnp.float32)
if dev.has_aspect_fp64:
dtypes.append(dpnp.float64)

# add complex types
if not no_complex:
dtypes.append(dpnp.complex64)
if dev.has_aspect_fp64:
dtypes.append(dpnp.complex128)

# add None value to validate a default dtype
if not no_none:
dtypes.append(None)
return dtypes
Loading