Skip to content

Sparsity Detection

asdex.jacobian_sparsity(f, *args, argnums=_DEFAULT_ARGNUMS, has_aux=_DEFAULT_HAS_AUX, **kwargs)

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. Defaults to 0.

_DEFAULT_ARGNUMS
has_aux bool

Whether f returns (output, auxiliary_data). When True, the auxiliary output is ignored and only output is analyzed for sparsity.

_DEFAULT_HAS_AUX
**kwargs Any

Sample keyword arguments of f. Non-traceable values (bools, strings, ints) are bound statically.

{}

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=_DEFAULT_ARGNUMS, has_aux=_DEFAULT_HAS_AUX, **kwargs)

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 whose Hessian 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. Defaults to 0.

_DEFAULT_ARGNUMS
has_aux bool

Whether f returns (output, auxiliary_data). When True, the auxiliary output is ignored and only output is analyzed for sparsity.

_DEFAULT_HAS_AUX
**kwargs Any

Sample keyword arguments of f. Non-traceable values (bools, strings, ints) are bound statically.

{}

Returns:

Type Description
SparsityPattern

Square SparsityPattern over the combined, selected input space.