|
4 | 4 | #include <executorch/runtime/core/exec_aten/exec_aten.h> |
5 | 5 | #include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h> |
6 | 6 | #include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h> |
7 | | - |
8 | 7 | #include <gtest/gtest.h> |
| 8 | +#include <limits> |
9 | 9 |
|
10 | 10 | using namespace ::testing; |
11 | 11 | using executorch::aten::Scalar; |
@@ -78,6 +78,21 @@ TEST_F(OpBucketizeScalarTest, ScalarEmptyBoundaries) { |
78 | 78 | EXPECT_TENSOR_EQ(out, expected); |
79 | 79 | } |
80 | 80 |
|
| 81 | +TEST_F(OpBucketizeScalarTest, ScalarInfInput) { |
| 82 | + TensorFactory<ScalarType::Long> tf_out; |
| 83 | + TensorFactory<ScalarType::Int> tf_bound; |
| 84 | + |
| 85 | + Scalar value = std::numeric_limits<float>::infinity(); |
| 86 | + Tensor boundaries = tf_bound.make({5}, {0, 2, 4, 6, 8}); |
| 87 | + Tensor expected = tf_out.make({}, {5}); |
| 88 | + Tensor out = tf_out.zeros({}); |
| 89 | + |
| 90 | + Tensor ret = op_bucketize_out(value, boundaries, false, true, out); |
| 91 | + |
| 92 | + EXPECT_TENSOR_EQ(ret, expected); |
| 93 | + EXPECT_TENSOR_EQ(out, expected); |
| 94 | +} |
| 95 | + |
81 | 96 | TEST_F(OpBucketizeScalarTest, ScalarBoundaryTypes) { |
82 | 97 | test_bucketize_bound_types(); |
83 | 98 | } |
@@ -327,6 +342,42 @@ TEST_F(OpBucketizeTest, EmptyAll) { |
327 | 342 | EXPECT_TENSOR_EQ(out, expected); |
328 | 343 | } |
329 | 344 |
|
| 345 | +TEST_F(OpBucketizeTest, InfInput) { |
| 346 | + TensorFactory<ScalarType::Long> tf_out; |
| 347 | + TensorFactory<ScalarType::Float> tf_dtype; |
| 348 | + |
| 349 | + Tensor values = tf_dtype.make( |
| 350 | + {2}, |
| 351 | + {-std::numeric_limits<float>::infinity(), |
| 352 | + std::numeric_limits<float>::infinity()}); |
| 353 | + Tensor boundaries = tf_dtype.make({5}, {0, 3, 5, 7, 9}); |
| 354 | + Tensor expected = tf_out.make({2}, {0, 5}); |
| 355 | + Tensor out = tf_out.zeros({2}); |
| 356 | + |
| 357 | + Tensor ret = op_bucketize_out(values, boundaries, false, true, out); |
| 358 | + |
| 359 | + EXPECT_TENSOR_EQ(ret, expected); |
| 360 | + EXPECT_TENSOR_EQ(out, expected); |
| 361 | +} |
| 362 | + |
| 363 | +TEST_F(OpBucketizeTest, InfBoundaries) { |
| 364 | + TensorFactory<ScalarType::Long> tf_out; |
| 365 | + TensorFactory<ScalarType::Float> tf_dtype; |
| 366 | + |
| 367 | + Tensor values = tf_dtype.make({2, 2}, {1, 4, 6, 8}); |
| 368 | + Tensor boundaries = tf_dtype.make( |
| 369 | + {2}, |
| 370 | + {-std::numeric_limits<float>::infinity(), |
| 371 | + std::numeric_limits<float>::infinity()}); |
| 372 | + Tensor expected = tf_out.ones({2, 2}); |
| 373 | + Tensor out = tf_out.zeros({2, 2}); |
| 374 | + |
| 375 | + Tensor ret = op_bucketize_out(values, boundaries, false, true, out); |
| 376 | + |
| 377 | + EXPECT_TENSOR_EQ(ret, expected); |
| 378 | + EXPECT_TENSOR_EQ(out, expected); |
| 379 | +} |
| 380 | + |
330 | 381 | TEST_F(OpBucketizeTest, BoundariesNDFails) { |
331 | 382 | TensorFactory<ScalarType::Long> tf_out; |
332 | 383 | TensorFactory<ScalarType::Float> tf_dtype; |
|
0 commit comments