Created
January 9, 2012 19:35
-
-
Save doobwa/1584535 to your computer and use it in GitHub Desktop.
Rcpp Module example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Borrowed from http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_3_advanced.pdf | |
require(Rcpp) | |
require(inline) | |
require(testthat) | |
fx <- cxxfunction(,"",includes= | |
' | |
double norm( double x, double y ){ | |
return sqrt( x*x + y*y) ; | |
} | |
RCPP_MODULE(foo){ | |
function( "norm", &norm ) ; | |
} | |
', plugin="Rcpp") | |
foo <- Module("foo",getDynLib(fx)) | |
norm <- function(x,y) sqrt(x*x + y*y) | |
test_that("Rcpp module agrees with R version",{ | |
expect_that(foo$norm(3,5),equals(norm(3,5))) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment