dymad.numerics.gradients

Functions

central_diff(f, x[, h, v])

Central difference.

complex_step(f, x[, h, v])

Complex step differentiation.

torch_jacobian(f, x[, v, dtype])

Jacobian using torch.func.jacobian.

dymad.numerics.gradients.central_diff(f, x, h=1e-06, v=None)

Central difference.

Parameters:
  • f – function handle that accepts and returns numpy arrays.

  • x – input array.

  • h – step size.

  • v – directions for directional derivative. If None, return full Jacobian.

Returns:

derivative of f at x, possibly directional.

Return type:

df

dymad.numerics.gradients.complex_step(f, x, h=1e-20, v=None)

Complex step differentiation.

Parameters:
  • f – function handle that accepts and returns numpy arrays.

  • x – input array.

  • h – step size.

  • v – directions for directional derivative. If None, return full Jacobian.

Returns:

derivative of f at x, possibly directional.

Return type:

df

dymad.numerics.gradients.torch_jacobian(f, x, v=None, dtype=torch.float64)

Jacobian using torch.func.jacobian.

Parameters:
  • f – function handle that accepts and returns torch tensors.

  • x – input array.

  • v – directions for directional derivative. If None, return full Jacobian.

Returns:

derivative of f at x, possibly directional.

Return type:

df