Skip to content

Instantly share code, notes, and snippets.

@gaebor
gaebor / test_opencl.py
Created April 30, 2019 12:26
just a small OpenCL test
from __future__ import print_function
from ctypes import*
import sys
dllname = "opencl"
if len(sys.argv) >= 2:
dllname = sys.argv[1]
opencl = cdll.LoadLibrary(dllname)
pointerarray_type = c_void_p * 10
platforms = pointerarray_type()
@gaebor
gaebor / ProgressIndicator.h
Created June 21, 2018 00:20
a lightweight progress indicator in c++11
#pragma once
#include <thread>
#include <chrono>
#include <cstdio>
#include <exception>
template<class Exception = std::exception, typename T1, typename T2, typename Func, typename ...Args>
void ProgressIndicator(T1 begin, T2* p, double total, const char* fmt,
bool enable, const Func& f, Args&&... args)
@gaebor
gaebor / ReadMe.md
Last active June 3, 2018 20:54
Directory name case (in)sensitivity on Windows

Case (in)sensitivity

You won't believe this!

Let's say that you make a folder in Bash on Ubuntu on Windows

bash -c "mkdir zZz"

As you may know, files on Windows are case insensitive, so you can:

dir zZz

@gaebor
gaebor / bayesian_model_comparison.py
Last active May 2, 2019 14:52
Performs Bayesian Model Comparison to find the right mixture of Gaussians
from __future__ import print_function
import numpy
import theano
import theano.tensor as T
from thextensions import *
from sklearn.utils.extmath import softmax
import matplotlib
matplotlib.use('Agg')
@gaebor
gaebor / Geodetics.m
Last active January 29, 2019 18:12
wolfram Mathematica package to calculate geodetics from Riemannian metric
BeginPackage["Geodetics`"]
ChristoffelSymbols::usage = "Calculates Christoffel symbols of the second kind.
Provide the Riemannian metric as a matrix vaued function and the number of parameters.";
ChristoffelSymbols[G_, n_] :=
Function[{Args(*=Table[Subscript[x, q], {q, n}]*)},
Module[{ginv=Inverse[G@Args]},
Table[
1/2 Sum[
ginv[[m, k]] (D[G[Args][[k, i]], Args[[j]]] +
@gaebor
gaebor / Hamiltonian.m
Last active October 11, 2018 11:54
Wolfram Mathematica package for deriving Lagrangian and Hamiltonian (classical mechanics)
(* ::Package:: *)
BeginPackage["Hamiltonian`"]
arg::usage = "Generates symbolic argument list of given length, optionally given symbol name.";
arg[n_, symbol_: q] :=
Table[Symbol[ToString[symbol] <> ToString[i]], {i, 1, n}]
KineticEnergy::usage = "Generates kinetic energy formula from parameterized coordinates.";
KineticEnergy[X_, M_, n_, qsym_: q, tsym_: t] :=
@gaebor
gaebor / test_cnmem.sh
Last active September 18, 2017 15:36
Test the cnmem library preallocation, in order to prevent concurrent memory allocations on GPU. python2 only!
# presupposes that theano with gpu is already installed
FILENAME=theano_cnmem_text.log
export THEANO_FLAGS="gpuarray.preallocate=0.5,device=cuda,floatX=float32"
A_BIT=2
pip install -U nvidia-ml-py
# http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
RED='\033[0;31m'
NC='\033[0m' # No Color
@gaebor
gaebor / tensorflow_install.sh
Last active September 8, 2016 11:53
tensorflow install
# the script assumes OpenBlas and Cuda installation
# make sure to have these in PATH (maybe not all are necessary)
# /usr/local/bin
# /usr/bin
# /bin
# /usr/local/cuda/
# /usr/local/cuda/bin
virtualenv tensorflow
source tensorflow/bin/activate
@gaebor
gaebor / test_batched_dot.py
Last active February 16, 2018 10:05
this example shows that narrow matrix product or batched dot product is poorly parallelized
from __future__ import print_function
import numpy
import theano
import sys
import time
n = 100000
i = 10
j = 10
k = 10
@gaebor
gaebor / theano_install.sh
Last active August 31, 2018 13:27
how to install libgpuarray and make theano to perform 64bit, double precision, float64 calculations on (cuda capable) GPU
# the followings are expected to be installed
#
# virtualenv, git
# OpenBlas: https://github.com/xianyi/OpenBLAS
# cuda: https://developer.nvidia.com/cuda-downloads
ARGV=("$@")
function check_command
{