Skip to content

Instantly share code, notes, and snippets.

View penelopeysm's full-sized avatar

Penelope Yong penelopeysm

View GitHub Profile
@penelopeysm
penelopeysm / benchmark.jl
Created March 23, 2026 18:02
benchmark script
using DynamicPPL, Distributions, LogDensityProblems, Chairmarks, LinearAlgebra
using ADTypes, ForwardDiff, ReverseDiff, Enzyme, Mooncake
const adtypes =
[
("FD", AutoForwardDiff()),
("RD", AutoReverseDiff()),
("RC", AutoReverseDiff(; compile=true)),
("MC", AutoMooncake()),
("EF" => AutoEnzyme(; mode=set_runtime_activity(Forward))),
@penelopeysm
penelopeysm / .bash_profile
Last active March 18, 2026 00:10
PackageCompiler + various Julia formatters
# JuliaFormatter and Runic sysimages
# adapted from https://github.com/domluna/JuliaFormatter.jl/issues/633#issuecomment-1518805248
# Place this in `~/.bash_profile` (or the corresponding config file for your shell).
# You should then be able to run the following commands in your shell:
#
# - `jf1`: Format with JuliaFormatter@v1
# - `jf2`: Format with JuliaFormatter@v2
# - `runic`: Format with Runic
#

Julia Vararg + Function-type specialization bug

The problem

When a Function subtype (like sum, a closure, etc.) is passed as an element of Vararg{Any,N}, Julia's compiler heuristic widens typeof(sum) to Function in the method specialization. This creates a less-specialized method instance that prevents optimization — leading to heap allocations and ~20x slowdowns.

Critically, **@code_warntype, @code_typed, @code_llvm, and @code_native

@penelopeysm
penelopeysm / chain.jl
Last active December 8, 2025 11:42
chain rule with mooncake
using Mooncake
using Mooncake: CoDual, NoFData, NoRData, zero_fcodual, primal
import Mooncake: rrule!!
foo(x::Vector{Float64}) = map(sin, x)
function rrule!!(::CoDual{typeof(foo)}, x::CoDual{Vector{Float64}})
x_p, x_fdata = x.x, x.dx
y = map(sin, x_p)
function foo_pb!!(dy::Vector{Float64})
x_fdata .+= map(cos, x_p) .* dy
@penelopeysm
penelopeysm / juliacon.md
Last active October 2, 2025 23:53
Turing @ JuliaCon
@penelopeysm
penelopeysm / powerpoint_fonts.sh
Last active September 25, 2025 14:47
Bash function to create a new theme font for PowerPoint
ppt() {
# Create a PowerPoint theme font XML file for a given font name
[ -z "$1" ] && { echo "Usage: ppt \"<font name>\" (don't forget to quote fonts with spaces)"; return 1; }
echo "Creating PowerPoint theme font XML for font: $1. Your admin password may be required."
fontname_no_space=$(echo "$1" | sed 's/ /_/g')
OLDPWD=$(pwd)
PPTDIR='/Applications/Microsoft PowerPoint.app/Contents/Resources/Office Themes/Theme Fonts'
cd "${PPTDIR}"
sudo cp 'Calibri.xml' "${fontname_no_space}.xml"
sudo sed -i '' "s/Calibri/$1/g" "${fontname_no_space}.xml"
@penelopeysm
penelopeysm / mcmc_basic.jl
Last active October 9, 2024 21:18
Swan dataset (DOI: 10.1111/gcb.15151)
using Distributions
function p(x)
return pdf(Normal(0, 1), x)
end
function mcmc(p, N)
samples = []
# Initial sample