def test_linear_adjoint(): A = np.random.rand(4, 3) x = np.random.rand(4) out = np.random.rand(3) Aop = MatVecOperator(A) xvec = Aop.range.element(x) outvec = Aop.domain.element() # Using inplace 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))
def test_type_errors(): r3 = odl.Rn(3) r4 = odl.Rn(4) Aop = MatVecOperator(np.random.rand(3, 3)) r3Vec1 = r3.zero() r3Vec2 = r3.zero() r4Vec1 = r4.zero() r4Vec2 = r4.zero() # Verify that correct usage works Aop(r3Vec1, r3Vec2) Aop.adjoint(r3Vec1, r3Vec2) # Test that erroneous usage raises TypeError with pytest.raises(OpDomainError): Aop(r4Vec1) with pytest.raises(OpDomainError): Aop.adjoint(r4Vec1) with pytest.raises(OpRangeError): Aop(r3Vec1, r4Vec1) with pytest.raises(OpRangeError): Aop.adjoint(r3Vec1, r4Vec1) with pytest.raises(OpDomainError): Aop(r4Vec1, r3Vec1) with pytest.raises(OpDomainError): Aop.adjoint(r4Vec1, r3Vec1) with pytest.raises(OpDomainError): Aop(r4Vec1, r4Vec2) with pytest.raises(OpDomainError): Aop.adjoint(r4Vec1, r4Vec2)