(points, degree)
return out, res
Using monomials.
Using monomials.
Using monomials .
def e2r_compute_weights(points, degree):
    """Using monomials."""
    exponents = np.concatenate([partition(2, d) for d in range(degree + 1)])

    exact_vals = np.array([integrate_monomial_over_enr(k) for k in exponents])

    def fun(x):
        k = exponents.T
        # <https://stackoverflow.com/a/46689653/353337>
        s = x.shape[1:] + k.shape[1:]
        return (
            (x.reshape(x.shape[0], -1, 1) ** k.reshape(k.shape[0], 1, -1))
            .prod(0)
            .reshape(s)
        )

    A = fun(points).T
    out = np.linalg.lstsq(A, exact_vals, rcond=None)
    res = np.dot(A, out[0]) - exact_vals
    return out, res
def e2r_compute_weights ( points , degree ) : exponents = np . concatenate ( [ partition ( 2 , d ) for d in range ( degree + 1 ) ] ) exact_vals = np . array ( [ integrate_monomial_over_enr ( k ) for k in exponents ] ) def fun ( x ) : k = exponents . T # <https://stackoverflow.com/a/46689653/353337> s = x . shape [ 1 : ] + k . shape [ 1 : ] return ( ( x . reshape ( x . shape [ 0 ] , - 1 , 1 ) ** k . reshape ( k . shape [ 0 ] , 1 , - 1 ) ) . prod ( 0 ) . reshape ( s ) ) A = fun ( points ) . T out = np . linalg . lstsq ( A , exact_vals , rcond = None ) res = np . dot ( A , out [ 0 ] ) - exact_vals return out , res