Skip to content

Instantly share code, notes, and snippets.

View JossWhittle's full-sized avatar
😸

Joss Whittle JossWhittle

😸
View GitHub Profile
@JossWhittle
JossWhittle / fast_copy.hpp
Created March 3, 2014 19:03
A fast AVX memcpy macro which copies the content of a 64 byte source buffer into a 64 byte destination buffer. Buffers must be 32byte aligned.
#pragma once
#include <immintrin.h>
#define I32B __m256i
#define STORE_I32B(ptrD, ptrS) _mm256_store_si256(ptrD, *ptrS)
/**
* Copies the content of one 32 byte aligned
* 64 byte buffer into another
import numpy as np
from numba import njit, prange
BIT_COUNT_LOOKUP = np.array([bin(i).count('1') for i in range(256)]).astype(np.uint8)
@njit(fastmath=True, nopython=True, parallel=True)
def fast_tanimoto_matrix(fingerprints, progress):
"""
Compute a symmetric Tanimoto similarity matrix over a set of fingerprints of size (N, F//8).
Where N is the number of fingerprints, and F is the length of the boolean fingerprint.
@JossWhittle
JossWhittle / earth-view.py
Last active August 29, 2022 18:06
Simple script to download all of the images on https://earthview.withgoogle.com/ in 1800x1200 resolution.
import os
import json
import urllib.request
from tqdm import tqdm
import multiprocessing
with urllib.request.urlopen('https://earthview.withgoogle.com/_api/photos.json') as f:
slugs = list(map(lambda slug: slug | dict(id=slug['slug'].split('-')[-1]),
json.loads(f.read().decode('utf-8'))))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
FROM frolvlad/alpine-python3
# Build and install numpy
RUN apk add --no-cache \
--virtual=.build-dependencies \
g++ gfortran file binutils \
musl-dev python3-dev cython openblas-dev lapack-dev && \
apk add libstdc++ openblas lapack && \
\
pip install --disable-pip-version-check --no-build-isolation --no-cache-dir numpy==1.18.5 && \
@JossWhittle
JossWhittle / JOSS BNF Grammar
Last active July 22, 2020 08:09
A BNF Grammar for the JOSS Programming Language. The JOHNNIAC Open Shop System (JOSS) was a programming language developed by the RAND Corporation between 1963-1964 to allow mathematicians and engineers to run simple yet time consuming calculations with little to no knowledge of computers and without access to a computer expert. JOSS was the fir…
--- Strings & Numbers ---
<String> := <Char> | <Char> <String>
<Char> := <Alpha> | <Digit> | <SpecialChar>
<Alpha> := "A..Z" | "a..z"
<SpecialChar> := "." | "," | ";" | ":" | "'" | " " | "#" | "$" | "?"
<Number> := <NumberPart> | <Sign> <NumberPart>
<NumberPart> := <IntPart> | <IntPart> "." <DecimalPart>
<IntPart> := "0" | <NZDigit> | <NZDigit> <DecimalPart>
# Keep last N weights and one weight every H hours, discard others
old_weight_paths = sorted(list(glob(os.path.join(weight_path, 'style_weights-*.h5'))))
# Iterate over weights from newest to oldest, discard oldest weights if multiple were saved that hour
prev_weight_age = -1
for old_weight_path in reversed(old_weight_paths[:-keep_last_n_weights]):
# Age of this weight file in hours
weight_age = int((time() - os.path.getmtime(old_weight_path)) // (60 * 60 * keep_weights_every_n_hours))
class LinearWarmUpAndCosineDecay(tf.keras.optimizers.schedules.LearningRateSchedule):
def __init__(self, initial_learning_rate, warmup_steps, total_steps, alpha, name=None):
super(LinearWarmUpAndCosineDecay, self).__init__(name=name)
self.warmup_steps = warmup_steps
self.total_steps = total_steps
self.alpha = alpha
self.initial_learning_rate = initial_learning_rate
self.min_learning_rate = self.initial_learning_rate * self.alpha
\usepackage{listings}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage[TS1,T1]{fontenc}
\usepackage[english]{babel}
\usepackage{sourcecodepro}
\usepackage{scrextend}
\addtokomafont{labelinglabel}{\sffamily}
\pdfmapfile{=SourceCodePro.map}
import numpy as np
import tensorflow as tf
class LogMetrics(tf.keras.callbacks.Callback):
def __init__(self, log_dir, loss, metrics, steps, dataset, training=False):
super(LogMetrics, self).__init__()
self.log_dir = log_dir
self.metrics = metrics
self.steps = steps