def test_P(): """Test permutation matrix _P(m)""" Pm0 = _P(m) X = np.random.normal(0.0, 1.0, (N, m, 1)) Y = np.random.normal(0.0, 1.0, (N, m, 1)) assert (Pm0.shape == (m**2, m**2)) assert (np.allclose(Pm0, Pm0.T)) # symmetric assert (np.allclose(np.dot(Pm0, Pm0), np.eye(m**2))) # is its own inverse Pm = broadcast_to(Pm0, (N, m**2, m**2)) for n in range(0, N): assert (np.allclose(np.dot(Pm0, np.kron(X[n, :, 0], Y[n, :, 0])), np.kron(Y[n, :, 0], X[n, :, 0]))) # next line is equivalent to the previous 3 lines: assert (np.allclose(_dot(Pm, _kp(X, Y)), _kp(Y, X)))
def test_P(): """Test permutation matrix _P(m)""" Pm0 = _P(m) X = np.random.normal(0.0, 1.0, (N, m, 1)) Y = np.random.normal(0.0, 1.0, (N, m, 1)) assert(Pm0.shape == (m**2, m**2)) assert(np.allclose(Pm0, Pm0.T)) # symmetric assert(np.allclose(np.dot(Pm0, Pm0), np.eye(m**2))) # is its own inverse Pm = broadcast_to(Pm0, (N, m**2, m**2)) for n in range(0, N): assert(np.allclose(np.dot(Pm0, np.kron(X[n,:,0], Y[n,:,0])), np.kron(Y[n,:,0], X[n,:,0]))) # next line is equivalent to the previous 3 lines: assert(np.allclose(_dot(Pm, _kp(X, Y)), _kp(Y, X)))
def test_kp(): """Test our special case Kronecker tensor product function _kp() by comparing it against the built-in numpy function np.kron() """ X = np.random.normal(0.0, 1.0, (N, m, 1)) Y = np.random.normal(0.0, 1.0, (N, m, 1)) XkY = _kp(X, Y) for n in range(0, N): assert (np.allclose(np.kron(X[n, :, 0], Y[n, :, 0]), XkY[n, :, 0]))
def test_kp(): """Test our special case Kronecker tensor product function _kp() by comparing it against the built-in numpy function np.kron() """ X = np.random.normal(0.0, 1.0, (N, m, 1)) Y = np.random.normal(0.0, 1.0, (N, m, 1)) XkY = _kp(X, Y) for n in range(0, N): assert(np.allclose(np.kron(X[n,:,0], Y[n,:,0]), XkY[n,:,0]))