dubfi.linalg.csc_sparse

CSC sparse matrix implementation of generic operators.

Added in version 0.1.0: (initial release)

Classes

CscMatrix

Compressed sparse column representation of a linear operator.

CscTraceProdOperator

Auxiliary class used for computing trace products.

CscEnsLinPostR

CSC representation of R matrix in flux inversion problem.

Functions

_csc_trace(→ numpy.ndarray)

Compute trace of a matrix in compressed sparse column representation.

tr_asolver_bcsr(apply_a, data, indices, indptr)

Compute trace(A @ B) where Ax := apply_a(x) and B is represented as BSR (data, indices, indptr).

tr_asolver_bcsc(apply_a, data, indices, indptr)

Compute trace(A @ B) where Ax := apply_a(x) and B is represented as BSC (data, indices, indptr).

_csc_csr_trace_prod(→ numpy.ndarray)

Compute trace(A @ B) represented as sparse CSC and CSR arrays.

_r_csc_from_ens(loc_data, indices, indptr, h)

Construct ensemble contribution to R CSC data.

_rgrad_csc_from_ens(loc_data, indices, indptr, h, h_ens)

Construct gradient of R CSC data.

_rhess_csc_from_ens(loc_data, indices, indptr, h_ens)

Construct Hesse matrix of R CSC data.

Module Contents

class dubfi.linalg.csc_sparse.CscMatrix(array, symmetric=False, use_inv=True)

Bases: dubfi.linalg.types.Operator

Compressed sparse column representation of a linear operator.

property symmetric

Indicate whether matrix is (or must be) real-symmetric.

property splu

Sparse LU decomposition of self.

tonumpy()

Convert to dense array.

property csc_array: scipy.sparse.csc_array

Return CSC sparse array representation.

diagonal()

Return diagonal of self.

__mul__(other)

Multiply by scalar or numpy array treated as scalar along vector space dimensions.

__add__(other)

Add other operator.

__iadd__(other)

Add other operator in-place.

__sub__(other)

Subtract other operator.

__isub__(other)

Subtract other operator in-place.

apply(vec)

Apply operator on vector: self @ vec.

rapply(vec)

Apply transpose operator on vector: self.T @ vec.

inv()

Compute (multiplicative) inverse operator.

solve(vec)

Solve linear equation self @ x = vec for x.

chain(other)

Combine operators: self @ other.

trace()

Compute trace of self.

logdet()

Compute log(det(self)) assuming that self is a positive definite, real-symmetric matrix.

class dubfi.linalg.csc_sparse.CscTraceProdOperator(data, indices, indptr, symmetric=False)

Bases: dubfi.linalg.types.AbstractOperator

Auxiliary class used for computing trace products.

property shape

Shape of array (matrix) representation of self.

property symmetric

True if self equals its adjoint.

apply(vec)

Apply operator on vector: self @ vec.

rapply(vec)

Apply transpose operator on vector: self.T @ vec.

trace()

Compute trace of self.

trace_product(other)

Compute trace(self @ other).

tonumpy()

Numpy array (matrix) representation of self.

chain(other)

Combine operators: self @ other.

__mul__(other)

Multiply element-wise.

__imul__(other)

Multiply element-wise in-place.

abstractmethod solve(vec)

Solve linear equation self @ x = vec for x.

dot(other)

Inner product along non-vector dimensions.

__add__(other)

Add two linear operators.

__iadd__(other)

Add two linear operators in-place.

__sub__(other)

Subtract two linear operators.

__isub__(other)

Subtract two linear operators in-place.

dubfi.linalg.csc_sparse._csc_trace(data: numpy.ndarray, indices: numpy.ndarray, indptr: numpy.ndarray) numpy.ndarray

Compute trace of a matrix in compressed sparse column representation.

dubfi.linalg.csc_sparse.tr_asolver_bcsr(apply_a, data, indices, indptr)

Compute trace(A @ B) where Ax := apply_a(x) and B is represented as BSR (data, indices, indptr).

dubfi.linalg.csc_sparse.tr_asolver_bcsc(apply_a, data, indices, indptr)

Compute trace(A @ B) where Ax := apply_a(x) and B is represented as BSC (data, indices, indptr).

Note

This function assumes that apply_a is expensive. tr_asolver_bcsr() is generally more efficient.

dubfi.linalg.csc_sparse._csc_csr_trace_prod(data1: numpy.ndarray, indices1: numpy.ndarray, indptr1: numpy.ndarray, data2: numpy.ndarray, indices2: numpy.ndarray, indptr2: numpy.ndarray) numpy.ndarray

Compute trace(A @ B) represented as sparse CSC and CSR arrays.

Consider two sparse square matrices A and B of equal shape. Let (data1, indices1, indptr1) be the CSC representation of A and (data2, indices2, indptr2) be the CSR representation of B. Then this function returns (a @ b).trace().

This function assumes sorted indices!

class dubfi.linalg.csc_sparse.CscEnsLinPostR(h_ensemble: numpy.ndarray, loc: scipy.sparse.csc_array, regularization: float | numpy.ndarray = 0.0, bg_ens: numpy.ndarray | None = None, bc_ens: numpy.ndarray | None = None)

Bases: dubfi.linalg.generic.ParametrizedOperator

CSC representation of R matrix in flux inversion problem.

set_bg_ens(bg_ens: numpy.ndarray) None

Set the background (or total concentration) meteorological ensemble.

set_bc_ens(bc_ens: numpy.ndarray) None

Set boundary condition ensemble.

__call__(s)

Compute operator at given parameter vector s.

grad(s)

Gradient at given parameter vector s.

hess(s)

Hesse matrix at given parameter vector s.

dubfi.linalg.csc_sparse._r_csc_from_ens(loc_data, indices, indptr, h)

Construct ensemble contribution to R CSC data.

Given a localization in CSC format and the ensemble observation operator H, construct the CSC data for R, assuming it share the same CSC indices and indptr as the localization.

dubfi.linalg.csc_sparse._rgrad_csc_from_ens(loc_data, indices, indptr, h, h_ens)

Construct gradient of R CSC data.

Given a localization in CSC format and the ensemble observation operator H, construct the CSC data for grad(R), assuming it share the same CSC indices and indptr as the localization.

dubfi.linalg.csc_sparse._rhess_csc_from_ens(loc_data, indices, indptr, h_ens)

Construct Hesse matrix of R CSC data.

Given a localization in CSC format and the ensemble observation operator H, construct the CSC data for hess(R), assuming it share the same CSC indices and indptr as the localization.