Next: The word adjoint'' Up: ADJOINT DEFINED: DOT-PRODUCT TEST Previous: Definition of a vector

## Dot-product test for validity of an adjoint

There is a huge gap between the conception of an idea and putting it into practice. During development, things fail far more often than not. Often, when something fails, many tests are needed to track down the cause of failure. Maybe the cause cannot even be found. More insidiously, failure may be below the threshold of detection and poor performance suffered for years. The dot-product test enables us to ascertain whether the program for the adjoint of an operator is precisely consistent with the operator itself. It can be, and it should be.

Conceptually, the idea of matrix transposition is simply . In practice, however, we often encounter matrices far too large to fit in the memory of any computer. Sometimes it is also not obvious how to formulate the process at hand as a matrix multiplication. (Examples are differential equations and fast Fourier transforms.) What we find in practice is that an application and its adjoint amounts to two routines. The first routine amounts to the matrix multiplication . The adjoint routine computes , where is the conjugate-transpose matrix. In later chapters we will be solving huge sets of simultaneous equations, in which both routines are required. If the pair of routines are inconsistent, we are doomed from the start. The dot-product test is a simple test for verifying that the two routines are adjoint to each other.

The associative property of linear algebra says that we do not need parentheses in a vector-matrix-vector product like because we get the same result no matter where we put the parentheses. They serve only to determine the sequence of computation. Thus,

 (29) (30)

(In general, the matrix is not square.) To perform the dot-product test, load the vectors and with random numbers. Using your program for , compute the vector , and using your program for , compute . Inserting these into equation (30) gives you two scalars that should be equal.
 (31)

The left and right sides of this equation will be computationally equal only if the program doing is indeed adjoint to the program doing (unless the random numbers do something miraculous). A final word: If an operator uses complex arithmetic then both its input and output are in the field of complex numbers.'' The conversion between real and complex numbers is not a linear operator despite its seeming similarity to truncation and zero padding.

The program for applying the dot product test is dottest . The C way of passing a linear operator as an argument is to specify the function interface. Fortunately, we have already defined the interface for a generic linear operator. To use the dottest program, you need to initialize an operator with specific arguments (the _init subroutine) and then pass the operator itself (the _lop function) to the test program. You also need to specify the sizes of the model and data vectors so that temporary arrays can be constructed. The program runs the dot product test twice, second time with add = true to test if the operator can be used properly for accumulating the result like .

api/c/dottest.c
  oper(false, false, nm, nd, mod1, dat1); dot1[0] = cblas_dsdot( nd, dat1, 1, dat2, 1); oper(true, false, nm, nd, mod2, dat2); dot1[1] = cblas_dsdot( nm, mod1, 1, mod2, 1); oper(false, true, nm, nd, mod1, dat1); dot2[0] = cblas_dsdot( nd, dat1, 1, dat2, 1); oper(true, true, nm, nd, mod2, dat2); dot2[1] = cblas_dsdot( nm, mod1, 1, mod2, 1); 

I tested (31) on many operators and was surprised and delighted to find that it is often satisfied to an accuracy near the computing precision. I do not doubt that larger rounding errors could occur, but so far, every time I encountered a relative discrepancy of or more, I was later able to uncover a conceptual or programming error. Naturally, when I do dot-product tests, I scale the implied matrix to a small dimension in order to speed things along, and to be sure that boundaries are not overwhelmed by the much larger interior.

Do not be alarmed if the operator you have defined has truncation errors. Such errors in the definition of the original operator should be identically matched by truncation errors in the adjoint operator. If your code passes the dot-product test, then you really have coded the adjoint operator. In that case, to obtain inverse operators, you can take advantage of the standard methods of mathematics.

We can speak of a continuous function or a discrete function . For continuous functions we use integration, and for discrete ones we use summation. In formal mathematics, the dot-product test defines the adjoint operator, except that the summation in the dot product may need to be changed to an integral. The input or the output or both can be given either on a continuum or in a discrete domain. So the dot-product test could have an integration on one side of the equal sign and a summation on the other. Linear-operator theory is rich with concepts not developed here.

Next: The word adjoint'' Up: ADJOINT DEFINED: DOT-PRODUCT TEST Previous: Definition of a vector