Skip to content

Instantly share code, notes, and snippets.

View mmaechler's full-sized avatar

Martin Mächler mmaechler

View GitHub Profile
@mmaechler
mmaechler / ifelse-checks.R
Last active November 28, 2016 18:07
`ifelse2()` - experiments for a new version of `ifelse()`
source("ifelse-def.R")
##' warnifnot(): a "only-warning" version of stopifnot():
##' {Yes, learn how to use do.call(substitute, ...) in a powerful manner !!}
warnifnot <- stopifnot
body(warnifnot) <- do.call(substitute, list(body(stopifnot),
list(stop = quote(warning))))
## (now, this was really cute ....)
@brandonwillard
brandonwillard / sparse-matrix-fix.R
Last active March 12, 2018 14:58
Slow fix for creating large sparse matrices with interactions
library(Rcpp)
#library(RcppProgress)
#library(RcppParallel)
{
code = '
// [[Rcpp::depends(RcppProgress, RcppArmadillo, RcppParallel)]]
#define ARMA_64BIT_WORD
#include <RcppArmadillo.h>
#include <RcppParallel.h>

Compiling an optimized ATLAS on Ubuntu 12.04

  1. Download the latest ATLAS source from http://sourceforge.net/projects/math-atlas/files/. I'm using version 3.10.1
  2. Download the latest Netlib LAPACK from http://www.netlib.org/lapack/. I'm using version 3.4.2
  3. Turn off frequency scalings on your chip so that you can get reliable timings. This is essential to get a good ATLAS build
  sudo apt-get install cpufreq-info cpuspeed cpufrequtils sysfsutils
  # set each core to the "performance" governor, so that the clock frequency doesn't go down when idle
  # I have 8 cores, which is why I need to do this 8 times
  sudo cpufreq-selector -c 0 -g performance