13 template <
typename dtype>
    28   E[
"ij"] -= Q[
"ki"]*conj<dtype>(Q)[
"kj"];
    30   bool pass_orthogonality = 
true;
    35     pass_orthogonality = 
false;
    38   A[
"ij"] -= Q[
"ik"]*R[
"kj"];
    40   bool pass_residual = 
true;
    42   if (nrm > m*n*n*1.E-6){
    43     pass_residual = 
false;
    48     printf(
"QR orthogonality check returned %d, residual check %d\n", pass_orthogonality, pass_residual);
    51   return pass_residual & pass_orthogonality;
    60   pass = pass & qr<float>(A,m,n,dw);
    66   pass = pass & qr<double>(B,m,n,dw);
    70   pass = pass & qr<std::complex<float>>(cA,m,n,dw);
    75   pass = pass & qr<std::complex<double>>(cB,m,n,dw);
    78       printf(
"{ A = QR and Q^TQ = I } passed\n");
    80       printf(
"{ A = QR and Q^TQ = I } failed\n");
    92   char ** itr = std::find(begin, end, option);
    93   if (itr != end && ++itr != end){
   100 int main(
int argc, 
char ** argv){
   102   int const in_num = argc;
   103   char ** input_str = argv;
   105   MPI_Init(&argc, &argv);
   106   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   107   MPI_Comm_size(MPI_COMM_WORLD, &np);
   110     m = atoi(
getCmdOption(input_str, input_str+in_num, 
"-m"));
   116     n = atoi(
getCmdOption(input_str, input_str+in_num, 
"-n"));
   122     World dw(argc, argv);
   125       printf(
"Testing %d-by-%d QR factorization\n", m, n);
 
bool qr(Matrix< dtype > A, int m, int n, World &dw)
void qr(Matrix< dtype > &Q, Matrix< dtype > &R)
Matrix class which encapsulates a 2D tensor. 
an instance of the CTF library (world) on a MPI communicator 
dtype norm2()
computes the frobenius norm of the tensor (needs sqrt()!) 
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
int rank
rank of local processor 
int main(int argc, char **argv)
char * getCmdOption(char **begin, char **end, const std::string &option)
bool test_qr(int m, int n, World dw)