Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdlib.h>
  2. int strmv(
  3.   const long n,
  4.   const long p,
  5.   const double alpha,
  6.   double **U,    /* two-dimensional array, row-major */
  7.   double **W,    /* two-dimensional array, row-major */
  8.   double *x,     /* one-dimensional array */
  9.   double *ws     /* workspace (length p array) */
  10.   ){
  11.  
  12.   /*Check if input constants n,p are 0 or pointers are equal to NULL*/
  13.   if ( (n == 0) || (p == 0) || (U == NULL) ||
  14.     (W == NULL) || (x == NULL) || (ws == NULL) ) return -1;
  15.  
  16.   /*Initialise new double x_new so we don't have to overwrite x in the loop*/
  17.   double x_new = 0;
  18.  
  19.   for(int i=0; i<n; i++){
  20.     for(int j=0; j<p; j++){
  21.         ws[j] += x[i]*W[i][j];
  22.         x_new += U[i][j]*ws[j];
  23.     }
  24.  
  25.     /*Update x[i] when out of inner loop and reinitialise x_new*/
  26.     x[i] = alpha*x_new;
  27.     x_new = 0;
  28.   }
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement