This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import abstractmethod | |
from typing import TypeVar, Generic, Protocol | |
class P1(Protocol): | |
def predict(self): ... | |
class P2(Protocol, P1): | |
def predict_proba(self): ... | |
T1 = TypeVar("T1", bound=P1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fudge() { | |
# Does some simple formatting for general things | |
# * Highlights based on status code | |
# * Highlight your name | |
# * Dim some things | |
# https://stackoverflow.com/a/33206814 | |
# https://www.linuxquestions.org/questions/linux-newbie-8/tput-for-bold-dim-italic-underline-blinking-reverse-invisible-4175704737/ | |
green=$(tput setaf 2) | |
orange=$(tput setaf 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
np.random.seed(1) | |
print("My code", np.random.choice([1,2,3,4,5])) | |
# My code 4 | |
# Update library | |
np.random.seed(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dask_jobqueue import SLURMCluster | |
import time | |
from pathlib import Path | |
from concurrent.futures import wait, ALL_COMPLETED | |
def f(x: int) -> int: | |
time.sleep(20) | |
print(f"Done {x}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An optimized implementation of the Lanczos algorithm to compute an | |
# estimate of the eigen-spectra of the Hessian of a neural network. | |
# | |
# The original implementation by `pyhessian` is used as a benchmark. | |
# https://github.com/amirgholami/PyHessian/tree/master | |
# | |
# To see how to actually use and plot the eigen-spectra based on this function, | |
# please see the original repository. | |
# | |
# # Requires: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* SparseSet is a data structure that most importantly keeps all its stored | |
* items in contiguous memory, while still allowing for O(1) insertions, | |
* deletions, and lookups. These are usually objects you'd like to keep | |
* a reference for later O(1) lookup and mutation. You may also think | |
* of it as a `HashMap<usize, T>` but contiguous memory holding Vec<T> | |
* | |
* The contiguous part is particularly useful to be able to map them | |
* into a GPU buffer, as the data transfer can only specify full blocks | |
* of memory. This is why this structure **must** own the data it stores. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
from typing import Iterator | |
def date_range( | |
start: datetime, | |
end: datetime, | |
step: timedelta, | |
*, | |
clamp: bool = True, |