Skip to content

Sparsity Detection

asdex.jacobian_sparsity(f, *args, argnums=0, has_aux=False)

Detect global Jacobian sparsity pattern for f.

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 whose Jacobian sparsity pattern is to be detected.

required
*args Any

Sample arguments of f. Only structure and dtypes are used, values are ignored.

()
argnums int | Sequence[int]

Specifies which positional argument(s) to differentiate with respect to (default 0).

0
has_aux bool

Whether f returns (output, auxiliary_data). When True, only output is analyzed for sparsity; the auxiliary branch of the computation is not traced.

False

Returns:

Type Description
SparsityPattern

SparsityPattern of shape (m, n_selected) where m = prod(output_shape) and n_selected is the total flat size of the selected inputs.

asdex.hessian_sparsity(f, *args, argnums=0, has_aux=False)

Detect global Hessian sparsity pattern for a scalar-valued f.

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 one or more positional arrays.

required
*args Any

Sample arguments of f. Only structure and dtypes are used, values are ignored.

()
argnums int | Sequence[int]

Specifies which positional argument(s) to differentiate with respect to (default 0).

0
has_aux bool

Whether f returns (scalar_output, auxiliary_data). When True, aux is stripped before detection.

False

Returns:

Type Description
SparsityPattern

Square SparsityPattern over the combined, selected input space.