Skip to content

Instantly share code, notes, and snippets.

Avatar

nbenn nbenn

  • ETH Zürich
  • Zürich
View GitHub Profile
@nbenn
nbenn / dtw-py-vs-r.R
Created Aug 22, 2019
Comparison of python tslearn and R dtw implementations
View dtw-py-vs-r.R
library(reticulate)
library(dtw)
use_condaenv("dtw")
tslearn <- import("tslearn")
tslearn$metrics$dtw(rep(0, 3), 1:4)
dtw(rep(0, 3), 1:4, keep.internals = T, step.pattern = symmetric1)[
@nbenn
nbenn / mp11-functor-recursion.cpp
Created Aug 6, 2019
Runtime index for choosing type
View mp11-functor-recursion.cpp
// compile: clang++ -Wall -std=c++11 -I /usr/local/include mp11.cpp -o mp11
#include <vector>
#include <iostream>
#include <stdexcept>
#include <boost/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/algorithm.hpp>
@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");
}
@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 / 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 / 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 / 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 / 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 / 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"
You can’t perform that action at this time.