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) ; |
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
# Chris DuBois | |
# October 2, 2011 | |
# dfapply: apply an expression to each row of a data.frame | |
# This can be especially helpful when organizing experimental setups and you want to plot the results from a data.frame. | |
# s: data.frame, where each row has argument values | |
# expr: expression to evaluate on each row of s |
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
log.sum.exp<- function(x) { | |
# Computes log(sum(exp(x)) | |
# Uses offset trick to avoid numeric overflow: http://jblevins.org/notes/log-sum-exp | |
offset <- x[which(x == max(abs(x)))] | |
log(sum(exp(x - offset))) + offset | |
} |
NewerOlder