message: add `TestMulGrad` to `math_grad_test`
diff: @@ -172,6 +172,35 @@ Status SubGradModel(AbstractContext* ctx,
  return Status::OK();
  }
  +Status MulModel(AbstractContext* ctx,
  + absl::Span<AbstractTensorHandle* const> inputs,
  + absl::Span<AbstractTensorHandle*> outputs) {
  + return ops::Mul(ctx, inputs, outputs, "Mul");
  +}
  +
  +Status MulGradModel(AbstractContext* ctx,
  + absl::Span<AbstractTensorHandle* const> inputs,
  + absl::Span<AbstractTensorHandle*> outputs) {
  + GradientRegistry registry;
  + TF_RETURN_IF_ERROR(registry.Register("Mul", MulRegisterer));
  +
  + Tape tape(/*persistent=*/false);
  + tape.Watch(inputs[0]);
  + tape.Watch(inputs[1]);
  + std::vector<AbstractTensorHandle*> temp_outputs(1);
  + AbstractContextPtr tape_ctx(new TapeContext(ctx, &tape, registry));
  + TF_RETURN_IF_ERROR(ops::Mul(tape_ctx.get(), inputs,
  + absl::MakeSpan(temp_outputs), "MulGrad"));
  +
  + TF_RETURN_IF_ERROR(tape.ComputeGradient(ctx, /*targets=*/temp_outputs,
  + /*sources=*/inputs,
  + /*output_gradients=*/{}, outputs));
  + for (auto temp_output : temp_outputs) {
  + temp_output->Unref();
  + }
  + return Status::OK();
  +}
  +
  class CppGradients
  : public ::testing::TestWithParam<std::tuple<const char*, bool, bool>> {
  protected:
  @@ -278,6 +307,27 @@ TEST_P(CppGradients, TestSubGrad) {
  SubModel, SubGradModel, ctx_.get(), {x.get(), y.get()}, UseFunction()));
  }
  +TEST_P(CppGradients, TestMulGrad) {
  + AbstractTensorHandlePtr x;
  + {
  + AbstractTensorHandle* x_raw = nullptr;
  + Status s = TestScalarTensorHandle(ctx_.get(), 2.0f, &x_raw);
  + ASSERT_EQ(errors::OK, s.code()) << s.error_message();
  + x.reset(x_raw);
  + }
  +
  + AbstractTensorHandlePtr y;
  + {
  + AbstractTensorHandle* y_raw = nullptr;
  + Status s = TestScalarTensorHandle(ctx_.get(), 2.0f, &y_raw);
  + ASSERT_EQ(errors::OK, s.code()) << s.error_message();
  + y.reset(y_raw);
  + }
  +
  + ASSERT_NO_FATAL_FAILURE(CompareNumericalAndAutodiffGradients(
  + MulModel, MulGradModel, ctx_.get(), {x.get(), y.get()}, UseFunction()));
  +}
  +
  #ifdef PLATFORM_GOOGLE
  INSTANTIATE_TEST_SUITE_P(
  UnifiedCAPI, CppGradients,
  