Skip to content

Instantly share code, notes, and snippets.

View WarrenWeckesser's full-sized avatar

Warren Weckesser WarrenWeckesser

View GitHub Profile
@WarrenWeckesser
WarrenWeckesser / check_rel_breitwigner_cdf.py
Created February 12, 2023 15:19
Compute relative error for the relativistic Breit-Wigner CDF calculation.
from mpmath import mp
from mpsci.distributions import rel_breitwigner
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
@WarrenWeckesser
WarrenWeckesser / check_rel_breitwigner_pdf.py
Created February 12, 2023 15:18
Compute relative error for the relativistic Breit-Wigner PDF calculation.
from mpmath import mp
from mpsci.distributions import rel_breitwigner
import numpy as np
from scipy import stats
from scipy.special import powm1
import matplotlib.pyplot as plt
@WarrenWeckesser
WarrenWeckesser / upfirdn_timing.py
Created November 11, 2022 19:12
Script to check the effect of https://github.com/scipy/scipy/pull/17397 on performance.
import subprocess
from timeit import timeit
import numpy as np
import scipy
from scipy.signal import upfirdn, resample_poly
try:
from scipy.signal._upfirdn_apply import _output_len
except ImportError:
from scipy.signal._upfirdn import _output_len
@WarrenWeckesser
WarrenWeckesser / skewnorm_moments_dict_timing.py
Last active August 10, 2022 03:20
Timing comparison for various ways to make a predefined dictionary available in the skew_norm_gen class.
import timeit
s0 = """
@lru_cache
def _get_skewnorm_odd_moments():
_skewnorm_odd_moments = {
1: Polynomial([1]),
3: Polynomial([3, -1]),
5: Polynomial([15, -10, 3]),
@WarrenWeckesser
WarrenWeckesser / find_numpy_functions_missing_examples.py
Created June 29, 2022 22:48
Find NumPy functions whose docstrings are missing the "Examples" section
"""
Find numpy functions whose docstrings do not contain "Examples".
"""
import types
import numpy as np
modules = [
'np',
@WarrenWeckesser
WarrenWeckesser / truncnorm_mp.py
Created March 26, 2022 11:40
Compute stats for the truncnorm distribution using mpmath
import mpmath
mpmath.mp.dps = 80
def truncnorm_delta_cdf(a, b):
if a > 0:
delta = mpmath.ncdf(-a) - mpmath.ncdf(-b)
@WarrenWeckesser
WarrenWeckesser / erfinv_approx.py
Created August 24, 2020 16:13
Code for generating a Padé approximant for the erfinv function.
"""
erfinv_approx.py
Create a Pade approximant for the erfinv function.
"""
import mpmath
import numpy as np
@WarrenWeckesser
WarrenWeckesser / bunch_idea1.py
Created June 8, 2020 17:01
Scratch work for a subclass of namedtuple with additional attributes.
from collections import namedtuple
def make_namedtuple_bunch1(typename, field_names, extra_field_names):
namedtuple_type = namedtuple(typename, field_names)
def __new__(cls, *args, **kwds):
# Pull out any keyword parameters that are not in the fields of
# the namedtuple.
@WarrenWeckesser
WarrenWeckesser / build.log
Created April 12, 2020 15:03
numpy build log, PR gh-15759
Processing numpy/random/_bounded_integers.pxd.in
Processing numpy/random/_bounded_integers.pyx.in
Processing numpy/random/_common.pyx
Processing numpy/random/_generator.pyx
Processing numpy/random/_mt19937.pyx
Processing numpy/random/_pcg64.pyx
Processing numpy/random/_philox.pyx
Processing numpy/random/_sfc64.pyx
Processing numpy/random/bit_generator.pyx
Processing numpy/random/mtrand.pyx
@WarrenWeckesser
WarrenWeckesser / build.out
Created November 18, 2019 19:58
NumPy build output from running: python3 setup.py install > build.out 2>&1
Processing numpy/random/_bounded_integers.pxd.in
Processing numpy/random/_bit_generator.pyx
Processing numpy/random/_bounded_integers.pyx
Processing numpy/random/_bounded_integers.pyx.in
Processing numpy/random/_common.pyx
Processing numpy/random/_generator.pyx
Processing numpy/random/_mt19937.pyx
Processing numpy/random/_pcg64.pyx
Processing numpy/random/_philox.pyx
Processing numpy/random/_sfc64.pyx