Skip to content

Sparsity Detection

asdex.jacobian_sparsity(f, input_shape)

Detect global Jacobian sparsity pattern for f: R^n -> R^m.

Analyzes the computation graph structure directly, without evaluating any derivatives. The result is valid for all inputs.

Parameters:

Name Type Description Default
f Callable

Function taking an array and returning an array.

required
input_shape int | tuple[int, ...]

Shape of the input array. An integer is treated as a 1D length.

required

Returns:

Type Description
SparsityPattern

SparsityPattern of shape (m, n) where n = prod(input_shape) and m = prod(output_shape). Entry (i, j) is present if output i depends on input j.

asdex.hessian_sparsity(f, input_shape)

Detect global Hessian sparsity pattern for f: R^n -> R.

Analyzes the Jacobian sparsity of the gradient function, without evaluating any derivatives. The result is valid for all inputs.

If f returns a squeezable shape like (1,) or (1, 1), it is automatically squeezed to scalar.

Parameters:

Name Type Description Default
f Callable

Scalar-valued function taking an array.

required
input_shape int | tuple[int, ...]

Shape of the input array. An integer is treated as a 1D length.

required

Returns:

Type Description
SparsityPattern

SparsityPattern of shape (n, n) where n = prod(input_shape). Entry (i, j) is present if H[i, j] may be nonzero.