MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TensorsAreClose

Function TensorsAreClose

tensorflow/compiler/tests/randomized_tests.cc:797–828  ·  view source on GitHub ↗

Tests if "x" and "y" are tensors of the same type, same shape, and with close values. For floating-point tensors, the element-wise difference between x and y must no more than atol + rtol * abs(x). For non-floating-point tensors the values must match exactly.

Source from the content-addressed store, hash-verified

795// x and y must no more than atol + rtol * abs(x). For non-floating-point
796// tensors the values must match exactly.
797Status TensorsAreClose(const Tensor& a, const Tensor& b, double atol,
798 double rtol) {
799 if (a.dtype() != b.dtype()) {
800 return errors::InvalidArgument(absl::StrCat(
801 "Tensors have different types: ", DataTypeString(a.dtype()), " and ",
802 DataTypeString(b.dtype())));
803 }
804 if (!a.IsSameSize(b)) {
805 return errors::InvalidArgument(
806 absl::StrCat("Tensors have different shapes: ", a.shape().DebugString(),
807 " and ", b.shape().DebugString()));
808 }
809
810 switch (a.dtype()) {
811 case DT_FLOAT:
812 return TensorsAreCloseImpl<float>(a, b, atol, rtol);
813 case DT_DOUBLE:
814 return TensorsAreCloseImpl<double>(a, b, atol, rtol);
815 case DT_COMPLEX64:
816 return TensorsAreCloseImpl<complex64>(a, b, atol, rtol);
817 case DT_INT32:
818 return TensorsAreEqualImpl<int32>(a, b);
819 case DT_INT64:
820 return TensorsAreEqualImpl<int64>(a, b);
821 case DT_BOOL:
822 return TensorsAreEqualImpl<bool>(a, b);
823 case DT_BFLOAT16:
824 return TensorsAreEqualImplBfloat16(a, b);
825 default:
826 LOG(FATAL) << "Unexpected type : " << DataTypeString(a.dtype());
827 }
828}
829
830OpTest::TestResult OpTest::ExpectTfAndXlaOutputsAreClose(
831 const OpTestBuilder& builder, double atol, double rtol) {

Callers 1

Calls 8

InvalidArgumentFunction · 0.85
StrCatFunction · 0.50
DataTypeStringFunction · 0.50
dtypeMethod · 0.45
IsSameSizeMethod · 0.45
DebugStringMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected