+++ /dev/null
-#include <stdlib.h>
-#include <R.h>
-#include <Rinternals.h>
-#include <Rmath.h>
-
-#include <stdio.h>
-
-SEXP filter(SEXP cwt_)
-{
- 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++)
- {
- double v1 = cwt[0];
- double ma = v1 + cwt[1] + cwt[2];
- for (int i=1; i<L-2; i++)
- {
- fcwt[i] = ma / 3.;
- ma = ma - v1 + cwt[i+2];
- v1 = cwt[i];
- }
- fcwt[0] = cwt[0];
- fcwt[L-2] = ma / 3.;
- fcwt[L-1] = cwt[L-1];
- cwt = cwt + L;
- fcwt = fcwt + L;
- }
-
- UNPROTECT(1);
- return R_fcwt;
-}