discretize.tests.assert_isadjoint#

discretize.tests.assert_isadjoint(forward, adjoint, shape_u, shape_v, complex_u=False, complex_v=False, clinear=True, rtol=1e-06, atol=0.0, assert_error=True, random_seed=None)[source]#

Do a dot product test for the forward operator and its adjoint operator.

Dot product test to verify the correctness of the adjoint operator \(F^H\) of the forward operator \(F\).

\[\mathbf{v}^H ( \mathbf{F} \mathbf{u} ) = ( \mathbf{F}^H \mathbf{v} )^H \mathbf{u}\]
Parameters:
forwardcallable()

Forward operator.

adjointcallable()

Adjoint operator.

shape_uint, tuple of int

Shape of vector u passed in to forward; it is accordingly the expected shape of the vector returned from the adjoint.

shape_vint, tuple of int

Shape of vector v passed in to adjoint; it is accordingly the expected shape of the vector returned from the forward.

complex_ubool, default: False

If True, vector u passed to forward is a complex vector; accordingly the adjoint is expected to return a complex vector.

complex_vbool, default: False

If True, vector v passed to adjoint is a complex vector; accordingly the forward is expected to return a complex vector.

clinearbool, default: True

If operator is complex-linear (True) or real-linear (False).

rtolfloat, default: 1e-6

Relative tolerance.

atolfloat, default: 0.0

Absolute tolerance.

assert_errorbool, default: True

By default this test is an assertion (silent if passed, raising an assertion error if failed). If set to False, the result of the test is returned as boolean and a message is printed.

random_seednumpy.random.Generator, int, optional

The random number generator to use for the adjoint test. If an integer or None it is used to seed a new numpy.random.default_rng.

Returns:
passedbool, optional

Result of the dot product test; only returned if assert_error is False.

Raises:
AssertionError

If the dot product test fails (only if assert_error=True).