Skip to content

Instantly share code, notes, and snippets.

Avatar

Gavin Gray gngdb

View GitHub Profile
View README.md

This gist shows how to use rebase to change the Git history of a repo. Imagine you realise that the first commit to your repo should be different (maybe it's incomplete, includes something it shouldn't or simply could be cleaner). However, since then you and others have made many changes to the repo that you want to preserve. Here we show how to split the first commit into multiple and re-attach the remaining version history to these new commits.

Let's make a dummy git repo rebase-root and add two files to it. We commit them with the commit #1.

@gngdb
gngdb / Soap Bubble Effect.ipynb
Created Jun 4, 2020
Soap bubble effect simulation
View Soap Bubble Effect.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / sample_output
Last active Jun 3, 2020
Testing random seed setting in different threads
View sample_output
Tuples sampled in parallel or sequentially are equal:
0.496, 0.549, 0.844 == 0.496, 0.549, 0.844
0.758, 0.417, 0.134 == 0.758, 0.417, 0.134
0.615, 0.436, 0.956 == 0.615, 0.436, 0.956
0.004, 0.551, 0.238 == 0.004, 0.551, 0.238
0.560, 0.967, 0.236 == 0.560, 0.967, 0.236
0.830, 0.222, 0.623 == 0.830, 0.222, 0.623
0.572, 0.893, 0.793 == 0.572, 0.893, 0.793
0.535, 0.076, 0.324 == 0.535, 0.076, 0.324
0.598, 0.873, 0.227 == 0.598, 0.873, 0.227
@gngdb
gngdb / thesis-planning.py
Last active May 7, 2020
Brute Force Ancestral Monte Carlo I used for project planning when writing my PhD thesis
View thesis-planning.py
# renders a MAP estimate of the PhD thesis timeline along with estimate of the
# 50%, 90% and 99% chance of thesis being complete
import numpy as np
import time
import datetime
from datetime import timedelta
def main():
# model the PhD as a sequence of events of random length.
@gngdb
gngdb / Iterated Indexing.ipynb
Last active Apr 29, 2020
I often come across the problem that I have an array of indexes I want to match to a elements along a dimension. It's solved by gather.
View Iterated Indexing.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / d12.py
Created Apr 9, 2020
Pure Python Gumbel Dice
View d12.py
import dice
print(dice.roll(12))
@gngdb
gngdb / show.py
Last active Feb 11, 2020
Display Images from arrays and tensors in Python 3 (based on https://github.com/google/deepdream/blob/master/dream.ipynb)
View show.py
from io import BytesIO
import PIL.Image
from IPython.display import clear_output, Image, display
def showarray(a, fmt='jpeg'):
a = a - a.min()
a = 255.*(a/a.max())
a = np.uint8(np.clip(a, 0, 255))
f = BytesIO()
PIL.Image.fromarray(a).save(f, fmt)
View Index Cartesian Product.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / Parameter Redundancy Through Time.ipynb
Last active Oct 17, 2019
Parameter redundancy from 5 pruning papers through time.
View Parameter Redundancy Through Time.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / pointwise.py
Created Sep 17, 2019
Pointwise convolution in PyTorch without using conv2d.
View pointwise.py
import torch
from torch.nn.functional import conv2d
def pointwise(X, W):
n,c_in,h,w = X.size() # (n examples, c_in channels, height, width)
c_out,c_in,_,_ = W.size() # (c_out channels, c_in channels, 1, 1)
W = W.view(c_out,c_in) # squeeze size 1 dims, shape=(c_out, c_in)
X = X.view(n,c_in,h*w) # flatten spatial dims
X = X.permute(0,2,1) # transpose, shape=(n,h*w, c_in)
K = X.reshape(n*h*w,c_in) # kernel matrix, shape=(n*h*w, c_in)
You can’t perform that action at this time.