- int L = INTEGER(getAttrib(cwt_, R_DimSymbol))[0],
- D = INTEGER(getAttrib(cwt_, R_DimSymbol))[1];
- double *cwt = REAL(cwt_);
- SEXP R_fcwt;
- PROTECT(R_fcwt = allocMatrix(REALSXP, L, D));
- double* fcwt = REAL(R_fcwt);
-
- //TODO: coding style is terrible... no time for now.
- for (int col=0; col<D; col++)
+ int L = INTEGER(getAttrib(M_, R_DimSymbol))[0],
+ D = INTEGER(getAttrib(M_, R_DimSymbol))[1],
+ w = INTEGER_VALUE(w_),
+ half_w = (w-1)/2,
+ i,
+ nt; //number of terms in the current sum (max: w)
+ double *M = REAL(M_),
+ cs, //current sum (max: w terms)
+ left; //leftward term in the current moving sum
+
+ SEXP fM_; //the filtered result
+ PROTECT(fM_ = allocMatrix(REALSXP, L, D));
+ double* fM = REAL(fM_); //pointer to the encapsulated vector
+
+ // NOTE: unused loop parameter: shifting at the end of the loop is more efficient
+ for (int col=D-1; col>=0; col--)