Skip to content

Commit 33f637e

Browse files
authored
Merge pull request #541 from coatless/master
Modernizing GSL's FastLM function to use new RcppGSL templates.
2 parents 76aa48c + 8a5069a commit 33f637e

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

ChangeLog

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
2016-08-14 James J Balamuta <[email protected]>
2+
3+
* inst/examples/FastLM/lmGSL.R: Updated example to use new GSL templates
4+
15
2016-08-11 Dirk Eddelbuettel <[email protected]>
26

3-
* .travis.yml: Switch to using run.sh for Travis CI
7+
* .travis.yml: Switch to using run.sh for Travis CI
48

59
2016-08-09 Artem Klevtsov <[email protected]>
610

inst/NEWS.Rd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
\code{RCPP_RETURN_MATRIX} macro when C++11 compiler used (Artem Klevtsov
2525
in \ghpr{537} fixing \ghit{38}).
2626
}
27+
\item Changes in Rcpp build system
28+
\itemize{
29+
\item Travis CI is now driven via \code{run.sh} from our fork, and deploys
30+
all packages as .deb binaries using our PPA where needed (Dirk in
31+
\ghpr{540} addressing issue \ghit{517}).
32+
}
2733
\item Changes in Rcpp unit tests
2834
\itemize{
2935
\item New unit tests for random number generators the R namespace which
@@ -34,7 +40,7 @@
3440
\itemize{
3541
\item Examples that used cxxfunction() from the inline package have been
3642
rewritten to use either sourceCpp() or cppFunction()
37-
(James Balamuta in \ghpr{535}, \ghpr{534}, and \ghpr{532}
43+
(James Balamuta in \ghpr{541}, \ghpr{535}, \ghpr{534}, and \ghpr{532}
3844
addressing issue \ghit{56}).
3945
}
4046
}

inst/examples/FastLM/lmGSL.R

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ sourceCpp(code='
8686
// [[Rcpp::export]]
8787
Rcpp::List fun(Rcpp::NumericVector Yr, Rcpp::NumericMatrix Xr){
8888
89-
int i,j,n = Xr.nrow(), k = Xr.ncol();
89+
int i, j, n = Xr.nrow(), k = Xr.ncol();
9090
double chisq;
9191
92-
gsl_matrix *X = gsl_matrix_alloc (n, k);
93-
gsl_vector *y = gsl_vector_alloc (n);
94-
gsl_vector *c = gsl_vector_alloc (k);
95-
gsl_matrix *cov = gsl_matrix_alloc (k, k);
92+
RcppGSL::Matrix X(n, k); // allocate a gsl_matrix<double> of dim n, k
93+
RcppGSL::Vector y(n); // allocate a gsl_vector<double> of length n
94+
RcppGSL::Vector c(k); // allocate a gsl_vector<double> of length k
95+
RcppGSL::Matrix cov(k, k); // allocate a gsl_matrix<double> of dim k, k
96+
9697
for (i = 0; i < n; i++) {
9798
for (j = 0; j < k; j++)
98-
gsl_matrix_set (X, i, j, Xr(i,j));
99-
gsl_vector_set (y, i, Yr(i));
99+
X(i, j) = Xr(i, j);
100+
y[i] = Yr(i); // Note vector requires [] not ()
100101
}
101102
102103
gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k);
@@ -105,17 +106,13 @@ Rcpp::List fun(Rcpp::NumericVector Yr, Rcpp::NumericMatrix Xr){
105106
106107
Rcpp::NumericVector coefr(k), stderrestr(k);
107108
for (i = 0; i < k; i++) {
108-
coefr(i) = gsl_vector_get(c,i);
109-
stderrestr(i) = sqrt(gsl_matrix_get(cov,i,i));
109+
coefr(i) = c[i];
110+
stderrestr(i) = sqrt(cov(i,i));
110111
}
111-
gsl_matrix_free (X);
112-
gsl_vector_free (y);
113-
gsl_vector_free (c);
114-
gsl_matrix_free (cov);
115112
116113
117-
return Rcpp::List::create( Rcpp::Named( "coef", coefr),
118-
Rcpp::Named( "stderr", stderrestr));
114+
return Rcpp::List::create( Rcpp::Named("coef") = coefr,
115+
Rcpp::Named("stderr") = stderrestr);
119116
}')
120117
fun
121118
}

0 commit comments

Comments
 (0)