[Genabel-commits] r1393 - pkg/ProbABEL/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Nov 18 21:59:22 CET 2013
Author: lckarssen
Date: 2013-11-18 21:59:21 +0100 (Mon, 18 Nov 2013)
New Revision: 1393
Modified:
pkg/ProbABEL/src/coxph_data.cpp
pkg/ProbABEL/src/gendata.cpp
pkg/ProbABEL/src/main.cpp
pkg/ProbABEL/src/regdata.cpp
Log:
After the 'experiment' in the previous commit, which solved a valgrind error in Jenkins this change replaces the variable length arrays in the rest of the ProbABEL code with a proper C++ construct.
Modified: pkg/ProbABEL/src/coxph_data.cpp
===================================================================
--- pkg/ProbABEL/src/coxph_data.cpp 2013-11-18 20:33:22 UTC (rev 1392)
+++ pkg/ProbABEL/src/coxph_data.cpp 2013-11-18 20:59:21 UTC (rev 1393)
@@ -114,10 +114,13 @@
{
for (int j = 0; j < ngpreds; j++)
{
- double snpdata[nids];
+ double *snpdata = new double[nids];
gend.get_var(snpnum * ngpreds + j, snpdata);
for (int i = 0; i < nids; i++)
+ {
X.put(snpdata[i], i, (ncov - ngpreds + j));
+ }
+ delete[] snpdata;
}
}
@@ -129,8 +132,8 @@
}
// sort by time
- double tmptime[nids];
- int passed_sorted[nids];
+ double *tmptime = new double[nids];
+ int *passed_sorted = new int[nids];
for (int i = 0; i < nids; i++)
{
@@ -177,6 +180,9 @@
// weights.print();
// stime.print();
// sstat.print();
+
+ delete[] tmptime;
+ delete[] passed_sorted;
}
void coxph_data::update_snp(gendata &gend, const int snpnum)
@@ -197,7 +203,7 @@
for (int j = 0; j < ngpreds; j++)
{
- double snpdata[nids];
+ double *snpdata = new double[nids];
for (int i = 0; i < nids; i++)
{
masked_data[i] = 0;
@@ -211,6 +217,7 @@
if (std::isnan(snpdata[i]))
masked_data[order[i]] = 1;
}
+ delete[] snpdata;
}
}
@@ -344,7 +351,9 @@
mematrix<double> u(X.nrow, 1);
mematrix<double> imat(X.nrow, X.nrow);
- double work[X.ncol * 2 + 2 * (X.nrow) * (X.nrow) + 3 * (X.nrow)];
+ double *work = new double[X.ncol * 2 +
+ 2 * (X.nrow) * (X.nrow) +
+ 3 * (X.nrow)];
double loglik_int[2];
int flag;
@@ -435,4 +444,6 @@
loglik = loglik_int[1];
}
}
+
+ delete[] work;
}
Modified: pkg/ProbABEL/src/gendata.cpp
===================================================================
--- pkg/ProbABEL/src/gendata.cpp 2013-11-18 20:33:22 UTC (rev 1392)
+++ pkg/ProbABEL/src/gendata.cpp 2013-11-18 20:59:21 UTC (rev 1393)
@@ -30,7 +30,7 @@
}
else if (DAG != NULL) // Read from fv file
{
- double tmpdata[DAG->getNumObservations()];
+ double *tmpdata = new double[DAG->getNumObservations()];
DAG->readVariableAs((unsigned long int) var, tmpdata);
unsigned int j = 0;
@@ -67,6 +67,7 @@
data[j++] = val;
}
}
+ delete[] tmpdata;
}
else
{
Modified: pkg/ProbABEL/src/main.cpp
===================================================================
--- pkg/ProbABEL/src/main.cpp 2013-11-18 20:33:22 UTC (rev 1392)
+++ pkg/ProbABEL/src/main.cpp 2013-11-18 20:59:21 UTC (rev 1393)
@@ -634,8 +634,8 @@
rgd.update_snp(gtd, csnp);
double freq = 0.;
unsigned int gcount = 0;
- double snpdata1[gtd.nids];
- double snpdata2[gtd.nids];
+ double *snpdata1 = new double[gtd.nids];
+ double *snpdata2 = new double[gtd.nids];
if (input_var.getNgpreds() == 2) // Two predictors (probs)
{
@@ -992,6 +992,8 @@
}
update_progress_to_cmd_line(csnp, nsnps);
+ delete[] snpdata1;
+ delete[] snpdata2;
} // END for loop over all SNPs
Modified: pkg/ProbABEL/src/regdata.cpp
===================================================================
--- pkg/ProbABEL/src/regdata.cpp 2013-11-18 20:33:22 UTC (rev 1392)
+++ pkg/ProbABEL/src/regdata.cpp 2013-11-18 20:59:21 UTC (rev 1393)
@@ -82,10 +82,13 @@
if (snpnum > 0)
for (int j = 0; j < ngpreds; j++)
{
- double snpdata[nids];
+ double *snpdata = new double[nids];
gend.get_var(snpnum * ngpreds + j, snpdata);
for (int i = 0; i < nids; i++)
+ {
X.put(snpdata[i], i, (ncov - ngpreds + 1 + j));
+ }
+ delete[] snpdata;
}
// for (int i=0;i<nids;i++)
// for (int j=0;j<ngpreds;j++)
@@ -100,7 +103,7 @@
for (int j = 0; j < ngpreds; j++)
{
- double snpdata[nids];
+ double *snpdata = new double[nids];
for (int i = 0; i < nids; i++)
{
masked_data[i] = 0;
@@ -116,6 +119,7 @@
masked_data[i] = 1;
}
}
+ delete[] snpdata;
}
}
More information about the Genabel-commits
mailing list