Skip to content

Instantly share code, notes, and snippets.

function download_google_drive {
SRC=$1
DST=$2
echo "$SRC -> $DST"
curl -c /tmp/cookies "https://drive.google.com/uc?export=download&id=$SRC" > /tmp/intermezzo.html
DL_LINK=$(cat /tmp/intermezzo.html |\
grep -Po 'uc-download-link" [^>]* href="\K[^"]*' |\
sed 's/\&/\&/g'
)
import numpy as np
from numba import njit, parallel
@njit(parallel=True)
def cross_exchange(route1, route2, dist):
best_savings = -np.inf
for offset11 in prange(len(route1) - 3):
i1, i2 = route1[offset11], route1[offset11 + 1]
dii = dist[i1, i2]
@bkj
bkj / ee.py
Created February 12, 2020 16:39
import ee
import urllib
import numpy as np
from skimage import io
from PIL import Image
from zipfile import ZipFile
from matplotlib import pyplot as plt
ee.Initialize()
@bkj
bkj / fast_argmax.py
Created November 12, 2019 16:42
fast_argmax.py
#!/usr/bin/env python
"""
fast_argmax.py
"""
import numpy as np
from time import time
from numba import jit, prange
#!/usr/bin/env python
"""
prep-CUB200.py
"""
import os
import shutil
import pandas as pd
from tqdm import tqdm
def rle2mask(rle, height, width):
rle = [int(xx) for xx in rle.split(' ')]
offsets, runs = rle[0::2], rle[1::2]
tmp = np.zeros(height * width, dtype=np.uint8)
for offset, run in zip(offsets, runs):
tmp[offset:offset + run] = 1
return tmp.reshape(width, height).T
// Note: `@` refers to matrix-matrix or matrix-vector multiplication. `*` refers to elementwise multiplication.
degrees = // vector s.t. degree[i] is the degree of the i'th node in graph G
D = // diagonal matrix s.t. D[i, i] = degrees[i]
D_inv = // diagonal matrix s.t. D_inv[i, i] = 1 / sqrt(degrees[i])
q = // zero matrix of shape (max_iters, num_nodes)
grad = -alpha * D_inv @ s
while k < max_iters do
@bkj
bkj / simple_batchnorm.py
Last active May 31, 2019 19:18
simple_batchnorm.py
#!/usr/bin/env python
"""
simple_batchnorm.py
"""
class SimpleBatchNorm1d(nn.Module):
def __init__(self, dim, momentum=0.5, eps=1e-5, affine=True, track_running_stats=True):
self.eps = eps
self.momentum = momentum
@bkj
bkj / sgd_optimizers.py
Last active May 31, 2019 18:31
sgd_optimizers.py
#!/usr/bin/env python
"""
sgd_optimizers.py
Pseudocode for optimizers
These _should be_ identical to Pytorch implementation of the optimizers
"""
#!/usr/bin/env python
"""
simple-random-nasbench.py
"""
import numpy as np
import pandas as pd
from tqdm import tqdm, trange
from matplotlib import pyplot as plt