def test_fixed_disp_adj(space): """Verify that the adjoint of LinDeformFixedDisp is correct.""" # Set up template and displacement field template = space.element(template_function) disp_field = space.real_space.tangent_bundle.element( disp_field_factory(space.ndim)) # Calculate result deform_op = LinDeformFixedDisp(disp_field, templ_space=space) deformed_templ_adj = deform_op.adjoint(template) # Calculate the analytic result true_deformed_templ_adj = space.element(inv_deformed_template) exp_div = space.element(exp_div_inv_disp) true_deformed_templ_adj *= exp_div # Verify that the result is within error limits error = (deformed_templ_adj - true_deformed_templ_adj).norm() rel_err = error / true_deformed_templ_adj.norm() assert rel_err < error_bound(space.interp) # Verify the adjoint definition <Ax, x> = <x, A^* x> deformed_templ = deform_op(template) inner1 = deformed_templ.inner(template) inner2 = template.inner(deformed_templ_adj) assert almost_equal(inner1, inner2, places=1)
def test_fixed_disp_init(): """Verify that the init method and checks work properly.""" space = odl.uniform_discr(0, 1, 5) disp_field = space.tangent_bundle.element(disp_field_factory(space.ndim)) # Valid input print(LinDeformFixedDisp(disp_field)) print(LinDeformFixedDisp(disp_field, templ_space=space)) # Non-valid input with pytest.raises(TypeError): # displacement not ProductSpaceElement LinDeformFixedDisp(space.one()) with pytest.raises(TypeError): # templ_space not DiscreteLp LinDeformFixedDisp(disp_field, space.tangent_bundle) with pytest.raises(TypeError): # templ_space not a power space bad_pspace = odl.ProductSpace(space, odl.rn(3)) LinDeformFixedDisp(disp_field, bad_pspace) with pytest.raises(TypeError): # templ_space not based on DiscreteLp bad_pspace = odl.ProductSpace(odl.rn(2), 1) LinDeformFixedDisp(disp_field, bad_pspace) with pytest.raises(TypeError): # wrong dtype on templ_space wrong_dtype = odl.ProductSpace(space.astype(complex), 1) LinDeformFixedDisp(disp_field, wrong_dtype) with pytest.raises(ValueError): # vector field spaces don't match bad_space = odl.uniform_discr(0, 1, 10) LinDeformFixedDisp(disp_field, bad_space)
def test_fixed_disp_init(): """Test init and props of lin. deformation with fixed displacement.""" space = odl.uniform_discr(0, 1, 5) disp_field = space.tangent_bundle.element(disp_field_factory(space.ndim)) # Valid input op = LinDeformFixedDisp(disp_field) assert repr(op) != '' op = LinDeformFixedDisp(disp_field, templ_space=space) assert repr(op) != '' # Non-valid input with pytest.raises(TypeError): # displacement not ProductSpaceElement LinDeformFixedDisp(space.one()) with pytest.raises(TypeError): # templ_space not DiscretizedSpace LinDeformFixedDisp(disp_field, space.tangent_bundle) with pytest.raises(TypeError): # templ_space not a power space bad_pspace = odl.ProductSpace(space, odl.rn(3)) LinDeformFixedDisp(disp_field, bad_pspace) with pytest.raises(TypeError): # templ_space not based on DiscretizedSpace bad_pspace = odl.ProductSpace(odl.rn(2), 1) LinDeformFixedDisp(disp_field, bad_pspace) with pytest.raises(TypeError): # wrong dtype on templ_space wrong_dtype = odl.ProductSpace(space.astype(complex), 1) LinDeformFixedDisp(disp_field, wrong_dtype) with pytest.raises(ValueError): # vector field spaces don't match bad_space = odl.uniform_discr(0, 1, 10) LinDeformFixedDisp(disp_field, bad_space)
def test_fixed_disp_inv(space): """Verify that the inverse of LinDeformFixedDisp is correct.""" # Set up template and displacement field template = space.element(template_function) disp_field = space.real_space.tangent_bundle.element( disp_field_factory(space.ndim)) # Verify that the inverse is in fact a (left and right) inverse deform_op = LinDeformFixedDisp(disp_field, templ_space=space) result_op_inv = deform_op(deform_op.inverse(template)) error = (result_op_inv - template).norm() rel_err = error / template.norm() assert rel_err < 2 * error_bound(space.interp) # need a bit more tolerance result_inv_op = deform_op.inverse(deform_op(template)) error = (result_inv_op - template).norm() rel_err = error / template.norm() assert rel_err < 2 * error_bound(space.interp) # need a bit more tolerance
def test_fixed_disp_call(space): """Verify that LinDeformFixedDisp produces the correct deformation.""" template = space.element(template_function) disp_field = space.real_space.tangent_bundle.element( disp_field_factory(space.ndim)) # Calculate result and exact result deform_op = LinDeformFixedDisp(disp_field, templ_space=space) deformed_templ = deform_op(template) true_deformed_templ = space.element(deformed_template) # Verify that the result is within error limits error = (true_deformed_templ - deformed_templ).norm() rlt_err = error / deformed_templ.norm() assert rlt_err < error_bound(space.interp)