[Rcpp-commits] r3507 - pkg/RcppSMC/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 14 03:37:56 CET 2012


Author: edd
Date: 2012-03-14 03:37:56 +0100 (Wed, 14 Mar 2012)
New Revision: 3507

Modified:
   pkg/RcppSMC/src/blockpfgaussianoptfuncs.cc
Log:
std::vector instead of new/delete []


Modified: pkg/RcppSMC/src/blockpfgaussianoptfuncs.cc
===================================================================
--- pkg/RcppSMC/src/blockpfgaussianoptfuncs.cc	2012-03-14 02:35:58 UTC (rev 3506)
+++ pkg/RcppSMC/src/blockpfgaussianoptfuncs.cc	2012-03-14 02:37:56 UTC (rev 3507)
@@ -1,5 +1,6 @@
 #include <iostream>
 #include <cmath>
+#include <vector>
 //#include <gsl/gsl_randist.h>
 
 #include "rngR.h"
@@ -39,10 +40,10 @@
     long lag = min(lTime,lLag);
 
     //These structures should really be made static 
-    double* mu = new double[lag+1];
-    double* sigma = new double[lag+1];
-    double* sigmah = new double[lag+1];
-    double* mub = new double[lag+1];
+    std::vector<double> mu(lag+1);
+    std::vector<double> sigma(lag+1);
+    std::vector<double> sigmah(lag+1);
+    std::vector<double> mub(lag+1);
 
     // Forward filtering
     mu[0] = cv_to->at(lTime-lag);
@@ -66,8 +67,4 @@
     // Importance weighting
     pFrom.AddToLogWeight(-0.5 * pow(y[int(lTime)] - mu[lag-1],2.0) / (sigmah[lag]+1) );
 
-    delete [] mu;
-    delete [] sigma;
-    delete [] sigmah;
-    delete [] mub;
 }



More information about the Rcpp-commits mailing list