Skip to content

Instantly share code, notes, and snippets.

Avatar
♟️

Thomas Dybdahl Ahle thomasahle

♟️
View GitHub Profile
@thomasahle
thomasahle / sinkhorn.py
Created Mar 15, 2021
Code from Differentiable Top-k Operator with Optimal Transport
View sinkhorn.py
def sinkhorn_forward(C, mu, nu, epsilon, max_iter):
bs, n, k_ = C.size()
v = torch.ones([bs, 1, k_])/(k_)
G = torch.exp(-C/epsilon)
if torch.cuda.is_available():
v = v.cuda()
for i in range(max_iter):
u = mu/(G*v).sum(-1, keepdim=True)
@thomasahle
thomasahle / tetraminos.py
Created Nov 27, 2020
Packing tetraminos
View tetraminos.py
import collections
from ortools.linear_solver import pywraplp
# xy format
tetras = [
# Up downs
((0,0),(0,1),(1,1),(1,2)),
((0,0),(0,1),(-1,1),(-1,2)),
# left rights
((0,0),(1,0),(1,-1),(2,-1)),