Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b554b53
remove redundant bitwise function tests
ndgrigorian Sep 10, 2025
c40d116
remove redundant tests in test_complex
ndgrigorian Sep 10, 2025
68f2874
remove redundant copysign tests
ndgrigorian Sep 10, 2025
abc795e
remove redundant tests for comparison functions
ndgrigorian Sep 10, 2025
bb14f36
remove redundant divide tests
ndgrigorian Sep 10, 2025
e9b1473
remove unnecessary tests related to exponential and logarithm functions
ndgrigorian Sep 10, 2025
defe0c6
remove redundant atan2 tests
ndgrigorian Sep 10, 2025
137340e
remove unnecessary cbrt test
ndgrigorian Sep 10, 2025
ea1a091
remove unnecessary trig tests
ndgrigorian Sep 10, 2025
a9358d0
remove unnecessary hypot tests
ndgrigorian Sep 10, 2025
e1d1699
remove unnecessary rounding function tests
ndgrigorian Sep 10, 2025
425faa4
remove unnecessary floor divide tests
ndgrigorian Sep 10, 2025
f2c1d1a
remove some redundant tests for logic functions
ndgrigorian Sep 10, 2025
1592ed1
remove unnecessary minimum and maximum tests
ndgrigorian Sep 10, 2025
80bf8aa
remove redundant tests for positive and negative
ndgrigorian Sep 10, 2025
b1ab705
remove redundant tests for pow
ndgrigorian Sep 10, 2025
f37578c
remove redundant tests for reciprocal
ndgrigorian Sep 10, 2025
66a97cb
remove redundant remainder tests
ndgrigorian Sep 10, 2025
85b0f4c
remove redundant rsqrt tests
ndgrigorian Sep 10, 2025
ab136a5
remove redundant sign function tests
ndgrigorian Sep 10, 2025
e8a49f8
remove redundant square and sqrt tests
ndgrigorian Sep 10, 2025
830ccf0
remove redundant subtract tests
ndgrigorian Sep 10, 2025
0152114
remove redundant tests from floating point classifying functions
ndgrigorian Sep 10, 2025
9326b06
remove redundant tests for multiply
ndgrigorian Sep 10, 2025
4a0c17b
remove redundant tests for nextafter
ndgrigorian Sep 10, 2025
6d24b36
remove steps running elementwise tests under gdb
ndgrigorian Sep 10, 2025
586148e
add back usm_type tests in simplified framework
ndgrigorian Sep 16, 2025
63f8c0c
improve coverage of out keyword for unary functions
ndgrigorian Sep 17, 2025
d97f840
add back test_divide_python_scalar
ndgrigorian Sep 17, 2025
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
9 changes: 0 additions & 9 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,6 @@ jobs:
. $CONDA/etc/profile.d/conda.sh
conda activate ${{ env.TEST_ENV_NAME }}
python -c "import dpctl; dpctl.lsplatform(verbosity=2)"
- name: Install gdb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful in the future, when we will need to debug some test.
Would it be better to comment instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured we'd just write it back in later if it becomes necessary again, we could just comment though

run: |
sudo apt-get update --fix-missing
sudo apt-get install -y gdb
- name: Run test_elementwise under gdb
run: |
. $CONDA/etc/profile.d/conda.sh
conda activate ${{ env.TEST_ENV_NAME }}
gdb --batch -ex r -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex bt --args ${CONDA_PREFIX}/bin/python -m pytest -q -ra --disable-warnings --pyargs dpctl.tests.elementwise.test_trigonometric::test_trig_order -vv || true
- name: Create test temp dir
# create temporary empty folder to runs tests from
# https://github.com/pytest-dev/pytest/issues/11904
Expand Down
64 changes: 44 additions & 20 deletions dpctl/tests/elementwise/test_abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
# limitations under the License.

import itertools
import re
import warnings

import numpy as np
import pytest

import dpctl
import dpctl.tensor as dpt
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported

from .utils import _all_dtypes, _complex_fp_dtypes, _real_fp_dtypes, _usm_types
from .utils import _all_dtypes, _complex_fp_dtypes, _real_fp_dtypes


@pytest.mark.parametrize("dtype", _all_dtypes)
Expand Down Expand Up @@ -51,25 +53,6 @@ def test_abs_out_type(dtype):
assert np.allclose(dpt.asnumpy(r), dpt.asnumpy(dpt.abs(X)))


