Skip to content

Instantly share code, notes, and snippets.

Avatar
😼
Feeling cool

Kai Xu xukai92

😼
Feeling cool
View GitHub Profile
@xukai92
xukai92 / set_ssl.jl
Last active Jun 26, 2020
Resolve the SSL issue with Julia's Pkg
View set_ssl.jl
using LibGit2
LibGit2.set_ssl_cert_locations("/etc/ssl/certs/ca-certificates.crt")
@xukai92
xukai92 / generated_quantile.jl
Last active Jun 26, 2020
Generated quantiles with Turing.jl
View generated_quantile.jl
# Modifed from https://github.com/cambridge-mlg/Covid19/blob/master/src/utils.jl#L79
function generated_quantities(m::Turing.Model, c::MCMCChains.Chains)
# If `c` is multiple chains, we convert them into a single chain
chain = length(chains(c)) == 1 ? c : MCMCChains.pool_chain(c)
vi = Turing.DynamicPPL.VarInfo(m)
return map(1:length(chain)) do i
Turing.DynamicPPL._setval!(vi, chain[i])
m(vi)
end
end
@xukai92
xukai92 / ahmc_gpu.jl
Created Oct 26, 2020
AHMC GPU improvements
View ahmc_gpu.jl
using Random: AbstractRNG, GLOBAL_RNG
using AdvancedHMC: PhasePoint, phasepoint
function AdvancedHMC.refresh(
rng::Union{AbstractRNG, AbstractVector{<:AbstractRNG}},
z::PhasePoint{T},
h::Hamiltonian
) where {T<:CuArray}
r = CuArray{Float32, 2}(undef, size(h.metric)...)
CUDA.CURAND.randn!(r)
@xukai92
xukai92 / takeuntil.jl
Created Nov 24, 2020
A variant of `takeuntil` from IterTools.jl
View takeuntil.jl
struct TakeUntil{I}
cond::Function
xs::I
end
"""
takeuntil(cond, xs)
An iterator that yields values from the iterator `xs` as long as the
predicate `cond` is true. Unlike `takewhile`, it also take the last
value for which the predicate `cond` is false.
@xukai92
xukai92 / mwe.jl
Last active Feb 24, 2021
`invokelatest` vs `mk_function`
View mwe.jl
using InteractiveUtils
versioninfo()
using DrWatson
@quickactivate
using Comonicon, Test, BenchmarkTools, ExprOptimization
using ExprOptimization.ProbabilisticExprRules: RuleNode, mindepth_map, ProbabilisticGrammar
using GeneralizedGenerated: mk_function