Skip to content

Instantly share code, notes, and snippets.

View shamanDevel's full-sized avatar

Sebastian Weiss shamanDevel

View GitHub Profile
@shamanDevel
shamanDevel / OnlineMeanVariance.cpp
Created January 29, 2021 12:14
OnlineMeanVariance.cpp
/**
* \brief Online algorithm to compute the mean and variance.
* Source: http://datagenetics.com/blog/november22017/index.html
*/
class MeanVariance
{
int64_t n_ = 0;
double mean_ = 0;
double sn_ = 0;
double lastmean_ = 0;
#include <vector>
#include <random>
#include <cstdio>
#include <optional>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <functional>
typedef double real; //using doubles in the test case
@shamanDevel
shamanDevel / ImageLenses.py
Created June 22, 2020 10:03
Image Lenses: Adds lenses -- zoomed crops -- to the image
"""
A small GUI that loads a number of images and allows to display a "lens" of a certain area.
Used to highlight important areas in comparison images.
"""
import math
import os
import numpy as np
import cv2 as cv
import imageio
@shamanDevel
shamanDevel / Multigrid.py
Created January 20, 2020 09:26
2D-Multigrid
"""
Multigrid-Test for the 2D poisson problem
with arbitrary Dirichlet boundaries over the domain and Neumann boundaries at the border.
Based on the tutorial from http://www.mgnet.org/mgnet/tutorials/xwb/example.html
"""
import numpy as np
import matplotlib.pyplot as plt
def generateProblem1(size : int):
@shamanDevel
shamanDevel / OnlineMeanVariance.py
Last active March 13, 2019 09:19
Online algorithm for computing the mean and variance
class MeanVariance():
"""
Online algorithm to compute the mean and variance
Source: http://datagenetics.com/blog/november22017/index.html
"""
def __init__(self):
self.n_ = 0
self.mean_ = 0
self.sn_ = 0
@shamanDevel
shamanDevel / BackgroundWorker.h
Created January 15, 2019 13:18
A simple background worker with status messages and interrupt
#pragma once
#include <ThreadPool.h> //https://github.com/mtrebi/thread-pool
#include <assert.h>
#include <iostream> //Only for logging, can be replaced by something else
/**
* \brief Improved background worker that reuses the thread.
* Can only be allocated on the heap
*/
@shamanDevel
shamanDevel / release_assert.h
Created January 15, 2019 13:10
An assertion macro for MSVC that behaves exactly like the regular assert-macro but stays active in release mode
#pragma once
#include <corecrt.h>
_CRT_BEGIN_C_HEADER
#ifdef release_assert
#undef release_assert
#endif
_ACRTIMP void __cdecl _wassert(
@shamanDevel
shamanDevel / halton.h
Last active January 15, 2019 13:07
Halton sequence generator
#include <array>
#include <numeric>
/**
* Computes the i-th entry of the halton sequence of size N.
* Code copied from somewhere (I don't remember) and then modernized to use std::array.
*/
template<int N>
std::array<double, N> halton(int i)
{
static_assert(N <= 168, "halton sequence only supported until dimension 168");
@shamanDevel
shamanDevel / cuPrintf.cu
Created January 15, 2019 12:54
cuPrintf: printf inside CUDA kernels, improved version with more arguments
#include "cuPrintf.cuh"
#include <device_launch_parameters.h>
#include "cuMat/src/Errors.h"
// This structure is used internally to track block/thread output restrictions.
typedef struct __align__(8) {
int threadid; // CUPRINTF_UNRESTRICTED for unrestricted
int blockid; // CUPRINTF_UNRESTRICTED for unrestricted
} cuPrintfRestriction;