@@ -27,6 +27,12 @@ using executorch::aten::Tensor;
2727
2828using torch::executor::testing::TensorFactory;
2929
30+ // `arange` steps its vectorized body with a fused multiply-add on some ISAs
31+ // (NEON float does), so an element can come out one ulp from the independently
32+ // rounded literals the cases below compare against. One ulp is the tightest
33+ // bound that holds; the largest deviation measured across them is 0.909 ulp.
34+ constexpr double kArangeUlpRtol = std::numeric_limits<float >::epsilon();
35+
3036class OpArangeOutTest : public OperatorTest {
3137 protected:
3238 Tensor& op_arange_out (const Scalar& end, Tensor& out) {
@@ -285,7 +291,7 @@ TEST_F(OpArangeStartOutTest, StartOut) {
285291 // Expected tensor, equal
286292 Tensor expected = tf.make ({4 }, {1.1 , 2.2 , 3.3 , 4.4 });
287293
288- EXPECT_TENSOR_EQ (out, expected);
294+ EXPECT_TENSOR_CLOSE_WITH_TOL (out, expected, kArangeUlpRtol , 0 );
289295
290296 end = Scalar (5.51 );
291297 out = tf.zeros ({5 });
@@ -298,7 +304,7 @@ TEST_F(OpArangeStartOutTest, StartOut) {
298304 // Expected tensor, equal
299305 expected = tf.make ({5 }, {1.1 , 2.2 , 3.3 , 4.4 , 5.5 });
300306
301- EXPECT_TENSOR_EQ (out, expected);
307+ EXPECT_TENSOR_CLOSE_WITH_TOL (out, expected, kArangeUlpRtol , 0 );
302308}
303309
304310TEST_F (OpArangeStartOutTest, StartOutNegativeStep) {
@@ -318,7 +324,7 @@ TEST_F(OpArangeStartOutTest, StartOutNegativeStep) {
318324 // Expected tensor, equal
319325 Tensor expected = tf.make ({4 }, {5.5 , 4.4 , 3.3 , 2.2 });
320326
321- EXPECT_TENSOR_EQ (out, expected);
327+ EXPECT_TENSOR_CLOSE_WITH_TOL (out, expected, kArangeUlpRtol , 0 );
322328
323329 end = Scalar (1.09 );
324330 out = tf.zeros ({5 });
@@ -331,5 +337,5 @@ TEST_F(OpArangeStartOutTest, StartOutNegativeStep) {
331337 // Expected tensor, equal
332338 expected = tf.make ({5 }, {5.5 , 4.4 , 3.3 , 2.2 , 1.1 });
333339
334- EXPECT_TENSOR_EQ (out, expected);
340+ EXPECT_TENSOR_CLOSE_WITH_TOL (out, expected, kArangeUlpRtol , 0 );
335341}
0 commit comments