Exemplo n.º 1
0
    def test_submodule_tranpose(self):

        X = interface.aslinearoperator(np.array([[1, 2, 3], [4, 5, 6]]))
        Y = interface.aslinearoperator(np.array([[7, 8, 9], [10, 11, 12]]))
        Z = interface.aslinearoperator(np.array([[1, 2], [3, 4]]))

        u = [1, 2]

        assert_equal((X + Y).T * u, [36, 42, 48])
        assert_equal((Z * X).T * u, [47, 64, 81])
        assert_equal((2 * X).T * u, [18, 24, 30])
        assert_equal((Z**2).T * u, [37, 54])
Exemplo n.º 2
0
def test_dtypes_of_operator_sum():
    # gh-6078

    mat_complex = np.random.rand(2, 2) + 1j * np.random.rand(2, 2)
    mat_real = np.random.rand(2, 2)

    complex_operator = interface.aslinearoperator(mat_complex)
    real_operator = interface.aslinearoperator(mat_real)

    sum_complex = complex_operator + complex_operator
    sum_real = real_operator + real_operator

    assert_equal(sum_real.dtype, np.float64)
    assert_equal(sum_complex.dtype, np.complex128)
Exemplo n.º 3
0
    def test_basic(self):

        for M in self.cases:
            A = interface.aslinearoperator(M)
            M, N = A.shape

            assert_equal(A.matvec(np.array([1, 2, 3])), [14, 32])
            assert_equal(A.matvec(np.array([[1], [2], [3]])), [[14], [32]])

            assert_equal(A * np.array([1, 2, 3]), [14, 32])
            assert_equal(A * np.array([[1], [2], [3]]), [[14], [32]])

            assert_equal(A.rmatvec(np.array([1, 2])), [9, 12, 15])
            assert_equal(A.rmatvec(np.array([[1], [2]])), [[9], [12], [15]])
            assert_equal(A.H.matvec(np.array([1, 2])), [9, 12, 15])
            assert_equal(A.H.matvec(np.array([[1], [2]])), [[9], [12], [15]])
            assert_equal(A.T.matvec(np.array([1, 2])), [9, 12, 15])
            assert_equal(A.T.matvec(np.array([[1], [2]])), [[9], [12], [15]])

            assert_equal(A.matmat(np.array([[1, 4], [2, 5], [3, 6]])),
                         [[14, 32], [32, 77]])

            assert_equal(A.T.matmat(np.array([[1, 2], [3, 4]])),
                         [[13, 18], [17, 24], [21, 30]])

            assert_equal(A * np.array([[1, 4], [2, 5], [3, 6]]),
                         [[14, 32], [32, 77]])

            if hasattr(M, 'dtype'):
                assert_equal(A.dtype, M.dtype)
Exemplo n.º 4
0
def test_attributes():
    A = interface.aslinearoperator(np.arange(16).reshape(4, 4))

    def always_four_ones(x):
        x = np.asarray(x)
        assert_(x.shape == (3, ) or x.shape == (3, 1))
        return np.ones(4)

    B = interface.LinearOperator(shape=(4, 3), matvec=always_four_ones)

    for op in [A, B, A * B, A.H, A + A, B + B, A**4]:
        assert_(hasattr(op, "dtype"))
        assert_(hasattr(op, "shape"))
        assert_(hasattr(op, "_matvec"))
Exemplo n.º 5
0
    def test_dot(self):

        for M in self.cases:
            A = interface.aslinearoperator(M)
            M, N = A.shape

            assert_equal(A.dot(np.array([1, 2, 3])), [14, 32])
            assert_equal(A.dot(np.array([[1], [2], [3]])), [[14], [32]])

            assert_equal(A.dot(np.array([[1, 4], [2, 5], [3, 6]])),
                         [[14, 32], [32, 77]])

            assert_equal(A.T.dot(np.array([[1, 2], [3, 4]])),
                         [[13, 18], [17, 24], [21, 30]])