Statistical Methods
Validate a Matrix-Free Operator's Contract
Define the task
A matrix-free operator supplies matrix-vector products without storing every matrix entry. This can reduce storage in iterative algorithms, but it shifts validation responsibility to the supplied function. Declare input and output dimensions, data type and whether an adjoint operation is provided. A function that accepts a vector is not necessarily linear. Parameters and hidden state must remain consistent throughout a solve; silently changing them changes the problem.
Carry out the check
Test additivity A(u+v)=Au+Av and scaling A(cu)=cAu on several synthetic inputs with scale-aware tolerances. Compare with an explicitly constructed small matrix where possible. If supplying an adjoint, check the inner-product relation against independent vectors and use conjugation correctly for complex values. Verify shape handling, including a column-vector input where required by the library contract. These tests detect implementation mistakes but do not prove correctness for every possible input or establish positive definiteness.
Worked hypothetical example
For hypothetical A(x1,x2)=(2x1+x2,3x2), u=(1,0) and v=(0,1), outputs are Au=(2,0), Av=(1,3), and A(u+v)=(3,3), matching their sum. Its transpose maps (a,b) to (2a,a+3b). In contrast, adding a fixed one to every output breaks linearity because A(0) is then nonzero. Save these reference calculations and rerun operator tests when indexing, scaling or boundary logic changes.
Method checked 21 November 2026 against Primary method documentation: LinearOperator.