xref: /libCEED/tests/t301-basis.c (revision b0d170e7bc2e5c930ee481a47eb73044935a48a4)
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++) A_qr[i * 3 + j] = qr[i * 3 + j];
20   }
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 "] = %f != A[%" CeedInt_FMT "] = %f\n", i, A_qr[i], i, A[i]);
27       // LCOV_EXCL_STOP
28     }
29   }
30 
31   CeedDestroy(&ceed);
32   return 0;
33 }
34