Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request #51711 from yongtang:46899-tf.range
PiperOrigin-RevId: 393844345
Change-Id: I2a72193d4416b8b009bc0b21489a42061f164203
  • Loading branch information
tensorflower-gardener committed Aug 30, 2021
2 parents 2adc043 + 8ad2e07 commit 1b0e0ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tensorflow/core/kernels/sequence_ops.cc
Expand Up @@ -78,9 +78,10 @@ class RangeOp : public OpKernel {
} else {
size = static_cast<int64>(std::ceil(std::abs((limit - start) / delta)));
}
TensorShape shape;
OP_REQUIRES_OK(context, shape.AddDimWithStatus(size));
Tensor* out = nullptr;
OP_REQUIRES_OK(context,
context->allocate_output(0, TensorShape({size}), &out));
OP_REQUIRES_OK(context, context->allocate_output(0, shape, &out));
auto flat = out->flat<T>();
T val = start;
for (int64_t i = 0; i < size; ++i) {
Expand Down
7 changes: 7 additions & 0 deletions tensorflow/python/kernel_tests/init_ops_test.py
Expand Up @@ -550,6 +550,13 @@ def testLargeLimits(self):
v = math_ops.range(0, 9223372036854775807)
self.evaluate(v)

def testLargeStarts(self):
# Test case for GitHub issue 46899.
with self.session():
with self.assertRaises(errors_impl.InternalError):
v = math_ops.range(start=-1e+38, limit=1)
self.evaluate(v)


# TODO(vrv): move to sequence_ops_test?
class LinSpaceTest(test.TestCase):
Expand Down

0 comments on commit 1b0e0ec

Please sign in to comment.