1 /// @file 2 /// Test QR Factorization 3 /// \test Test QR Factorization 4 #include <ceed.h> 5 #include <ceed/backend.h> 6 #include <math.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedScalar A[12] = {1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0}; 11 CeedScalar qr[12] = {1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0}; 12 CeedScalar A_qr[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 13 CeedScalar tau[4]; 14 15 CeedInit(argv[1], &ceed); 16 17 CeedQRFactorization(ceed, qr, tau, 4, 3); 18 for (CeedInt i=0; i<3; i++) 19 for (CeedInt j=i; j<3; j++) 20 A_qr[i*3+j] = qr[i*3+j]; 21 CeedHouseholderApplyQ(A_qr, qr, tau, CEED_NOTRANSPOSE, 4, 3, 3, 3, 1); 22 23 for (CeedInt i=0; i<12; i++) 24 if (fabs(A_qr[i] - A[i]) > 100.*CEED_EPSILON) 25 // LCOV_EXCL_START 26 printf("Error in QR factorization A_qr[%" CeedInt_FMT 27 "] = %f != A[%" CeedInt_FMT "] = %f\n", i, A_qr[i], i, A[i]); 28 // LCOV_EXCL_STOP 29 30 CeedDestroy(&ceed); 31 return 0; 32 } 33