Skip to content

Backport gh1874 #1904

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 5 commits into from
Nov 21, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.18.2] - Nov. XX, 2024

### Fixed
* Fix for `tensor.result_type` when all inputs are Python built-in scalars [gh-1904](https://github.com/IntelPython/dpctl/pull/1904)

## [0.18.1] - Oct. 11, 2024

### Changed
Expand Down
3 changes: 3 additions & 0 deletions dpctl/tensor/_type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ def result_type(*arrays_and_dtypes):
target_dev = d
inspected = True

if not dtypes and weak_dtypes:
dtypes.append(weak_dtypes[0].get())

if not (has_fp16 and has_fp64):
for dt in dtypes:
if not _dtype_supported_by_device_impl(dt, has_fp16, has_fp64):
Expand Down
25 changes: 25 additions & 0 deletions dpctl/tests/test_usm_ndarray_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.


import itertools

import numpy as np
import pytest
from numpy.testing import assert_, assert_array_equal, assert_raises_regex
Expand Down Expand Up @@ -1531,3 +1533,26 @@ def test_repeat_0_size():
res = dpt.repeat(x, repetitions, axis=1)
axis_sz = 2 * x.shape[1]
assert res.shape == (0, axis_sz, 0)


def test_result_type_bug_1874():
py_sc = True
np_sc = np.asarray([py_sc])[0]
dts_bool = [py_sc, np_sc]
py_sc = int(1)
np_sc = np.asarray([py_sc])[0]
dts_ints = [py_sc, np_sc]
dts_floats = [float(1), np.float64(1)]
dts_complexes = [complex(1), np.complex128(1)]

# iterate over two categories
for dts1, dts2 in itertools.product(
[dts_bool, dts_ints, dts_floats, dts_complexes], repeat=2
):
res_dts = []
# iterate over Python scalar/NumPy scalar choices within categories
for dt1, dt2 in itertools.product(dts1, dts2):
res_dt = dpt.result_type(dt1, dt2)
res_dts.append(res_dt)
# check that all results are the same
assert res_dts and all(res_dts[0] == el for el in res_dts[1:])
Loading