Exemplo n.º 1
0
def test_linear_adjoint():
    A = np.random.rand(4, 3)
    x = np.random.rand(4)
    out = np.random.rand(3)

    Aop = MatrixOperator(A)
    xvec = Aop.range.element(x)
    outvec = Aop.domain.element()

    # Using in-place adjoint
    Aop.adjoint(xvec, outvec)
    np.dot(A.T, x, out)
    assert all_almost_equal(out, outvec)

    # Using out-of-place method
    assert all_almost_equal(Aop.adjoint(xvec), np.dot(A.T, x))
Exemplo n.º 2
0
def test_type_errors():
    r3 = odl.rn(3)
    r4 = odl.rn(4)

    op = MatrixOperator(np.random.rand(3, 3))
    r3_elem1 = r3.zero()
    r3_elem2 = r3.zero()
    r4_elem1 = r4.zero()
    r4_elem2 = r4.zero()

    # Verify that correct usage works
    op(r3_elem1, r3_elem2)
    op.adjoint(r3_elem1, r3_elem2)

    # Test that erroneous usage raises
    with pytest.raises(OpDomainError):
        op(r4_elem1)

    with pytest.raises(OpDomainError):
        op.adjoint(r4_elem1)

    with pytest.raises(OpRangeError):
        op(r3_elem1, r4_elem1)

    with pytest.raises(OpRangeError):
        op.adjoint(r3_elem1, r4_elem1)

    with pytest.raises(OpDomainError):
        op(r4_elem1, r3_elem1)

    with pytest.raises(OpDomainError):
        op.adjoint(r4_elem1, r3_elem1)

    with pytest.raises(OpDomainError):
        op(r4_elem1, r4_elem2)

    with pytest.raises(OpDomainError):
        op.adjoint(r4_elem1, r4_elem2)