@pytest.mark.parametrize("usm_type", _usm_types)
def test_abs_usm_type(usm_type):
q = get_queue_or_skip()

arg_dt = np.dtype("i4")
input_shape = (10, 10, 10, 10)
X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q)
X[..., 0::2] = 1
X[..., 1::2] = 0

Y = dpt.abs(X)
assert Y.usm_type == X.usm_type
assert Y.sycl_queue == X.sycl_queue
assert Y.flags.c_contiguous

expected_Y = dpt.asnumpy(X)
assert np.allclose(dpt.asnumpy(Y), expected_Y)


def test_abs_types_property():
get_queue_or_skip()
types = dpt.abs.types
Expand Down Expand Up @@ -202,3 +185,44 @@ def test_abs_alignment(dtype):

dpt.abs(x[:-1], out=r[1:])
assert np.allclose(dpt.asnumpy(r[1:]), dpt.asnumpy(r2))


def test_abs_errors():
q1 = get_queue_or_skip()
q2 = dpctl.SyclQueue()

x = dpt.ones(2, dtype="float32", sycl_queue=q1)
y = dpt.empty_like(x, sycl_queue=q2)
with pytest.raises(dpctl.utils.ExecutionPlacementError) as excinfo:
dpt.abs(x, out=y)
assert "Input and output allocation queues are not compatible" in str(
excinfo.value
)

x = dpt.ones(2, dtype="float32")
y = dpt.empty(3, dtype=x.dtype)
with pytest.raises(ValueError) as excinfo:
dpt.abs(x, out=y)
assert "The shape of input and output arrays are inconsistent" in str(
excinfo.value
)

x = np.ones(2, dtype="float32")
with pytest.raises(TypeError) as excinfo:
dpt.abs(x)
assert re.match(
"Expected dpctl.tensor.usm_ndarray, got.*",
str(excinfo.value),
)

x = dpt.ones(2, dtype="float32")
y = np.empty(x.shape, dtype=x.dtype)
with pytest.raises(TypeError) as excinfo:
dpt.abs(x, out=y)
assert "output array must be of usm_ndarray type" in str(excinfo.value)

x = dpt.ones(5, dtype="f4")
y = dpt.zeros_like(x, dtype="int8")
with pytest.raises(ValueError) as excinfo:
dpt.abs(x, out=y)
assert re.match("Output array of type.*is needed", str(excinfo.value))
66 changes: 13 additions & 53 deletions dpctl/tests/elementwise/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
from dpctl.utils import ExecutionPlacementError

from .utils import _all_dtypes, _compare_dtypes, _usm_types
from .utils import _all_dtypes, _compare_dtypes


@pytest.mark.parametrize("op1_dtype", _all_dtypes)
Expand Down Expand Up @@ -71,23 +71,6 @@ def test_add_dtype_matrix(op1_dtype, op2_dtype):
assert (dpt.asnumpy(r2) == np.full(r2.shape, 2, dtype=r2.dtype)).all()


@pytest.mark.parametrize("op1_usm_type", _usm_types)
@pytest.mark.parametrize("op2_usm_type", _usm_types)
def test_add_usm_type_matrix(op1_usm_type, op2_usm_type):
get_queue_or_skip()

sz = 128
ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type)
ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type)

r = dpt.add(ar1, ar2)
assert isinstance(r, dpt.usm_ndarray)
expected_usm_type = dpctl.utils.get_coerced_usm_type(
(op1_usm_type, op2_usm_type)
)
assert r.usm_type == expected_usm_type


def test_add_order():
get_queue_or_skip()

Expand Down Expand Up @@ -267,19 +250,12 @@ def test_add_types_property():


def test_add_errors():
get_queue_or_skip()
try:
gpu_queue = dpctl.SyclQueue("gpu")
except dpctl.SyclQueueCreationError:
pytest.skip("SyclQueue('gpu') failed, skipping")
try:
cpu_queue = dpctl.SyclQueue("cpu")
except dpctl.SyclQueueCreationError:
pytest.skip("SyclQueue('cpu') failed, skipping")

ar1 = dpt.ones(2, dtype="float32", sycl_queue=gpu_queue)
ar2 = dpt.ones_like(ar1, sycl_queue=gpu_queue)
y = dpt.empty_like(ar1, sycl_queue=cpu_queue)
q1 = get_queue_or_skip()
q2 = dpctl.SyclQueue()

ar1 = dpt.ones(2, dtype="float32", sycl_queue=q1)
ar2 = dpt.ones_like(ar1, sycl_queue=q1)
y = dpt.empty_like(ar1, sycl_queue=q2)
with pytest.raises(ExecutionPlacementError) as excinfo:
dpt.add(ar1, ar2, out=y)
assert "Input and output allocation queues are not compatible" in str(
Expand Down Expand Up @@ -311,17 +287,8 @@ def test_add_errors():
dpt.add(ar1, ar2, out=y)
assert "output array must be of usm_ndarray type" in str(excinfo.value)


@pytest.mark.parametrize("dtype", _all_dtypes)
def test_add_dtype_error(
dtype,
):
q = get_queue_or_skip()
skip_if_dtype_not_supported(dtype, q)

ar1 = dpt.ones(5, dtype=dtype)
ar1 = dpt.ones(5, dtype="f4")
ar2 = dpt.ones_like(ar1, dtype="f4")

y = dpt.zeros_like(ar1, dtype="int8")
with pytest.raises(ValueError) as excinfo:
dpt.add(ar1, ar2, out=y)
Expand Down Expand Up @@ -453,18 +420,11 @@ def test_add_inplace_operator_mutual_broadcast():


def test_add_inplace_errors():
get_queue_or_skip()
try:
gpu_queue = dpctl.SyclQueue("gpu")
except dpctl.SyclQueueCreationError:
pytest.skip("SyclQueue('gpu') failed, skipping")
try:
cpu_queue = dpctl.SyclQueue("cpu")
except dpctl.SyclQueueCreationError:
pytest.skip("SyclQueue('cpu') failed, skipping")

ar1 = dpt.ones(2, dtype="float32", sycl_queue=gpu_queue)
ar2 = dpt.ones_like(ar1, sycl_queue=cpu_queue)
q1 = get_queue_or_skip()
q2 = dpctl.SyclQueue()

ar1 = dpt.ones(2, dtype="float32", sycl_queue=q1)
ar2 = dpt.ones_like(ar1, sycl_queue=q2)
with pytest.raises(ExecutionPlacementError):
dpt.add(ar1, ar2, out=ar1)

Expand Down
24 changes: 1 addition & 23 deletions dpctl/tests/elementwise/test_atan2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import ctypes

import numpy as np
import pytest
from numpy.testing import assert_allclose
Expand Down Expand Up @@ -68,26 +66,6 @@ def test_atan2_dtype_matrix(op1_dtype, op2_dtype):
assert_allclose(dpt.asnumpy(r), expected, atol=tol, rtol=tol)


@pytest.mark.parametrize("arr_dt", _no_complex_dtypes[1:])
def test_atan2_python_scalar(arr_dt):
q = get_queue_or_skip()
skip_if_dtype_not_supported(arr_dt, q)

X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q)
py_ones = (
bool(1),
int(1),
float(1),
np.float32(1),
ctypes.c_int(1),
)
for sc in py_ones:
R = dpt.atan2(X, sc)
assert isinstance(R, dpt.usm_ndarray)
R = dpt.atan2(sc, X)
assert isinstance(R, dpt.usm_ndarray)


@pytest.mark.parametrize("dt", ["f2", "f4", "f8"])
def test_atan2_special_case_one_nan(dt):
"""If either x1_i or x2_i is NaN, the result is NaN."""
Expand Down Expand Up @@ -194,7 +172,7 @@ def test_atan2_special_case_pzero_and_nzero(dt):


