derivkit.utils.validate module¶
Validation utilities for DerivativeKit.
- derivkit.utils.validate.check_scalar_valued(function, theta0: ndarray, i: int, n_workers: int)¶
Helper used by
build_gradientandbuild_hessian.- Parameters:
function (callable) – The scalar-valued function to differentiate. It should accept a list or array of parameter values as input and return a scalar observable value.
theta0 – The points at which the derivative is evaluated. A 1D array or list of parameter values matching the expected input of the function.
i – Zero-based index of the parameter with respect to which to differentiate.
n_workers – Number of workers used inside
DerivativeKit.adaptive.differentiate. This does not parallelize across parameters.
- Raises:
TypeError – If
functiondoes not return a scalar value.
- derivkit.utils.validate.is_finite_and_differentiable(function: Callable[[float], Any], x: float, delta: float = 1e-05) bool¶
Check that
functionis finite atxandx + delta.Evaluates without exceptions and returns finite values at both points.
- Parameters:
function – Callable
f(x)returning a scalar or array-like.x – Probe point.
delta – Small forward step.
- Returns:
True if finite at both points; otherwise False.