[XLA] Make shape inference error messages for the While HLO more readable. Build the error lazily.

PiperOrigin-RevId: 168531083
This commit is contained in:
Peter Hawkins 2017-09-13 06:30:33 -07:00 committed by TensorFlower Gardener
parent d10374e458
commit 99423416a4

View File

@ -1816,14 +1816,18 @@ ShapeInference::InferDegenerateDimensionBroadcastShape(
body.parameters_size());
}
string shape_string = tensorflow::strings::Printf(
"condition: %s; body: %s; init: %s", condition.ShortDebugString().c_str(),
body.ShortDebugString().c_str(), init.ShortDebugString().c_str());
auto shape_string = [&]() {
return tensorflow::strings::Printf(
"condition: %s; body: %s; init: %s",
ShapeUtil::HumanString(condition).c_str(),
ShapeUtil::HumanString(body).c_str(),
ShapeUtil::HumanString(init).c_str());
};
// Check the shapes of computation parameters and return types.
if (!ShapeUtil::ShapeIs(condition.result(), PRED, {})) {
return InvalidArgument("condition must return a boolean; got %s",
shape_string.c_str());
shape_string().c_str());
}
if (!ShapeUtil::Compatible(body.result(), condition.parameters(0)) ||
!ShapeUtil::Compatible(body.result(), body.parameters(0)) ||
@ -1831,7 +1835,7 @@ ShapeInference::InferDegenerateDimensionBroadcastShape(
return InvalidArgument(
"the parameter of condition and body, the result of the body, and init "
"must all have the same shape; got %s",
shape_string.c_str());
shape_string().c_str());
}
return init;