fips.linalg.BlockDiagonalOperator#

class fips.linalg.BlockDiagonalOperator(*args, **kwargs)[source]#

Bases: LinearOperator

A square matrix made of forms on its diagonal blocks, zero between them.

A covariance whose blocks are independent (a flux block with Kronecker factors and a diagonal bias block, say) keeps each block in its own form: products, solves, the diagonal and the log-determinant go block by block, and the full matrix is formed only by dense().

Parameters:

blocks (sequence of LinearOperator, SciPy sparse matrix or 2D array) – The diagonal blocks, in order, each square. A form is kept as it is (it holds its own copy); an array or a sparse matrix is copied, as as_linear_operator() does.

Raises:

ValueError – If there is no block or a block is not square.

Examples

>>> import numpy as np
>>> from fips.linalg import BlockDiagonalOperator, DiagonalOperator
>>> S = BlockDiagonalOperator(
...     [np.array([[2.0, 1.0], [1.0, 2.0]]), DiagonalOperator([4.0])]
... )
>>> S.dense()
array([[2., 1., 0.],
       [1., 2., 0.],
       [0., 0., 4.]])
>>> S.solve(np.array([3.0, 3.0, 4.0]))
array([1., 1., 1.])

Attributes

blocks

The diagonal blocks, each in its own form.

Methods

dense()

Return the form as a dense NumPy array.

diagonal()

Return the main diagonal, block by block.

logdet()

Return the sum of the blocks' log-determinants.

solve(B)

Solve self @ X = B block by block (see LinearOperator.solve()).

sqrt()

Return the square root of each block.

Inherited

From LinearOperator: dot, trace