1 /// @file 2 /// Test taking the reciprocal of a vector 3 /// \test Test taking the reciprocal of a vector 4 #include <ceed.h> 5 #include <math.h> 6 #include <stdio.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedVector x; 11 CeedInt len = 10; 12 13 CeedInit(argv[1], &ceed); 14 15 CeedVectorCreate(ceed, len, &x); 16 { 17 CeedScalar array[len]; 18 19 for (CeedInt i = 0; i < len; i++) array[i] = len + i; 20 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array); 21 } 22 { 23 // Sync memtype to device for GPU backends 24 CeedMemType type = CEED_MEM_HOST; 25 CeedGetPreferredMemType(ceed, &type); 26 CeedVectorSyncArray(x, type); 27 } 28 CeedVectorReciprocal(x); 29 30 { 31 const CeedScalar *read_array; 32 33 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array); 34 for (CeedInt i = 0; i < len; i++) { 35 if (fabs(read_array[i] - 1. / (len + i)) > 10. * CEED_EPSILON) { 36 // LCOV_EXCL_START 37 printf("Error taking reciprocal, array[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)read_array[i]); 38 // LCOV_EXCL_STOP 39 } 40 } 41 CeedVectorRestoreArrayRead(x, &read_array); 42 } 43 44 CeedVectorDestroy(&x); 45 CeedDestroy(&ceed); 46 return 0; 47 } 48