Skip to content

Instantly share code, notes, and snippets.

View femtomc's full-sized avatar
:shipit:
This is the way.

McCoy R. Becker femtomc

:shipit:
This is the way.
View GitHub Profile
[[package]]
name = "absl-py"
version = "1.2.0"
description = "Abseil Python Common Libraries, see https://github.com/abseil/abseil-py."
category = "main"
optional = false
python-versions = ">=3.6"
[[package]]
name = "alabaster"
@femtomc
femtomc / CollapsingTowers.scala
Created July 30, 2022 21:19 — forked from TiarkRompf/CollapsingTowers.scala
compilation by interpreting* staged interpreters
/* collapsing multiple levels of interpreters */
object TestMeta3 {
abstract class Exp
case class Lit(n:Int) extends Exp
case class Sym(s:String) extends Exp
case class Var(n:Int) extends Exp
case class App(e1:Exp, e2:Exp) extends Exp
case class Lam(e:Exp) extends Exp
# Recursively wraps function calls with the below generated function call and inserts the context argument.
function remix!(ir, hooks = false)
pr = IRTools.Pipe(ir)
new = argument!(pr)
for (v, st) in pr
ex = st.expr
ex isa Expr && ex.head == :call && begin
if !(ex.args[1] isa GlobalRef && (ex.args[1].mod == Base || ex.args[1].mod == Core))
args = copy(ex.args)
ex = Expr(:call, :remix!, new, ex.args...)
@femtomc
femtomc / interactive.sh
Last active May 13, 2020 14:43
A command line tool for watching Julia src and executing arbitrary files.
#!/usr/bin/env julia
# Check if Revise is installed.
using Pkg
try
Pkg.status("Revise")
catch e
error("\n\033[0;31mRevise not installed to your global environment. Please install Revise.\033[0m\n\033[0;32mUse 'using Pkg; Pkg.add(\"Revise\")' at REPL.\033[0m\n")
end
using Revise
module ReverseModeADwithContexts
using Cassette
Cassette.@context J; # J is the notation for the function which generates pullbacks (the lambda terms you see below)
# Equivalent to gradient tape.
mutable struct ReverseTrace
gradient_tape::Array{Function, 1}
ReverseTrace() = new([])
-- Autodiff using algebraic effects
-- Simple reverse mode with a gradient tape
use .base
ability Differentiable where
cos : Float -> Float
sin : Float -> Float
exp : Float -> Float