~ubuntu-branches/ubuntu/trusty/r-cran-rcpparmadillo/trusty

« back to all changes in this revision

Viewing changes to inst/examples/fastLm.r

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2013-07-31 16:40:01 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130731164001-h9t7espn2nh9wf9p
Tags: 0.3.900.7-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
##
3
3
## fastLm.r: Benchmarking lm() via RcppArmadillo and directly
4
4
##
5
 
## Copyright (C)  2010 - 2012  Dirk Eddelbuettel, Romain Francois and Douglas Bates
 
5
## Copyright (C)  2010 - 2013  Dirk Eddelbuettel, Romain Francois and Douglas Bates
6
6
##
7
7
## This file is part of RcppArmadillo.
8
8
##
19
19
## You should have received a copy of the GNU General Public License
20
20
## along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
 
library(inline)
 
22
library(RcppArmadillo)
23
23
library(rbenchmark)
24
24
 
25
25
src <- '
26
 
    Rcpp::NumericMatrix Xr(Xs);
27
 
    Rcpp::NumericVector yr(ys);
 
26
Rcpp::List fLmTwoCasts(Rcpp::NumericMatrix Xr, Rcpp::NumericVector yr) {
28
27
    int n = Xr.nrow(), k = Xr.ncol();
29
28
    arma::mat X(Xr.begin(), n, k, false);
30
29
    arma::colvec y(yr.begin(), yr.size(), false);
43
42
    return Rcpp::List::create(Rcpp::Named("coefficients")=coef,
44
43
                              Rcpp::Named("stderr")      =sderr,
45
44
                              Rcpp::Named("df")          =df);
 
45
}
46
46
'
47
 
 
48
 
fLmTwoCasts <- cxxfunction(signature(Xs="numeric", ys="numeric"),
49
 
                           src, plugin="RcppArmadillo")
 
47
cppFunction(code=src, depends="RcppArmadillo")
50
48
 
51
49
src <- '
52
 
    arma::mat X = Rcpp::as<arma::mat>(Xs);
53
 
    arma::colvec y = Rcpp::as<arma::colvec>(ys);
 
50
Rcpp::List fLmOneCast(arma::mat X, arma::colvec y) {
54
51
    int df = X.n_rows - X.n_cols;
55
52
 
56
53
    // fit model y ~ X, extract residuals
66
63
    return Rcpp::List::create(Rcpp::Named("coefficients")=coef,
67
64
                              Rcpp::Named("stderr")      =sderr,
68
65
                              Rcpp::Named("df")          =df);
 
66
}
69
67
'
70
 
 
71
 
fLmOneCast <- cxxfunction(signature(Xs="numeric", ys="numeric"),
72
 
                          src, plugin="RcppArmadillo")
 
68
cppFunction(code=src, depends="RcppArmadillo")
73
69
 
74
70
 
75
71
fastLmPureDotCall <- function(X, y) {