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_gradient and build_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 function does 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 function is finite at x and x + 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.