| 21 | |
| 22 | template <typename T> |
| 23 | void 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 | |
| 53 | void ExpectClose(const Tensor& x, const Tensor& y, double atol, double rtol) { |
| 54 | internal::AssertSameTypeDims(x, y); |
no test coverage detected