@pytest.mark.parametrize("dt", ["f2", "f4", "f8"])
def test_atan2_special_case_pzero_and_negatvie(dt):
def test_atan2_special_case_pzero_and_negative(dt):
"""
If x1_i is +0 and x2_i is less than 0, the result
is an approximation to +pi.
Expand Down
40 changes: 1 addition & 39 deletions dpctl/tests/elementwise/test_bitwise_and.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@pytest.mark.parametrize("op_dtype", _integral_dtypes)
def test_bitwise_and_dtype_matrix_contig(op_dtype):
def test_bitwise_and_dtype_matrix(op_dtype):
q = get_queue_or_skip()
skip_if_dtype_not_supported(op_dtype, q)

Expand All @@ -50,32 +50,6 @@ def test_bitwise_and_dtype_matrix_contig(op_dtype):
assert (r_np == dpt.asnumpy(r)).all()


@pytest.mark.parametrize("op_dtype", _integral_dtypes)
def test_bitwise_and_dtype_matrix_strided(op_dtype):
q = get_queue_or_skip()
skip_if_dtype_not_supported(op_dtype, q)

sz = 11
n = 2 * sz
dt1 = dpt.dtype(op_dtype)
dt2 = dpt.dtype(op_dtype)

x1_range_begin = -sz if dpt.iinfo(dt1).min < 0 else 0
x1 = dpt.arange(x1_range_begin, x1_range_begin + n, dtype=dt1)[::2]

x2_range_begin = -(sz // 2) if dpt.iinfo(dt2).min < 0 else 0
x2 = dpt.arange(x2_range_begin, x2_range_begin + n, dtype=dt1)[::-2]

r = dpt.bitwise_and(x1, x2)
assert isinstance(r, dpt.usm_ndarray)

x1_np = np.arange(x1_range_begin, x1_range_begin + n, dtype=op_dtype)[::2]
x2_np = np.arange(x2_range_begin, x2_range_begin + n, dtype=op_dtype)[::-2]
r_np = np.bitwise_and(x1_np, x2_np)

assert (r_np == dpt.asnumpy(r)).all()


def test_bitwise_and_bool():
get_queue_or_skip()

Expand All @@ -88,18 +62,6 @@ def test_bitwise_and_bool():
assert dpt.all(dpt.equal(r_bw, r_lo))


@pytest.mark.parametrize("dtype", ["?"] + _integral_dtypes)
def test_bitwise_and_inplace_python_scalar(dtype):
q = get_queue_or_skip()
skip_if_dtype_not_supported(dtype, q)
X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q)
dt_kind = X.dtype.kind
if dt_kind == "b":
X &= False
else:
X &= int(0)


@pytest.mark.parametrize("op1_dtype", ["?"] + _integral_dtypes)
@pytest.mark.parametrize("op2_dtype", ["?"] + _integral_dtypes)
def test_bitwise_and_inplace_dtype_matrix(op1_dtype, op2_dtype):
Expand Down
48 changes: 1 addition & 47 deletions dpctl/tests/elementwise/test_bitwise_invert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import dpctl.tensor as dpt
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported

from .utils import _compare_dtypes, _integral_dtypes, _usm_types
from .utils import _compare_dtypes, _integral_dtypes


@pytest.mark.parametrize(
Expand Down Expand Up @@ -73,52 +73,6 @@ def test_bitwise_invert_dtype_matrix(op_dtype):
assert dpt.all(dpt.equal(r, r3))


@pytest.mark.parametrize("op_usm_type", _usm_types)
def test_bitwise_invert_usm_type_matrix(op_usm_type):
get_queue_or_skip()

sz = 128
ar1 = dpt.asarray(
np.random.randint(0, 2, sz), dtype="i4", usm_type=op_usm_type
)

r = dpt.bitwise_invert(ar1)
assert isinstance(r, dpt.usm_ndarray)
assert r.usm_type == op_usm_type


def test_bitwise_invert_order():
get_queue_or_skip()

ar1 = dpt.ones((20, 20), dtype="i4", order="C")
r1 = dpt.bitwise_invert(ar1, order="C")
assert r1.flags.c_contiguous
r2 = dpt.bitwise_invert(ar1, order="F")
assert r2.flags.f_contiguous
r3 = dpt.bitwise_invert(ar1, order="A")
assert r3.flags.c_contiguous
r4 = dpt.bitwise_invert(ar1, order="K")
assert r4.flags.c_contiguous

ar1 = dpt.zeros((20, 20), dtype="i4", order="F")
r1 = dpt.bitwise_invert(ar1, order="C")
assert r1.flags.c_contiguous
r2 = dpt.bitwise_invert(ar1, order="F")
assert r2.flags.f_contiguous
r3 = dpt.bitwise_invert(ar1, order="A")
assert r3.flags.f_contiguous
r4 = dpt.bitwise_invert(ar1, order="K")
assert r4.flags.f_contiguous

ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2]
r4 = dpt.bitwise_invert(ar1, order="K")
assert r4.strides == (20, -1)

ar1 = dpt.zeros((40, 40), dtype="i4", order="C")[:20, ::-2].mT
r4 = dpt.bitwise_invert(ar1, order="K")
assert r4.strides == (-1, 20)


def test_bitwise_invert_large_boolean():
get_queue_or_skip()

Expand Down
Loading
Loading