Skip to content

Instantly share code, notes, and snippets.

View ttesmer's full-sized avatar

Tammo Tesmer ttesmer

  • Technical University of Munich
  • Munich
View GitHub Profile
@ttesmer
ttesmer / AD.hs
Last active March 19, 2024 03:04
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v
@ttesmer
ttesmer / conv.c
Last active July 7, 2022 21:14
2D convolution on 28x28 matrix using 5x5 filter. Stride assumed to be 1, padding 0 and input matrix as well as kernel are assumed to be square. Not very fast or usable, but illustrates the core algorithm/what convolution is doing.
#include <stdio.h>
/*
2D convolution as used in machine learning, i.e. actually cross-correlation, not convolution.
But since the kernel would be learned either way, flipping it is not necessary.
So, let's just call it convolution.
*/
int main() {
int STRIDE = 1; // Don't let this fool you; stride other than 1 will not work currently
@ttesmer
ttesmer / hello_world.s
Last active June 11, 2022 06:47
"Hello world" in 32-bit assembly. Link with gcc using `gcc -nostdlib -m32 hello_world.s`
.section .text
.global _start
_start:
mov $4, %eax
mov $1, %ebx
mov $message, %ecx
mov msglength, %edx
int $0x80
mov $1, %eax