core.BlockDiag
core.BlockDiag(blocks)One operator per block, keyed by block name (see layout).
The precision is block diagonal, \(P = \operatorname{blockdiag}(P_1, \dots, P_K)\). Vectors here are mappings from block name to that block’s flat vector.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| blocks | Mapping[str, Op] | The operator \(P_k\) of each block, keyed by block name. | required |
Methods
| Name | Description |
|---|---|
| add_diagonal | The same as add_per_block(d): a 0-dim entry is added as an isotropic term. |
| add_isotropic | \(P_k + \lambda I\) for each block \(k\). |
| add_per_block | Add precision[k] to block k: a scalar to every diagonal entry, or a vector. |
| add_same | \(P_k + P'_k\) for each block \(k\). |
| block_sizes | Each block’s flat size, the length of its diagonal. |
| cov_sqrt_mv | \(L_k v_k\) for each block \(k\), with \(L_k\) the block’s covariance square root. |
| diagonal | Each block’s diagonal. |
| inverse_diagonal | Each block’s inverse_diagonal. |
| logdet | \(\sum_k \log \det P_k\). |
| mv | \(P_k v_k\) for each block \(k\). |
| scaled | Each block scaled by \(s\). |
| solve | \(P_k^{-1} v_k\) for each block \(k\). |
add_diagonal
core.BlockDiag.add_diagonal(d, /)The same as add_per_block(d): a 0-dim entry is added as an isotropic term.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| d | Mapping[str, Tensor] | The diagonal \(d\), shaped like a vector of the operator. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | d is not a mapping, its keys differ from the blocks, or a block can’t hold a diagonal (a KronEigenbasis given a vector). |
add_isotropic
core.BlockDiag.add_isotropic(precision, /)\(P_k + \lambda I\) for each block \(k\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| precision | Tensor | The precision \(\lambda\), a 0-dim tensor. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
add_per_block
core.BlockDiag.add_per_block(precision, /)Add precision[k] to block k: a scalar to every diagonal entry, or a vector.
A 0-dim precision[k] goes through the block’s add_isotropic, a vector through its add_diagonal.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| precision | Mapping[str, Tensor] | A mapping from block name to a 0-dim tensor or a vector [P_k], with the operator’s block names. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | precision is not a mapping, its keys differ from the blocks, or a block can’t hold a diagonal (a KronEigenbasis given a vector). |
add_same
core.BlockDiag.add_same(other, /)\(P_k + P'_k\) for each block \(k\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| other | Operator[Mapping[str, Tensor]] | The operator \(P'\). | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | other is not a BlockDiag, its block names differ, or a block’s add_same raises it. |
block_sizes
core.BlockDiag.block_sizes()Each block’s flat size, the length of its diagonal.
Returns
| Name | Type | Description |
|---|---|---|
| Mapping[str, int] | A mapping from block name to flat size, in block order. |
cov_sqrt_mv
core.BlockDiag.cov_sqrt_mv(v, /)\(L_k v_k\) for each block \(k\), with \(L_k\) the block’s covariance square root.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| v | Mapping[str, Tensor] | A mapping of vectors [..., P_k], keyed by block name. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Mapping[str, Tensor] | \(L v\), shaped like v. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | v is not a mapping, its keys differ from the blocks, or a block raises it (such as a Dense that is not positive definite). |
diagonal
core.BlockDiag.diagonal()Each block’s diagonal.
Returns
| Name | Type | Description |
|---|---|---|
| Mapping[str, Tensor] | A mapping of vectors [P_k], keyed by block name. |
inverse_diagonal
core.BlockDiag.inverse_diagonal()Each block’s inverse_diagonal.
Returns
| Name | Type | Description |
|---|---|---|
| Mapping[str, Tensor] | A mapping of vectors [P_k], keyed by block name. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | A block raises it (such as a Dense that is not positive definite). |
logdet
core.BlockDiag.logdet()\(\sum_k \log \det P_k\).
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | A 0-dim tensor. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | A block raises it (such as a Dense that is not positive definite). |
mv
core.BlockDiag.mv(v, /)\(P_k v_k\) for each block \(k\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| v | Mapping[str, Tensor] | A mapping of vectors [..., P_k], keyed by block name. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Mapping[str, Tensor] | \(P v\), shaped like v. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | v is not a mapping, or its keys differ from the blocks. |
scaled
core.BlockDiag.scaled(s, /)Each block scaled by \(s\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| s | Tensor | A 0-dim factor. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
solve
core.BlockDiag.solve(v, /)\(P_k^{-1} v_k\) for each block \(k\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| v | Mapping[str, Tensor] | A mapping of vectors [..., P_k], keyed by block name. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Mapping[str, Tensor] | \(P^{-1} v\), shaped like v. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | v is not a mapping, its keys differ from the blocks, or a block raises it (such as a Dense that is not positive definite). |