Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- int strmv(
- const long n,
- const long p,
- const double alpha,
- double **U, /* two-dimensional array, row-major */
- double **W, /* two-dimensional array, row-major */
- double *x, /* one-dimensional array */
- double *ws /* workspace (length p array) */
- ){
- /*Check if input constants n,p are 0 or pointers are equal to NULL*/
- if ( (n == 0) || (p == 0) || (U == NULL) ||
- (W == NULL) || (x == NULL) || (ws == NULL) ) return -1;
- /*Initialise new double x_new so we don't have to overwrite x in the loop*/
- double x_new = 0;
- for(int i=0; i<n; i++){
- for(int j=0; j<p; j++){
- ws[j] += x[i]*W[i][j];
- x_new += U[i][j]*ws[j];
- }
- /*Update x[i] when out of inner loop and reinitialise x_new*/
- x[i] = alpha*x_new;
- x_new = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement