1 /// @file 2 /// Test vector norms 3 /// \test Test vector norms 4 #include <ceed.h> 5 #include <math.h> 6 7 int main(int argc, char **argv) { 8 Ceed ceed; 9 CeedVector x; 10 CeedInt n = 10; 11 CeedScalar a[10]; 12 13 CeedInit(argv[1], &ceed); 14 15 CeedVectorCreate(ceed, n, &x); 16 for (CeedInt i=0; i<n; i++) 17 a[i] = i * (i % 2 ? 1 : -1); 18 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 19 20 CeedScalar norm; 21 CeedVectorNorm(x, CEED_NORM_1, &norm); 22 if (fabs(norm - 45.) > 1e-14) 23 // LCOV_EXCL_START 24 printf("Error: L1 norm %f != 45.\n", norm); 25 // LCOV_EXCL_STOP 26 27 CeedVectorNorm(x, CEED_NORM_2, &norm); 28 if (fabs(norm - sqrt(285.)) > 1e-14) 29 // LCOV_EXCL_START 30 printf("Error: L2 norm %f != sqrt(285.)\n", norm); 31 // LCOV_EXCL_STOP 32 33 CeedVectorNorm(x, CEED_NORM_MAX, &norm); 34 if (fabs(norm - 9.) > 1e-14) 35 // LCOV_EXCL_START 36 printf("Error: Max norm %f != 9.\n", norm); 37 // LCOV_EXCL_STOP 38 39 CeedVectorDestroy(&x); 40 CeedDestroy(&ceed); 41 return 0; 42 } 43