Skip to content

Replaced few TypeError with ValueError in _elementwise_common #1496

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
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
8 changes: 4 additions & 4 deletions dpctl/tensor/_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __call__(self, x, out=None, order="K"):
acceptance_fn=self.acceptance_fn_,
)
if res_dt is None:
raise TypeError(
raise ValueError(
f"function '{self.name_}' does not support input type "
f"({x.dtype}), "
"and the input could not be safely coerced to any "
Expand All @@ -209,7 +209,7 @@ def __call__(self, x, out=None, order="K"):
)

if res_dt != out.dtype:
raise TypeError(
raise ValueError(
f"Output array of type {res_dt} is needed,"
f" got {out.dtype}"
)
Expand Down Expand Up @@ -587,7 +587,7 @@ def __call__(self, o1, o2, out=None, order="K"):
)

if res_dt is None:
raise TypeError(
raise ValueError(
f"function '{self.name_}' does not support input types "
f"({o1_dtype}, {o2_dtype}), "
"and the inputs could not be safely coerced to any "
Expand All @@ -608,7 +608,7 @@ def __call__(self, o1, o2, out=None, order="K"):
)

if res_dt != out.dtype:
raise TypeError(
raise ValueError(
f"Output array of type {res_dt} is needed,"
f"got {out.dtype}"
)
Expand Down
6 changes: 3 additions & 3 deletions dpctl/tests/elementwise/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_add_dtype_error(

y = dpt.zeros_like(ar1, dtype="int8")
assert_raises_regex(
TypeError, "Output array of type.*is needed", dpt.add, ar1, ar2, y
ValueError, "Output array of type.*is needed", dpt.add, ar1, ar2, y
)


Expand Down Expand Up @@ -384,7 +384,7 @@ def test_add_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.asnumpy(ar3) == np.full(ar3.shape, 2, dtype=ar3.dtype)
).all()
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 += ar2
dpt.add(ar1, ar2, out=ar1)

Expand All @@ -404,7 +404,7 @@ def test_add_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.asnumpy(ar4) == np.full(ar4.shape, 2, dtype=ar4.dtype)
).all()
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.add(ar1, ar2, out=ar2)


Expand Down
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_bitwise_and.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_bitwise_and_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 &= ar4
assert dpt.all(ar3 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 &= ar2
dpt.bitwise_and(ar1, ar2, out=ar1)

Expand All @@ -139,5 +139,5 @@ def test_bitwise_and_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.bitwise_and(ar3, ar4, out=ar4)
dpt.all(ar4 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.bitwise_and(ar1, ar2, out=ar2)
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_bitwise_left_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_bitwise_left_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 <<= ar4
assert dpt.all(ar3 == 2)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 <<= ar2
dpt.bitwise_left_shift(ar1, ar2, out=ar1)

Expand All @@ -147,5 +147,5 @@ def test_bitwise_left_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.bitwise_left_shift(ar3, ar4, out=ar4)
dpt.all(ar4 == 2)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.bitwise_left_shift(ar1, ar2, out=ar2)
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_bitwise_or.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_bitwise_or_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 |= ar4
assert dpt.all(ar3 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 |= ar2
dpt.bitwise_or(ar1, ar2, out=ar1)

Expand All @@ -139,5 +139,5 @@ def test_bitwise_or_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.bitwise_or(ar3, ar4, out=ar4)
dpt.all(ar4 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.bitwise_or(ar1, ar2, out=ar2)
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_bitwise_right_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_bitwise_right_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 >>= ar4
assert dpt.all(ar3 == 0)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 >>= ar2
dpt.bitwise_right_shift(ar1, ar2, out=ar1)

Expand All @@ -147,5 +147,5 @@ def test_bitwise_right_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.bitwise_right_shift(ar3, ar4, out=ar4)
dpt.all(ar4 == 0)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.bitwise_right_shift(ar1, ar2, out=ar2)
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_bitwise_xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_bitwise_xor_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 ^= ar4
assert dpt.all(ar3 == 0)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 ^= ar2
dpt.bitwise_xor(ar1, ar2, out=ar1)

Expand All @@ -139,5 +139,5 @@ def test_bitwise_xor_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.bitwise_xor(ar3, ar4, out=ar4)
dpt.all(ar4 == 0)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.bitwise_xor(ar1, ar2, out=ar2)
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 /= ar4
assert dpt.all(ar3 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 /= ar2
dpt.divide(ar1, ar2, out=ar1)

Expand All @@ -254,5 +254,5 @@ def test_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.divide(ar3, ar4, out=ar4)
dpt.all(ar4 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.divide(ar1, ar2, out=ar2)
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_floor_ceil_trunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_floor_ceil_trunc_error_dtype(dpt_call, dtype):
x = dpt.zeros(5, dtype=dtype)
y = dpt.empty_like(x, dtype="b1")
assert_raises_regex(
TypeError, "Output array of type.*is needed", dpt_call, x, y
ValueError, "Output array of type.*is needed", dpt_call, x, y
)


Expand Down
4 changes: 2 additions & 2 deletions dpctl/tests/elementwise/test_floor_divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_floor_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
ar3 //= ar4
assert dpt.all(ar3 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 //= ar2
dpt.floor_divide(ar1, ar2, out=ar1)

Expand All @@ -315,5 +315,5 @@ def test_floor_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
dpt.floor_divide(ar3, ar4, out=ar4)
dpt.all(ar4 == 1)
else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
dpt.floor_divide(ar1, ar2, out=ar2)
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_hyperbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_hyper_error_dtype(callable, dtype):
x = dpt.ones(5, dtype=dtype)
y = dpt.empty_like(x, dtype="int16")
assert_raises_regex(
TypeError, "Output array of type.*is needed", callable, x, y
ValueError, "Output array of type.*is needed", callable, x, y
)


Expand Down
7 changes: 6 additions & 1 deletion dpctl/tests/elementwise/test_logaddexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,10 @@ def test_logaddexp_dtype_error(

y = dpt.zeros_like(ar1, dtype="int8")
assert_raises_regex(
TypeError, "Output array of type.*is needed", dpt.logaddexp, ar1, ar2, y
ValueError,
"Output array of type.*is needed",
dpt.logaddexp,
ar1,
ar2,
y,
)
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_multiply_inplace_dtype_matrix(op1_dtype, op2_dtype):
).all()

else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 *= ar2


Expand Down
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_pow_inplace_dtype_matrix(op1_dtype, op2_dtype):
).all()

else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 **= ar2


Expand Down
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_remainder.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_remainder_inplace_dtype_matrix(op1_dtype, op2_dtype):
assert dpt.all(ar3 == dpt.zeros(ar3.shape, dtype=ar3.dtype))

else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 %= ar2


Expand Down
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_subtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_subtract_inplace_dtype_matrix(op1_dtype, op2_dtype):
assert (dpt.asnumpy(ar3) == np.zeros(ar3.shape, dtype=ar3.dtype)).all()

else:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
ar1 -= ar2


Expand Down
2 changes: 1 addition & 1 deletion dpctl/tests/elementwise/test_trigonometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_trig_error_dtype(callable, dtype):
x = dpt.zeros(5, dtype=dtype)
y = dpt.empty_like(x, dtype="int16")
assert_raises_regex(
TypeError, "Output array of type.*is needed", callable, x, y
ValueError, "Output array of type.*is needed", callable, x, y
)


Expand Down