def random_bi_diagonalizable_pair( n: int, d1: Optional[int] = None, d2: Optional[int] = None) -> Tuple[np.ndarray, np.ndarray]: u = testing.random_orthogonal(n) s = random_real_diagonal_matrix(n, d1) z = random_real_diagonal_matrix(n, d2) v = testing.random_orthogonal(n) a = combinators.dot(u, s, v) b = combinators.dot(u, z, v) return a, b
def test_random_orthogonal(): o1 = random_orthogonal(2) o2 = random_orthogonal(2) assert is_orthogonal(o1) assert is_orthogonal(o2) assert not np.allclose(o1, o2)
def test_bidiagonalize_real_matrix_pair_with_symmetric_products(a, b): a = np.array(a) b = np.array(b) p, q = diagonalize.bidiagonalize_real_matrix_pair_with_symmetric_products( a, b) assert_bidiagonalized_by(a, p, q) assert_bidiagonalized_by(b, p, q) @pytest.mark.parametrize('a,b', [ [X, Z], [Y, np.eye(2)], [np.eye(2), Y], [np.eye(5), np.eye(4)], [ e * testing.random_orthogonal(4) for e in random_bi_diagonalizable_pair(4) ], [ testing.random_orthogonal(4) * e for e in random_bi_diagonalizable_pair(4) ], ]) def test_bidiagonalize_real_fails(a, b): a = np.array(a) b = np.array(b) with pytest.raises(ValueError): diagonalize.bidiagonalize_real_matrix_pair_with_symmetric_products( a, b)
def test_random_orthogonal_deterministic_given_seed(): o1 = random_orthogonal(2, random_state=1234) o2 = random_orthogonal(2, random_state=1234) np.testing.assert_equal(o1, o2)