def case_spd_linsys( spd_matrix: Union[np.ndarray, scipy.sparse.spmatrix, linops.LinearOperator], rng: np.random.Generator, ) -> problems.LinearSystem: """Linear system with symmetric positive definite matrix.""" return random_linear_system(rng=rng, matrix=spd_matrix)
def test_custom_solution_randvar(rng: np.random.Generator): n = 5 x = randvars.Normal(mean=np.ones(n), cov=np.eye(n)) _ = random_linear_system(rng=rng, matrix=random_spd_matrix, solution_rv=x, dim=n)
def test_incompatible_matrix_and_solution(rng: np.random.Generator): with pytest.raises(ValueError): _ = random_linear_system( rng=rng, matrix=random_spd_matrix, solution_rv=randvars.Normal(np.ones(2), np.eye(2)), dim=5, )
"""Probabilistic linear solver state test cases.""" import numpy as np from pytest_cases import case from probnum import linalg, linops, randvars from probnum.problems.zoo.linalg import random_linear_system, random_spd_matrix # Problem n = 10 linsys = random_linear_system( rng=np.random.default_rng(42), matrix=random_spd_matrix, dim=n ) # Prior Ainv = randvars.Normal( mean=linops.Identity(n), cov=linops.SymmetricKronecker(linops.Identity(n)) ) b = randvars.Constant(linsys.b) prior = linalg.solvers.beliefs.LinearSystemBelief( A=randvars.Constant(linsys.A), Ainv=Ainv, x=(Ainv @ b[:, None]).reshape( (n,) ), # TODO: This can be replaced by Ainv @ b once https://github.com/probabilistic-numerics/probnum/issues/456 is fixed b=b, ) @case(tags=["initial"]) def case_initial_state(
def case_linsys( matrix: Union[np.ndarray, scipy.sparse.spmatrix, linops.LinearOperator], rng: np.random.Generator, ) -> problems.LinearSystem: """Linear system.""" return random_linear_system(rng=rng, matrix=matrix)
def test_custom_random_matrix(rng: np.random.Generator): random_unitary_matrix = lambda rng, dim: scipy.stats.unitary_group.rvs( dim=dim, random_state=rng) _ = random_linear_system(rng, random_unitary_matrix, dim=5)