| 450 | } |
| 451 | |
| 452 | std::vector<Tensor> ReverseGrad(const Tensor& x, const Tensor& dims, |
| 453 | const Tensor& dy) { |
| 454 | auto T = DT_FLOAT; |
| 455 | auto gdef = test::function::GDef( |
| 456 | {f::NDef("x", "Placeholder", {}, {{"dtype", T}}), |
| 457 | f::NDef("dims", "Placeholder", {}, {{"dtype", DT_BOOL}}), |
| 458 | f::NDef("dy", "Placeholder", {}, {{"dtype", T}}), |
| 459 | f::NDef("dx", "SymbolicGradient", {"x", "dims", "dy"}, |
| 460 | {{"f", FDH::FunctionRef("Reverse", {{"T", T}})}, |
| 461 | {"Tin", DataTypeSlice{T, DT_BOOL, T}}, |
| 462 | {"Tout", DataTypeSlice{T, DT_BOOL}}})}); |
| 463 | VLOG(1) << DebugStringWhole(gdef); |
| 464 | auto sess = NewSession(); |
| 465 | TF_CHECK_OK(sess->Create(gdef)); |
| 466 | std::vector<Tensor> out; |
| 467 | TF_CHECK_OK(sess->Run({{"x:0", x}, {"dims:0", dims}, {"dy:0", dy}}, |
| 468 | {"dx:0", "dx:1"}, {}, &out)); |
| 469 | CHECK_EQ(out.size(), 2); |
| 470 | TF_CHECK_OK(sess->Close()); |
| 471 | return out; |
| 472 | } |
| 473 | |
| 474 | TEST(ArrayGradTest, ReverseGrad) { |
| 475 | Tensor x(DT_FLOAT, {2, 3}); |
no test coverage detected