import numpy as np
from scipy.spatial import ConvexHull
from .utils import config
[docs]def trapezoidal(x):
"""Trapezoidal weights for trapezoidal rule integration."""
diff = np.diff(x, axis=0)
weights = np.zeros(x.shape, dtype=config.real(np))
weights[1:-1] = diff[1:] + diff[:-1]
weights[0] = diff[0]
weights[-1] = diff[-1]
weights = weights / 2
return weights
[docs]def get_weights(identifier, x):
"""Get the type of quadrature weights associated to the numpy array x."""
if isinstance(identifier, str):
return {
"trapezoidal": trapezoidal(x),
"uniform": uniform(x),
}[identifier]