1 /// @file 2 /// Test scaling a vector 3 /// \test Test scaling of a vector 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; 11 CeedScalar a[10]; 12 const CeedScalar *b; 13 14 CeedInit(argv[1], &ceed); 15 16 n = 10; 17 CeedVectorCreate(ceed, n, &x); 18 for (CeedInt i=0; i<n; i++) 19 a[i] = 10 + i; 20 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, a); 21 22 CeedVectorScale(x, -0.5); 23 24 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &b); 25 for (CeedInt i=0; i<n; i++) 26 if (fabs(b[i] + (10.0 + i)/2 ) > 1e-14) 27 // LCOV_EXCL_START 28 printf("Error in alpha x, computed: %f actual: %f\n", b[i], 29 -(10.0 + i)/2); 30 // LCOV_EXCL_STOP 31 CeedVectorRestoreArrayRead(x, &b); 32 33 CeedVectorDestroy(&x); 34 CeedDestroy(&ceed); 35 return 0; 36 } 37