def test_spd_inv_split_nocutoff(): x = np.random.normal(size=(5, 5)) unitary = np.linalg.qr(x)[0] assert_array_almost_equal(unitary @ unitary.T, np.eye(5)) spd = unitary @ np.diag([1., 2., 3., 4., 5.]) @ unitary.T w, _ = np.linalg.eigh(spd) L = spd_inv_split(spd, epsilon=0) spd_inv = L @ L.T assert_array_almost_equal(spd_inv, np.linalg.pinv(spd))
def test_spd_inv_split(spd_matrix, epsilon, method, canonical_signs): split = spd_inv_split(spd_matrix, epsilon=epsilon, method=method, canonical_signs=canonical_signs) spd_matrix_inv = split @ split.T sminv, _ = spd_eig(spd_matrix_inv) sm, _ = spd_eig(spd_matrix) assert_array_almost_equal(np.sort(sm), np.sort(1. / sminv)[-3:]) if canonical_signs: for i in range(3): assert_(np.max(split[:, i]) > 0)
def test_spd_inv_splid_1d(): W = np.array([[.5]]) assert_almost_equal(spd_inv_split(W).squeeze(), 1. / np.sqrt(.5)) with assert_raises(ZeroRankError): spd_inv_split(np.array([[.001]]), epsilon=.01)