Skip to content

Commit 60b87c0

Browse files
vtavanandgrigorian
authored andcommitted
modification to handle a special case
1 parent be63aaf commit 60b87c0

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

dpctl/tensor/_elementwise_funcs.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@
131131
Default: "K".
132132
Returns:
133133
usm_narray:
134-
An array containing the element-wise inverse cosine, in radians
135-
and in the closed interval `[-pi/2, pi/2]`. The data type
136-
of the returned array is determined by the Type Promotion Rules.
134+
An array containing the element-wise ceiling of input array.
135+
The returned array has the same data type as `x`.
137136
"""
138137

139138
ceil = UnaryElementwiseFunc(
@@ -312,9 +311,8 @@
312311
Default: "K".
313312
Returns:
314313
usm_narray:
315-
An array containing the element-wise floor, in radians
316-
and in the closed interval `[-pi/2, pi/2]`. The data type
317-
of the returned array is determined by the Type Promotion Rules.
314+
An array containing the element-wise floor of input array.
315+
The returned array has the same data type as `x`.
318316
"""
319317

320318
floor = UnaryElementwiseFunc(
@@ -972,9 +970,8 @@
972970
Default: "K".
973971
Returns:
974972
usm_narray:
975-
An array containing the element-wise inverse cosine, in radians
976-
and in the closed interval `[-pi/2, pi/2]`. The data type
977-
of the returned array is determined by the Type Promotion Rules.
973+
An array containing the element-wise truncated value of input array.
974+
The returned array has the same data type as `x`.
978975
"""
979976

980977
trunc = UnaryElementwiseFunc(

dpctl/tensor/libtensor/include/kernels/elementwise_functions/ceil.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ template <typename argT, typename resT> struct CeilFunctor
6969
return in;
7070
}
7171
else {
72-
return sycl::ceil(in);
72+
if (in == 0 && std::signbit(in)) {
73+
return in;
74+
}
75+
return std::ceil(in);
7376
}
7477
}
7578
};

dpctl/tensor/libtensor/include/kernels/elementwise_functions/floor.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ template <typename argT, typename resT> struct FloorFunctor
6969
return in;
7070
}
7171
else {
72-
return sycl::floor(in);
72+
if (in == 0 && std::signbit(in)) {
73+
return in;
74+
}
75+
return std::floor(in);
7376
}
7477
}
7578
};

dpctl/tests/elementwise/test_floor_ceil_trunc.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
import numpy as np
2020
import pytest
21-
from numpy.testing import assert_allclose, assert_raises_regex
21+
from numpy.testing import (
22+
assert_allclose,
23+
assert_array_equal,
24+
assert_raises_regex,
25+
)
2226

2327
import dpctl
2428
import dpctl.tensor as dpt
@@ -196,12 +200,14 @@ def test_floor_ceil_trunc_special_cases(np_call, dpt_call, dtype):
196200
q = get_queue_or_skip()
197201
skip_if_dtype_not_supported(dtype, q)
198202

199-
x = [np.nan, np.inf, -np.inf]
203+
x = [np.nan, np.inf, -np.inf, +0.0, -0.0]
200204

201205
xf = np.array(x, dtype=dtype)
202206
yf = dpt.asarray(xf, dtype=dtype, sycl_queue=q)
203207

204208
Y_np = np_call(xf)
209+
Y = dpt.asnumpy(dpt_call(yf))
205210

206211
tol = 8 * dpt.finfo(dtype).resolution
207-
assert_allclose(dpt.asnumpy(dpt_call(yf)), Y_np, atol=tol, rtol=tol)
212+
assert_allclose(Y, Y_np, atol=tol, rtol=tol)
213+
assert_array_equal(np.signbit(Y), np.signbit(Y_np))

0 commit comments

Comments
 (0)