derivkit.adaptive.batch_eval module¶
Batch evaluation utilities for derivative estimation.
Evaluate a user function over a 1D grid with optional parallelism and return a 2D array with consistent shape suitable for downstream polynomial fitting and diagnostics (e.g., in AdaptiveFitDerivative).
- derivkit.adaptive.batch_eval.eval_function_batch(function: Callable[[float], Any], xs: ndarray, n_workers: int = 1) ndarray¶
Evaluate a function over 1D inputs and return a (n_points, n_comp) float array.
Evaluates
function(x)for eachxinxs. Ifn_workers > 1, uses amultiprocess.Pool; otherwise runs serially. Scalars become a single column. For array outputs, this routine coerces to a consistent 2D shape that downstream polynomial-fitting code expects.- Parameters:
function – Callable mapping a float to a scalar or array-like. Must be picklable if used with multiple processes.
xs – 1D array of abscissae.
n_workers – If > 1, evaluate in parallel using
multiprocess.Pool.
- Returns:
Array of shape
(n_points, n_comp)with dtypefloat.- Return type:
np.ndarray
- Raises:
ValueError – If
xsis not 1D or outputs cannot be coerced consistently.
Examples
>>> import numpy as np >>> f = lambda x: np.array([x, x**2]) >>> xs = np.linspace(-1.0, 1.0, 5) >>> y = eval_function_batch(f, xs) >>> y.shape (5, 2)