def METHOD_NAME(modname, recorded):
    m = get_module(modname)
    dr.set_flag(dr.JitFlag.VCallRecord, recorded)
    data = m.Float([1.0, 2.0, 3.0, 4.0])
    dr.enable_grad(data)
    def f(a, i):
        return a + dr.gather(m.Float, data, i)
    def g(a, i):
        return a + 4 * dr.gather(m.Float, data, i)
    idx = m.UInt([0, 0, 1, 1])
    a = m.Float([1.0, 2.0, 3.0, 4.0])
    i = m.UInt([3, 2, 1, 0])
    result = dr.switch(idx, [f, g], a, i)
    assert dr.allclose(result, [5, 5, 11, 8])
    dr.backward(result)
    assert dr.allclose(dr.grad(data), [4, 4, 1, 1])