Skip to content

Instantly share code, notes, and snippets.

View jrevels's full-sized avatar

Jarrett Revels jrevels

View GitHub Profile
using Cassette, Test
using Cassette: @context, enabletagging, @overdub, overdub, recurse,
hasmetadata, metadata, tag, untag
using ChainRules: frule, Zero, extern
@context DiffCtx
Cassette.metadatatype(::Type{<:DiffCtx}, ::Type{T}) where {T<:Real} = T
function D(f, x)
using ForwardDiff, ReverseDiff, BenchmarkTools
mutable struct MyJacobianWrapper{fType,tType} <: Function
f::fType
t::tType
end
function (ff::MyJacobianWrapper)(u, p)
du1 = similar(p, size(u))
ff.f(du1,u,p,ff.t)
using ForwardDiff, ReverseDiff, BenchmarkTools
n = 100
x = rand(n)
v = rand(n)
tape = ReverseDiff.compile(ReverseDiff.GradientTape(cumprod, rand(n)))
vJ = rand(n)'
function vecjacobian_new!(vJ, v, tape, x)
input = ReverseDiff.input_hook(tape)
# NOTE: Make sure to run this in a "fresh" session. If the method you're invoking
# has already been compiled, then the compiler might grab its old results instead
# of populating the cache we're constructing here.
mymethod = # callable value you want to check
mysig = Tuple{typeof(mymethod), #= types of arguments here =#}
p = Core.Compiler.Params(typemax(UInt))
Core.Compiler.typeinf_code(methods(mymethod).ms[end], mysig, Core.svec(), false, p)
Core.show(map(((i, x),) -> (i, x.result, x.linfo), enumerate(p.cache)))
using ReverseDiff, ForwardDiff
x, v = rand(3), rand(3)
tp = ReverseDiff.InstructionTape()
tx = ReverseDiff.track(x, tp)
ty = cumprod(tx)
ReverseDiff.increment_deriv!(ty, v)
ReverseDiff.reverse_pass!(tp)
# Basic example.
using Stheno
using Stheno: GPC
# Define model.
function gp(σ, l)
g = GP(EQ(), GPC())
f = σ * g ∘ (x->l * x)
return g, f
end
diff --git a/llvm2.log b/llvm1.log
index e9e65c0..2544cf0 100644
--- a/llvm2.log
+++ b/llvm1.log
@@ -8,30 +8,32 @@ CodeInfo(
└─── goto #6 if not %6
5 ── invoke Base.getindex(()::Tuple, 1::Int64)::Union{}
└─── $(Expr(:unreachable))::Union{}
- 6 ── goto #7
- 7 ── goto #8
diff --git a/llvm1.log b/llvm2.log
index 99f9319..be6ed79 100644
--- a/llvm1.log
+++ b/llvm2.log
@@ -1,13 +1,13 @@
; Function f
-; Location: REPL[18]:1
-define nonnull %jl_value_t addrspace(10)* @japi1_f_249602385(%jl_value_t addrspace(10)*, %jl_value_t addrspace(10)**, i32) #0 {
+; Location: REPL[9]:1
+define nonnull %jl_value_t addrspace(10)* @japi1_f_94174783(%jl_value_t addrspace(10)*, %jl_value_t addrspace(10)**, i32) #0 {
$ cat ../../wip.jl
using InteractiveUtils
# code_llvm(exp, Tuple{Float64})

function f(x)
  _1 = exp(x)
  _2 = exp(x)
  return _1 + _2
end
using Cassette
using Core: CodeInfo, SlotNumber, SSAValue
Cassette.@context Ctx
struct Slice end
const SLICE = Slice()
function Cassette.execute(ctx::Ctx, ::Slice, callback, f, args...)