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

Function ExpectClose

tensorflow/core/framework/tensor_testutil.cc:23–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22template <typename T>
23void ExpectClose(const Tensor& x, const Tensor& y, double atol, double rtol) {
24 const T* Tx = x.flat<T>().data();
25 const T* Ty = y.flat<T>().data();
26 const auto size = x.NumElements();
27
28 // Tolerance's type (RealType) can be different from T.
29 // For example, if T = std::complex<float>, then RealType = float.
30 // Did not use std::numeric_limits<T> because
31 // 1) It returns 0 for Eigen::half.
32 // 2) It doesn't support T=std::complex<RealType>.
33 // (Would have to write a templated struct to handle this.)
34 typedef decltype(Eigen::NumTraits<T>::epsilon()) RealType;
35 const RealType kSlackFactor = static_cast<RealType>(5.0);
36 const RealType kDefaultTol = kSlackFactor * Eigen::NumTraits<T>::epsilon();
37 const RealType typed_atol =
38 (atol < 0) ? kDefaultTol : static_cast<RealType>(atol);
39 const RealType typed_rtol =
40 (rtol < 0) ? kDefaultTol : static_cast<RealType>(rtol);
41 ASSERT_GE(typed_atol, static_cast<RealType>(0.0))
42 << "typed_atol is negative: " << typed_atol;
43 ASSERT_GE(typed_rtol, static_cast<RealType>(0.0))
44 << "typed_rtol is negative: " << typed_rtol;
45 for (int i = 0; i < size; ++i) {
46 EXPECT_TRUE(
47 internal::Helper<T>::IsClose(Tx[i], Ty[i], typed_atol, typed_rtol))
48 << "index = " << i << " x = " << Tx[i] << " y = " << Ty[i]
49 << " typed_atol = " << typed_atol << " typed_rtol = " << typed_rtol;
50 }
51}
52
53void ExpectClose(const Tensor& x, const Tensor& y, double atol, double rtol) {
54 internal::AssertSameTypeDims(x, y);

Callers 15

TEST_FFunction · 0.85
TESTFunction · 0.85
RunComposedOpMethod · 0.85
TESTFunction · 0.85
TEST_FFunction · 0.85
RunTestMethod · 0.85
RunTestMethod · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls 7

epsilonFunction · 0.85
IsCloseFunction · 0.85
AssertSameTypeDimsFunction · 0.85
DataTypeStringFunction · 0.70
dataMethod · 0.45
NumElementsMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected