Coloring¶
asdex.jacobian_coloring(f, input_shape, *, mode=None, symmetric=False)
¶
Detect Jacobian sparsity and color in one step.
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. |
required |
mode
|
JacobianMode | None
|
AD mode.
|
None
|
symmetric
|
bool
|
Whether to use symmetric (star) coloring. Requires a square Jacobian. |
False
|
Returns:
| Type | Description |
|---|---|
ColoredPattern
|
A |
asdex.hessian_coloring(f, input_shape, *, mode=None, symmetric=True)
¶
Detect Hessian sparsity and color in one step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable
|
Scalar-valued function taking an array. |
required |
input_shape
|
int | tuple[int, ...]
|
Shape of the input array. |
required |
mode
|
HessianMode | None
|
AD composition strategy for Hessian-vector products.
|
None
|
symmetric
|
bool
|
Whether to use symmetric (star) coloring. Defaults to True (exploits H = H^T for fewer colors). |
True
|
Returns:
| Type | Description |
|---|---|
ColoredPattern
|
A |
asdex.jacobian_coloring_from_sparsity(sparsity, *, mode=None, symmetric=False)
¶
Color a sparsity pattern for sparse Jacobian computation.
Assigns colors so that same-colored rows (or columns) can be computed together in a single VJP (or JVP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparsity
|
SparsityPattern
|
Sparsity pattern of shape (m, n). |
required |
mode
|
JacobianMode | None
|
AD mode.
|
None
|
symmetric
|
bool
|
Whether to use symmetric (star) coloring. Requires a square pattern. |
False
|
Returns:
| Type | Description |
|---|---|
ColoredPattern
|
A |
asdex.hessian_coloring_from_sparsity(sparsity, *, mode=None, symmetric=True)
¶
Color a sparsity pattern for sparse Hessian computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparsity
|
SparsityPattern
|
Sparsity pattern of shape (n, n). |
required |
mode
|
HessianMode | None
|
AD composition strategy for Hessian-vector products.
|
None
|
symmetric
|
bool
|
Whether to use symmetric (star) coloring. Defaults to True (exploits Hessian symmetry for fewer colors). |
True
|
Returns:
| Type | Description |
|---|---|
ColoredPattern
|
A |