|
2 | 2 | import numpy as np |
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from probnum import linops, randvars |
| 5 | +from probnum import backend, linops, randvars |
6 | 6 | from probnum.problems.zoo.linalg import random_spd_matrix |
7 | 7 | from probnum.typing import ShapeArgType |
| 8 | +from tests.testing import seed_from_args |
8 | 9 |
|
9 | 10 |
|
10 | 11 | @pytest.fixture |
11 | | -def rng() -> np.random.Generator: |
12 | | - return np.random.default_rng(42) |
| 12 | +def constant(shape_const: ShapeArgType) -> randvars.Constant: |
| 13 | + seed = seed_from_args(shape_const, 19836) |
13 | 14 |
|
14 | | - |
15 | | -@pytest.fixture |
16 | | -def constant(shape_const: ShapeArgType, rng: np.random.Generator) -> randvars.Constant: |
17 | | - return randvars.Constant(support=rng.normal(size=shape_const)) |
| 15 | + return randvars.Constant( |
| 16 | + support=backend.random.standard_normal(seed, shape=shape_const) |
| 17 | + ) |
18 | 18 |
|
19 | 19 |
|
20 | 20 | @pytest.fixture |
21 | 21 | def multivariate_normal( |
22 | | - shape: ShapeArgType, precompute_cov_cholesky: bool, rng: np.random.Generator |
| 22 | + shape: ShapeArgType, precompute_cov_cholesky: bool |
23 | 23 | ) -> randvars.Normal: |
| 24 | + seed = seed_from_args(shape, precompute_cov_cholesky, 1908) |
| 25 | + seed_mean, seed_cov = backend.random.split(seed) |
| 26 | + |
24 | 27 | rv = randvars.Normal( |
25 | | - mean=rng.normal(size=shape), |
26 | | - cov=random_spd_matrix(rng=rng, dim=shape[0]), |
| 28 | + mean=backend.random.standard_normal(seed_mean, shape=shape), |
| 29 | + cov=random_spd_matrix(seed_cov, dim=shape[0]), |
27 | 30 | ) |
28 | 31 | if precompute_cov_cholesky: |
29 | | - rv.precompute_cov_cholesky() |
| 32 | + rv.compute_cov_cholesky() |
30 | 33 | return rv |
31 | 34 |
|
32 | 35 |
|
33 | 36 | @pytest.fixture |
34 | 37 | def matrixvariate_normal( |
35 | | - shape: ShapeArgType, precompute_cov_cholesky: bool, rng: np.random.Generator |
| 38 | + shape: ShapeArgType, precompute_cov_cholesky: bool |
36 | 39 | ) -> randvars.Normal: |
| 40 | + seed = seed_from_args(shape, precompute_cov_cholesky, 354) |
| 41 | + seed_mean, seed_cov_A, seed_cov_B = backend.random.split(seed, num=3) |
| 42 | + |
37 | 43 | rv = randvars.Normal( |
38 | | - mean=rng.normal(size=shape), |
| 44 | + mean=backend.random.standard_normal(seed_mean, shape=shape), |
39 | 45 | cov=linops.Kronecker( |
40 | | - A=random_spd_matrix(dim=shape[0], rng=rng), |
41 | | - B=random_spd_matrix(dim=shape[1], rng=rng), |
| 46 | + A=random_spd_matrix(seed_cov_A, dim=shape[0]), |
| 47 | + B=random_spd_matrix(seed_cov_B, dim=shape[1]), |
42 | 48 | ), |
43 | 49 | ) |
44 | 50 | if precompute_cov_cholesky: |
45 | | - rv.precompute_cov_cholesky() |
| 51 | + rv.compute_cov_cholesky() |
46 | 52 | return rv |
47 | 53 |
|
48 | 54 |
|
49 | 55 | @pytest.fixture |
50 | 56 | def symmetric_matrixvariate_normal( |
51 | | - shape: ShapeArgType, precompute_cov_cholesky: bool, rng: np.random.Generator |
| 57 | + shape: ShapeArgType, precompute_cov_cholesky: bool |
52 | 58 | ) -> randvars.Normal: |
| 59 | + seed = seed_from_args(shape, precompute_cov_cholesky, 246) |
| 60 | + seed_mean, seed_cov = backend.random.split(seed) |
| 61 | + |
53 | 62 | rv = randvars.Normal( |
54 | | - mean=random_spd_matrix(dim=shape[0], rng=rng), |
55 | | - cov=linops.SymmetricKronecker(A=random_spd_matrix(dim=shape[0], rng=rng)), |
| 63 | + mean=random_spd_matrix(seed_mean, dim=shape[0]), |
| 64 | + cov=linops.SymmetricKronecker(A=random_spd_matrix(seed_cov, dim=shape[0])), |
56 | 65 | ) |
57 | 66 | if precompute_cov_cholesky: |
58 | | - rv.precompute_cov_cholesky() |
| 67 | + rv.compute_cov_cholesky() |
59 | 68 | return rv |
0 commit comments