Skip to content

Instantly share code, notes, and snippets.

@sdewaele
sdewaele / getindex-zygote.jl
Last active Jan 25, 2020
setindex with copy to enable Zygote autodiff
View getindex-zygote.jl
using ZygoteRules:@adjoint
using Zygote
using Random
function ngradient(f, xs::AbstractArray...)
grads = zero.(xs)
for (x, Δ) in zip(xs, grads), i in 1:length(x)
δ = sqrt(eps())
tmp = x[i]
x[i] = tmp - δ/2
@sdewaele
sdewaele / expm.jl
Last active Feb 28, 2019 — forked from matthiasschabel/expm.jl
Julia translation of MATLAB expm function (matrix exponential) and test code in Julia and MATLAB
View expm.jl
using LinearAlgebra
import Base.exp
import LinearAlgebra.exp!
function expmchk()
# EXPMCHK Check the class of input A and
# initialize M_VALS and THETA accordingly.
m_vals = [3 5 7 9 13];
# theta_m for m=1:13.
theta = [#3.650024139523051e-008
You can’t perform that action at this time.