Skip to content

Instantly share code, notes, and snippets.

Avatar

nbenn nbenn

  • ETH Zürich
  • Zürich
View GitHub Profile
@nbenn
nbenn / install-gitlab.R
Last active May 19, 2016
Fetch latest build artifact from gitlab and install as R package.
View install-gitlab.R
#' Install an R package hosted as a build artifact on gitlab
#'
#' Gitlab supports the storage of build artifacts which may be utilized as
#' distribution mechanism for code binaries. Applying this to scheme to R, a
#' build task may be defined (for example for each tagged commit), yielding a
#' .zip file of the tar.gz package produced by R CMD build. This function
#' fetches the most recent build artifact and installs it as a package.
#'
#' @param gitlab A string representing the base url of the gitlab host
#' @param name The name of the package repository
@nbenn
nbenn / install-xgboost.sh
Created Oct 8, 2018
Install xgboost r-pkg on Mac OS 10.14 with openMP
View install-xgboost.sh
export C_INCLUDE_PATH=$(/usr/local/clang-7/bin/llvm-config --includedir)
export CPLUS_INCLUDE_PATH=$(/usr/local/clang-7/bin/llvm-config --includedir)
export LIBRARY_PATH=$(/usr/local/clang-7/bin/llvm-config --libdir)
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
cp make/config.mk config.mk
vi config.mk
# make edits such that
# export CC = /usr/local/clang-7/bin/clang
@nbenn
nbenn / install-r.sh
Created Oct 8, 2018
install R on Mac OS 10.14 with openMP capable clang
View install-r.sh
wget https://stat.ethz.ch/CRAN/src/base/R-3/R-3.5.1.tar.gz
tar -xvf R-3.5.1.tar.gz
cd R-3.5.1
vi config.site
# edit such that
# CC=/usr/local/clang-7/bin/clang
# OBJC=$CC
# F77=/usr/local/gcc-8.2/bin/gfortran-8
# LDFLAGS="-L/usr/local/clang-7/lib -L/usr/local/lib"
@nbenn
nbenn / rm-obj.R
Created Oct 25, 2018
Ad SO #52974000
View rm-obj.R
rm_tbl_4 <- function(tbl, env) {
tbl = deparse(substitute(tbl))
rm(list = tbl, pos = env)
}
fun_a <- function(dat_tbl) {
fun_b(dat_tbl)
}
fun_b <- function(data_table) {
@nbenn
nbenn / parallel-bm.R
Created Oct 30, 2018
Experiments with parallel access to bigmemory objects
View parallel-bm.R
library(bigmemory)
add_col_var <- function(x) {
biganalytics::apply(x, 2L, function(y) {
col_var <- 0
y_bar <- 0
for (i in y) y_bar <- y_bar + i
y_bar <- y_bar / length(y)
for (i in y) col_var <- col_var + (i - y_bar) ^ 2
y + (col_var / length(y))
@nbenn
nbenn / parallel-dt.R
Last active Dec 28, 2018
Experiments with parallel group-by in data.table
View parallel-dt.R
dt_sequential <- function(tbl, group_by, fun, use_cols) {
time_taken <- system.time({
res <- tbl[, fun(.SD), by = group_by, .SDcols = use_cols]
})
list(result = res, timings = time_taken)
}
@nbenn
nbenn / install-arrow.sh
Last active Jan 31, 2019
Install apache-arrow 0.12
View install-arrow.sh
# make sure a recent version of bison is available
brew install bison
wget https://www-eu.apache.org/dist/arrow/arrow-0.12.0/apache-arrow-0.12.0.tar.gz
tar -xvf apache-arrow-0.12.0.tar.gz
cd apache-arrow-0.12.0/cpp && mkdir release && cd release
# It is important to statically link to boost libraries
cmake .. -DARROW_PARQUET=ON -DCMAKE_BUILD_TYPE=Release -DARROW_BOOST_USE_SHARED:BOOL=Off \
-DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison
@nbenn
nbenn / mp11-type-list-switch.cpp
Last active Aug 4, 2019
Runtime index for choosing type
View mp11-type-list-switch.cpp
// compile: clang++ -Wall -std=c++14 -I /usr/local/include mp11-type-list-switch.cpp -o mp11-type-list-switch
#include <vector>
#include <iostream>
#include <boost/mp11/list.hpp>
#include <boost/mp11/algorithm.hpp>
namespace mp11 = boost::mp11;
@nbenn
nbenn / functor-type-switch.cpp
Last active Aug 4, 2019
Runtime index for choosing type
View functor-type-switch.cpp
// compile: clang++ -Wall -std=c++11 functor-type-switch.cpp -o functor-type-switch
#include <vector>
#include <iostream>
#include <stdexcept>
template <template<typename> class Func, typename ...Ar>
auto dispatch_type(size_t type, Ar&&... rg) ->
decltype(Func<int>()(std::forward<Ar>(rg)...)) {
switch(type) {
@nbenn
nbenn / functor-recursive-switch.cpp
Last active Aug 5, 2019
Runtime index for choosing type
View functor-recursive-switch.cpp
#include <stdexcept>
#include <tuple>
#include <iostream>
// terminating case to avoid if-constexpr
template <template<class> class F, typename R, typename... Ar>
R dispatch_impl(int, Ar&&... rgs) {
throw std::runtime_error("error");
}
You can’t perform that action at this time.