提交 cc7f05f6 编写于 作者: A A. Unique TensorFlower 提交者: TensorFlower Gardener

Restrict the use of OUT_OF_RANGE to what it was intended to.

Clarify that OUT_OF_RANGE is raised only when reaching the end of
input for interable contents.

Change the few places where we incorrectly raised OUT_OF_RANGE to raise
ILLEGAL_ARGUMENT instead.

This will make code that catches the OUT_OF_RANGE exception more robust
as it won't get confused by spurious uses of the exception class.
Change: 119560848
上级 6e8e7cac
......@@ -678,8 +678,8 @@ Status FunctionCallFrame::GetRetvals(std::vector<Tensor>* rets) const {
Status FunctionCallFrame::GetArg(int index, Tensor* val) const {
if (index < 0 || static_cast<size_t>(index) >= args_.size()) {
return errors::OutOfRange("GetArg ", index, " is not within [0, ",
args_.size(), ")");
return errors::InvalidArgument("GetArg ", index, " is not within [0, ",
args_.size(), ")");
}
*val = args_[index];
return Status::OK();
......@@ -687,8 +687,8 @@ Status FunctionCallFrame::GetArg(int index, Tensor* val) const {
Status FunctionCallFrame::SetRetval(int index, const Tensor& val) {
if (index < 0 || static_cast<size_t>(index) >= rets_.size()) {
return errors::OutOfRange("SetRetval ", index, " is not within [0, ",
rets_.size(), ")");
return errors::InvalidArgument("SetRetval ", index, " is not within [0, ",
rets_.size(), ")");
}
if (val.dtype() != ret_types_[index]) {
return errors::InvalidArgument(
......
......@@ -563,8 +563,8 @@ TEST(FunctionCallFrame, Void_Void) {
auto a = test::AsTensor<float>({100});
HasError(frame.SetArgs({a}), "Invalid argument");
Tensor v;
HasError(frame.GetArg(0, &v), "Out of range");
HasError(frame.SetRetval(0, v), "Out of range");
HasError(frame.GetArg(0, &v), "Invalid argument");
HasError(frame.SetRetval(0, v), "Invalid argument");
std::vector<Tensor> rets;
TF_EXPECT_OK(frame.GetRetvals(&rets));
EXPECT_EQ(rets.size(), 0);
......@@ -581,16 +581,16 @@ TEST(FunctionCallFrame, Float_Float_Float) {
TF_EXPECT_OK(frame.SetArgs({a, b}));
Tensor v;
HasError(frame.GetArg(-1, &v), "Out of range");
HasError(frame.GetArg(2, &v), "Out of range");
HasError(frame.GetArg(-1, &v), "Invalid argument");
HasError(frame.GetArg(2, &v), "Invalid argument");
TF_EXPECT_OK(frame.GetArg(0, &v));
test::ExpectTensorEqual<float>(a, v);
TF_EXPECT_OK(frame.GetArg(1, &v));
test::ExpectTensorEqual<float>(b, v);
v = test::AsTensor<float>({-100});
HasError(frame.SetRetval(-1, v), "Out of range");
HasError(frame.SetRetval(1, v), "Out of range");
HasError(frame.SetRetval(-1, v), "Invalid argument");
HasError(frame.SetRetval(1, v), "Invalid argument");
HasError(frame.SetRetval(0, test::AsTensor<int64>({-100})),
"Invalid argument: Expects ret[0] to be float");
......
......@@ -99,7 +99,7 @@ class BinaryElementWiseOp : public BinaryOp<T> {
#undef NDIM_CASE
default:
context->SetStatus(errors::OutOfRange(
context->SetStatus(errors::InvalidArgument(
"We only handle up to Tensor::dims() up to 8, not ", a.dims()));
break;
}
......
......@@ -73,7 +73,7 @@ class ListDiffOp : public OpKernel {
for (int i = 0, p = 0; i < x_size; ++i) {
if (y_set.count(Tx(i)) == 0) {
OP_REQUIRES(context, p < out_size,
errors::OutOfRange(
errors::InvalidArgument(
"Tried to set output index ", p,
" when output Tensor only had ", out_size,
" elements. Check that your "
......
......@@ -63,9 +63,9 @@ Status ReductionHelper::Simplify(const Tensor& data, const Tensor& axis,
for (int64 i = 0; i < axis.NumElements(); ++i) {
const int32 index = axis_vec(i);
if (index < 0 || index >= data.dims()) {
return errors::OutOfRange("Invalid reduction dimension (", index,
" for input with ", data.dims(),
" dimension(s)");
return errors::InvalidArgument("Invalid reduction dimension (", index,
" for input with ", data.dims(),
" dimension(s)");
}
bitmap[index] = true;
}
......
......@@ -89,7 +89,7 @@ class SummaryHistoOp : public OpKernel {
T v = flat(i);
if (!std::isfinite(v)) {
c->SetStatus(
errors::OutOfRange("Nan in summary histogram for: ", name()));
errors::InvalidArgument("Nan in summary histogram for: ", name()));
break;
}
histo.Add(static_cast<double>(v));
......
......@@ -99,7 +99,7 @@ enum Code {
// ABORTED, and UNAVAILABLE.
ABORTED = 10;
// Operation was attempted past the valid range. E.g., seeking or
// Operation tried to iterate past the valid input range. E.g., seeking or
// reading past end of file.
//
// Unlike INVALID_ARGUMENT, this error indicates a problem that may
......
......@@ -89,7 +89,7 @@ The generated
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
has one summary value containing a histogram for `values`.
This op reports an `OutOfRange` error if any value is not finite.
This op reports an `InvalidArgument` error if any value is not finite.
tag: Scalar. Tag to use for the `Summary.Value`.
values: Any shape. Values to use to build the histogram.
......
......@@ -328,7 +328,7 @@ class AbortedError(OpError):
class OutOfRangeError(OpError):
"""Raised when an operation executed past the valid range.
"""Raised when an operation iterates past the valid input range.
This exception is raised in "end-of-file" conditions, such as when a
[`queue.dequeue()`](../../api_docs/python/io_ops.md#QueueBase.dequeue)
......
......@@ -94,7 +94,7 @@ def histogram_summary(tag, values, collections=None, name=None):
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
has one summary value containing a histogram for `values`.
This op reports an `OutOfRange` error if any value is not finite.
This op reports an `InvalidArgument` error if any value is not finite.
Args:
tag: A `string` `Tensor`. 0-D. Tag to use for the summary value.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册