Skip to content

Instantly share code, notes, and snippets.

View lgarrison's full-sized avatar

Lehman Garrison lgarrison

View GitHub Profile
@lgarrison
lgarrison / swot vs corrfunc
Last active February 1, 2017 20:16
swot vs corrfunc: timing & accuracy
swot: https://github.com/jcoupon/swot/
corrfunc: https://github.com/manodeep/Corrfunc
To test the speed and agreement of swot vs corrfuc, we generated random
datasets of increasing size and measured the w(theta) autocorrelation function.
Swot has an approximation parameter 'OA' (opening angle) that critically impacts its runtime.
We tried OA=0.03 and OA='no'. However, even the conservative value of OA=0.03
caused >10% errors in wtheta for this randomized configuration. Thus, it should
be used with caution.
@lgarrison
lgarrison / RR_autocorrelations.ipynb
Last active July 24, 2020 12:52
A note on the RR term in autocorrelations
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / repeat_histogram.py
Created December 27, 2016 22:25
Fast repeated histogramming in numpy
# Note: this function uses the term 'radius', but the histogramming is completely general
import numpy as np
def RadialBin(radii, values, bin_edges, bin_indices=None):
"""
Radial histogramming that supports fast re-evaluation
for the same `radii` with new `values` by passing back `bin_indices`.
Parameters
@lgarrison
lgarrison / high_performance_python.ipynb
Last active July 23, 2020 14:10
High-Performance Python, or When to Write For Loops in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / scale_free_sigma8.ipynb
Last active October 25, 2019 19:18
sigma8 in Scale-Free Cosmologies
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / SAO_python_worksheet.ipynb
Created August 14, 2018 15:57
Simple simulations with Python and NumPy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / corrfunc_bug_gh193.c
Created September 29, 2019 20:50
GCC Bug (Corrfunc #193)
/*
This is a "minimal" reproducer for an apparent GCC-7 bug related to AVX-512.
It has a 100% reproduction rate on my machine (Cascade Lake).
A simple loop that copies the values from a double array to a float array
sometimes gives the wrong answer in the first few elements (zero, nan, or garbage).
The bug seems correlated with alignment values of the input and output
arrays, but it's not a one-to-one relationship.
@lgarrison
lgarrison / globus.py
Last active September 24, 2020 17:17
Abacus Globus script
#!/usr/bin/env python3
'''
This script facilitates Globus transfers of Abacus simulation data.
In particular, for AbacusSummit we want to transfer particle data and
halo catalogs from OLCF to NERSC after each simulation is done.
Both sites already have Globus endpoints, so the job of this script
is to initiate a transfer between the two, saving the transfer ID
number so we can query the transfer status later.
The intention of this script is primarily to do disk-to-disk
@lgarrison
lgarrison / multithreaded_io_queue.py
Created March 25, 2021 20:40
A simple multi-threaded Python file writer
'''
A simple multi-threaded Python file writer.
Author: Lehman Garrison (lgarrison.github.io)
'''
import threading
import queue
import numpy as np
@lgarrison
lgarrison / numba_ecdf.py
Last active March 29, 2021 17:44
Fast N-dimensional empirical CDF
import numba as nb
import numpy as np
def nb_ecdf(X,Rmax,ngrid=64,nthreads=1):
'''Compute the empirical CDF of points X (shape (N,D))
in domain [0,Rmax) using a histogram with `ngrid` cells
per dimension.
Rmax and ngrid can also be length D arrays.
'''