| 53 | } |
| 54 | |
| 55 | bool Compare() { |
| 56 | const auto& input = GetInput(0); |
| 57 | const int64 batch_size = input.dim_size(0); |
| 58 | const int64 rows = input.dim_size(1); |
| 59 | const int64 cols = input.dim_size(2); |
| 60 | const int64 depth = input.dim_size(3); |
| 61 | const int64 rest = cols * rows * batch_size; |
| 62 | |
| 63 | const int64 depth_radius = GetIntAttr("depth_radius"); |
| 64 | const float bias = GetFloatAttr("bias"); |
| 65 | const float alpha = GetFloatAttr("alpha"); |
| 66 | const float beta = GetFloatAttr("beta"); |
| 67 | |
| 68 | Eigen::Tensor<float, 4, Eigen::RowMajor> expected(batch_size, rows, cols, |
| 69 | depth); |
| 70 | auto out = expected.reshape(Eigen::DSizes<int64, 2>{rest, depth}); |
| 71 | auto in = input.shaped<float, 2>({rest, depth}); |
| 72 | |
| 73 | for (int64 i = 0; i < rest; ++i) { |
| 74 | Eigen::Tensor<float, 1, Eigen::RowMajor> out_col(depth); |
| 75 | for (int64 d = 0; d < depth; ++d) { |
| 76 | float denom = 0.0f; |
| 77 | for (int64 r = std::max(int64{0}, d - depth_radius); |
| 78 | r < std::min(depth, d + depth_radius + 1); ++r) { |
| 79 | denom += in(i, r) * in(i, r); |
| 80 | } |
| 81 | denom = std::pow(denom * alpha + bias, beta); |
| 82 | out_col(d) = in(i, d) / denom; |
| 83 | } |
| 84 | out.chip<0>(i) = out_col; |
| 85 | } |
| 86 | auto actual = GetOutput(0)->tensor<float, 4>(); |
| 87 | Eigen::Tensor<float, 0, Eigen::RowMajor> sum = |
| 88 | ((expected - actual).abs() > actual.constant(tol_)) |
| 89 | .select(actual.constant(1), actual.constant(0)) |
| 90 | .sum(); |
| 91 | return sum() == 0; |
| 92 | } |
| 93 | |
| 94 | random::PhiloxRandom philox_; |
| 95 | random::SimplePhilox rand_; |
nothing calls this directly
no test coverage detected