@parameterized.named_parameters(({'testcase_name': f'_{name}', 'cond': cond} for (cond, name) in COND_IMPLS))
def testCondVmapGrad(self, cond):

    def f_1(x):
        return (x ** 2)

    def f_2(x):
        return (x ** 3)

    def f(x):
        return cond((x > 0), f_1, f_2, x)

    def g(x):
        return jnp.where((x > 0), f_1(x), f_2(x))
    x = jnp.linspace((- 1), 1, 20)
    ans = api.vmap(api.grad(f))(x)
    expected = api.vmap(api.grad(g))(x)
    self.assertAllClose(ans, expected, check_dtypes=False)
@parameterized.named_parameters(({'testcase_name': f'_{name}', 'cond': cond} for (cond, name) in COND_IMPLS))
def testCondVmapGrad(self, cond):

    def f_1(x):
        return (x ** 2)

    def f_2(x):
        return (x ** 3)

    def f(x):
        return cond((x > 0), f_1, f_2, x)

    def g(x):
        return jnp.where((x > 0), f_1(x), f_2(x))
    x = jnp.linspace((- 1), 1, 20)
    ans = api.vmap(api.grad(f))(x)
    expected = api.vmap(api.grad(g))(x)
    self.assertAllClose(ans, expected, check_dtypes=False)