Skip to content

Instantly share code, notes, and snippets.

View jonashaag's full-sized avatar

Jonas Haag jonashaag

View GitHub Profile
@jonashaag
jonashaag / distutils_compiler_launcher.py
Last active March 12, 2022 21:26
Python distutils/setup.py/pip compiler launcher (ccache/sccache)
class CompilerLauncherMixin:
"""Add "compiler launchers" to distutils.
We use this to be able to run the Pandas build using "ccache".
A compiler launcher is a program that is invoked instead of invoking the
compiler directly. It is passed the full compiler invocation command line.
A similar feature exists in CMake, see
https://cmake.org/cmake/help/latest/prop_tgt/LANG_COMPILER_LAUNCHER.html.
@jonashaag
jonashaag / snowflake_fix_fetch.py
Created February 22, 2022 16:24
Snowflake fix fetch
def snowflake_fix_fetch(
df,
*,
parse_variant_columns=(),
lower_column_names=True,
convert_int64=True,
):
"""Apply Snowflake-specific fixes to a dataframe fetched from Snowflake.
- Lower all column names
- Parse VARIANT columns
@jonashaag
jonashaag / conftest.py
Created February 16, 2022 15:07
PySpark Continuous Integration setup
from pyspark.sql import SparkSession
def local_pyspark_cluster(n_cpus=1, memory_mb=512) -> SparkSession:
"""Start a local PySpark cluster with default settings.
Returns a client to that session.
"""
return (
SparkSession.builder.master(f"local[{n_cpus}]")
@jonashaag
jonashaag / pytest_mark_fixture.py
Last active October 18, 2021 16:59
pytest mark a fixture
import pytest
def mark_fixture(mark, *args, **kwargs):
"""Decorator to mark a fixture.
Usage:
@mark_fixture(pytest.mark.slow, scope="session", ...)
def my_fixture():
...
@jonashaag
jonashaag / trunet.py
Created June 26, 2021 14:57
REAL-TIME DENOISING AND DEREVERBERATION WTIH TINY RECURRENT U-NET
import torch
from torch.nn import *
def pointwise(in_channels, out_channels):
return Sequential(
Conv2d(in_channels, out_channels, 1, 1),
BatchNorm2d(out_channels),
ReLU(),
)
hop dev dtype win impl error (dB)
32 cuda torch.float32 ones torch.stft 92
32 cuda torch.float32 ones stft_fb 30
32 cuda torch.float32 ones torch_stft_fb 92
32 cuda torch.float32 ones librosa 92
32 cuda torch.float32 librosa torch.stft 92
32 cuda torch.float32 librosa stft_fb 29
32 cuda torch.float32 librosa torch_stft_fb 92
32 cuda torch.float32 librosa librosa 92
32 cuda torch.float32 asteroid torch.stft 92
@jonashaag
jonashaag / github-involved.py
Created October 10, 2020 20:36
List of GitHub projects you have been involved in
import json
import os
import requests
from collections import Counter
username = "jonashaag"
password = "..."
cache_name = f"involves-{username}.json"
if not os.path.exists(cache_name):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def bin_freqs(x, nbins):
return (
x.T.reshape((-1, int(x.shape[0] / nbins))).mean(axis=-1).reshape((-1, nbins)).T
)
def compact_freqs(x):
return np.vstack(
(
x[:16],