utils — Testing and analysis utilities¶
Testing¶
- allclose(a: Array, b: Array, rtol: float = 1e-5, atol: float = 1e-8) bool[source]¶
Array-namespace agnostic equivalent of np.allclose.
Works for scalars (0-d arrays) and multi-dimensional arrays alike.
- dottest(linop: LinOp, num: int = 1, rtol: float = 1e-5, atol: float = 1e-8, echo: bool = False, xp=np) bool[source]¶
The dot test.
Verify the validity of forward and adjoint methods with equality
(Aᴴ·u)ᴴ·v = uᴴ·(A·v).
where u and v are random vectors, to detect errors in implementation.
- Parameters:
linop (LinOp) – The linear operator to test.
num (int, optional) – The number of tests. They must all pass.
rtol (float, optional) – The relative tolerance parameter (see allclose).
atol (float, optional) – The absolute tolerance parameter (see allclose).
echo (bool, optional) – If True, print the two sides of the equality for each test.
xp (array namespace, optional) – The array namespace for generating test vectors (default: numpy).
- Returns:
True if all num tests pass.
- Return type:
Notes
Numpy is used for random number generation; arrays are converted to xp if xp is not numpy.
- fwadjtest(linop: LinOp, num: int = 1, rtol: float = 1e-5, atol: float = 1e-8, echo: bool = False, xp=np) bool[source]¶
Test fwadj validity.
Verify the validity of fwadj wrt. forward and adjoint methods with equality
(Aᴴ·A)·v = Aᴴ·(A·v).
where v is a random vector, to detect errors in implementation.
- Parameters:
linop (LinOp) – The linear operator to test.
num (int, optional) – The number of tests. They must all pass.
rtol (float, optional) – The relative tolerance parameter (see allclose).
atol (float, optional) – The absolute tolerance parameter (see allclose).
echo (bool, optional) – If True, print the two sides of the equality for each test.
xp (array namespace, optional) – The array namespace for generating test vectors (default: numpy).
- Returns:
True if all num tests pass.
- Return type:
Matrix properties¶
- is_pos_def(linop: Array | LinOp) bool[source]¶
Return True if linop is positive definite.
- linopArray or LinOp
The operator or matrix to test.
bool
A positive definite matrix $M$ has strictly positive eigenvalues, but the converse is not true for non-symmetric matrices. The function therefore tests all eigenvalues of $M + M^T$: since $x^T M x = x^T
- rac{M + M^T}{2} x$
for any vector $x$, positive definiteness of $M$ is equivalent to positive definiteness of $M + M^T$.
- is_semi_pos_def(linop: Array | LinOp) bool[source]¶
Return True if linop is semi positive definite.
See also
Condition number¶
- cond(linop: Array | LinOp) float[source]¶
Return the condition number κ.
The condition number κ is defined as:
κ = max(|λ|) / min(|λ|)
where λ are eigenvalues of linop.