Skip to content

Instantly share code, notes, and snippets.

View jekbradbury's full-sized avatar

James Bradbury jekbradbury

View GitHub Profile
@JonathanRaiman
JonathanRaiman / human.cpp
Last active November 27, 2018 02:25
Code auto generated by Dali
auto a = op::uniform(-20.0, 20.0, {2, 5}).astype(dtype);
a.eval();
auto exped = op::exp(a - op::max(a, {-1}, true));
auto fused_softmax = exped / op::sum(exped, {-1}, true);
@tbeason
tbeason / fulltabular.jl
Created January 22, 2018 17:02
a more-featured LaTeX table printing function
using LatexPrint
function fulltabular(A::AbstractArray{T,2}; placement::String="htb",rounding::Int=0, colnames::Vector{String}=Vector{String}(), frontmatter::String="" , caption::String="", title::String="", label::String="", strfirstcol::Bool=false,arraystretch=1) where {T<:Any}
(r,c) = size(A)
println("\\begin{table}[", placement, "] \\centering")
println("\\renewcommand{\\arraystretch}{",arraystretch ,"}")
println(frontmatter)
if !isempty(title)
println("\\caption{", title, "}")
@maleadt
maleadt / tinycassette.jl
Last active April 12, 2018 10:47
Reimplementation of Cassette's core mechanics
module Cassette
using Logging
# wrapper for overdubbing functions
struct Overdub{F,C}
func::F
context::C
Overdub(f::F, c::C=nothing) where {F,C} = new{F,C}(f,c)
end
using InteractiveUtils
const Compiler = Core.Compiler
function method_match_to_ir(methds, types)
if length(methds) != 1
@show methds
@assert false
end
x = methds[1]
meth = Core.Main.Base.func_for_method_checked(x[3], types)
@pfitzseb
pfitzseb / TraceCalls.jl
Created December 17, 2018 15:10
TraceCalls.jl with Cassette
module TraceCalls
using Cassette
mutable struct Trace
level::Int
cutoff::Int
end
Cassette.@context TraceCtx
@maxbennedich
maxbennedich / sparse_show.jl
Last active January 16, 2019 14:28
Braille plot sparse show
const BRAILLE = split("⠀⠁⠂⠄⡀⠈⠐⠠⢀", "") .|> s -> Int(s[1])
function show_any_nonzero(S::SparseMatrixCSC; maxw = displaysize(stdout)[2], maxh = displaysize(stdout)[1]-3)
h,w = size(S)
h > 4maxh && (w = max(1, (w*4maxh+h÷2)÷h); h = 4maxh)
w > 2maxw && (h = max(1, (h*2maxw+w÷2)÷w); w = 2maxw)
P = fill(BRAILLE[1], (w+3)÷2, (h+3)÷4)
P[end, :].=10
@inbounds for c = 0:w-1, r = 0:h-1
_anynz(S, r*S.m÷h+1, c*S.n÷w+1, (r+1)*S.m÷h, (c+1)*S.n÷w) &&
from functools import partial
import numpy.random as npr
import jax.numpy as np
from jax import lax
from jax import grad, pjit, papply
### set up some synthetic data
@rntz
rntz / Runtime.hs
Created February 14, 2019 21:38
A seminaïve, mildly optimizing compiler from modal Datafun to Haskell, in OCaml.
-- The Datafun runtime.
module Runtime where
import qualified Data.Set as Set
import Data.Set (Set)
class Eq a => Preord a where
(<:) :: a -> a -> Bool
class Preord a => Semilat a where
@staticfloat
staticfloat / fix_nvidia
Created March 8, 2019 23:47
Fixer script for NVidia driver installs on dkms-compatible systems
#!/usr/bin/env bash
function red_echo()
{
tput setaf 1
echo "$*"
tput sgr0
}
if [[ "$*" == *--help* ]]; then
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.