Advertisement
Guest User

smdvquad.c

a guest
Jan 29th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include "smdvquad.h"
  2.  
  3. void smdv_quad(const mxArray *Q, const double **x, double* y) {
  4.     const double *pQ, *px;
  5.     mwIndex *irQ, *jcQ;
  6.     mwSize col, total = 0;
  7.     mwIndex star_row_idx, stop_row_idx, current_row_index;
  8.     mwSize n;
  9.  
  10.     /* Get the starting positions of all four data arrays. */
  11.     pQ = mxGetPr(Q);
  12.     irQ = mxGetIr(Q);
  13.     jcQ = mxGetJc(Q);
  14.     n = mxGetN(Q);
  15.  
  16.     /* Retrieve the values of x */
  17.     px = *x;
  18.  
  19.     /* Do le magic  */
  20.     *y = 0;
  21.     for (col = 0; col < n; col++) { // Iterate over all columns
  22.  
  23.         star_row_idx = jcQ[col];
  24.         stop_row_idx = jcQ[col + 1];
  25.  
  26.         if (star_row_idx == stop_row_idx)
  27.             continue;
  28.         else {
  29.             for (current_row_index = star_row_idx; current_row_index < stop_row_idx; current_row_index++) {
  30.                 (*y) += pQ[total++] * px[irQ[current_row_index]] * px[col];
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement