def SchemeUniform_OptInner(u, SB, f, bc, oracle=None):
    # Use the oracle, if available, to select the active superbases only
    if not (oracle is None):
        SB = np.take_along_axis(SB,
                                np.broadcast_to(
                                    oracle,
                                    SB.shape[:2] + (1, ) + oracle.shape),
                                axis=2)

    d2u = bc.Diff2(u, SB)
    d2u[..., bc.not_interior] = 0.  # Placeholder value to silent NaN warnings

    # Generate the parameters for the low dimensional optimization problem
    Q = 0.5 * np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]])
    dim = 2
    l = -d2u
    m = lp.dot_VV(SB, SB)

    m = bc.as_field(m)
    from agd.FiniteDifferences import as_field
    Q = as_field(Q, m.shape[1:])

    dim = 2
    alpha = dim * f**(1 / dim)
    mask = (alpha == 0)

    Q = Q * np.where(mask, 1., alpha**2)
    # Evaluate the non-linear functional using dense-sparse composition
    residue = ad.apply(ConstrainedMaximize, Q, l, m,
                       shape_bound=u.shape).copy()
    residue[:, mask] = np.max(l / m, axis=0)[:, mask]

    return ad.max_argmax(residue, axis=0)
def SchemeUniform(u, SB, f, bc):
    # Compute the finite differences along the superbase directions
    d2u = bc.Diff2(u, SB)
    d2u[..., bc.not_interior] = 0.  # Placeholder value to silent NaN warnings

    # Generate the parameters for the low dimensional optimization problem
    Q = 0.5 * np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]])
    l = -d2u
    m = lp.dot_VV(SB, SB)

    # Evaluate the numerical scheme
    m = bc.as_field(m)
    from agd.FiniteDifferences import as_field
    Q = as_field(Q, m.shape[1:])

    dim = 2
    alpha = dim * f**(1 / dim)
    mask = (alpha == 0)

    Q = Q * np.where(mask, 1., alpha**2)
    residue = ConstrainedMaximize(Q, l, m).max(axis=0)
    residue[mask] = np.max(l / m, axis=0).max(axis=0)[mask]

    # Boundary conditions
    return np.where(bc.interior, residue, u - bc.grid_values)