Skip to content

Instantly share code, notes, and snippets.

View mschauer's full-sized avatar

Moritz Schauer mschauer

View GitHub Profile
@mschauer
mschauer / diff.txt
Created June 30, 2017 13:54
Ellipsis notation
iff --git a/src/Bridge.jl b/src/Bridge.jl
index 0653f9e..a633742 100644
--- a/src/Bridge.jl
+++ b/src/Bridge.jl
@@ -11,6 +11,7 @@ export thetamethod, thetamethod!, thetainnovations!, thetainnovations, heun, heu
export ullikelihood, ullikelihoodtrapez, uinnovations!, ubridge
using Distributions
+using EllipsisNotation
import Base.rand
@mschauer
mschauer / RandFromRanges.jl
Created July 1, 2017 06:34
RandFromRanges
import Base: start, next, done, length
type RandFromRangeDown
k::Int
mask::Int
end
RandFromRangeDown(k) = RandFromRangeDown(k,2^16-1)
_rnd(::RandFromRangeDown) = Base.Random.rand_ui52_raw(Base.Random.GLOBAL_RNG)
mm(n,k) = div(n,k)*k
function start(rfr::RandFromRangeDown)
@mschauer
mschauer / matprint.jl
Created August 1, 2017 11:43
Custom Matrix print
function Base.show(io::IO, ::MIME"text/plain", pwm::MyT)
# ...
end
function has_path(g::AbstractGraph, u::Integer, v::Integer; exclude_vertices::AbstractVector=Vector{eltype(g)}())
T = eltype(g)
seen = falses(nv(g))
next = Vector{T}()
push!(next, u)
excludeset = Set(exclude_vertices)
while !isempty(next)
src = shift!(next) #Get first element
src in excludeset && continue
vertexneighbors = neighbors(g, src)
@mschauer
mschauer / unshaped.jl
Created August 7, 2017 18:18
Forget the shape
using Base.Iterators
import Base: done, next, start, length, eltype, iteratorsize, HasShape, HasLength
struct UnshapedIterator{I}
it::I
UnshapedIterator{I}(it::I, a::HasShape) = new{I}(it)
UnshapedIterator{I}(it::I, a::HasLength) = new{I}(it)
end
@mschauer
mschauer / exceptions.jl
Last active August 18, 2017 19:30
Undocumented exceptions
"ArgumentError"
"AssertionError"
"Base.DNSError" No documentation found.
"Base.Distributed.BatchProcessingError" No documentation found.
"Base.LibGit2.Error.GitError" No documentation found.
"Base.LinAlg.ARPACKException" No documentation found.
"Base.LinAlg.LAPACKException" No documentation found.
"Base.LinAlg.PosDefException" No documentation found.
"Base.LinAlg.RankDeficientException" No documentation found.
"Base.LinAlg.SingularException" No documentation found.
@mschauer
mschauer / ode.jl
Created August 10, 2017 14:30
ode
using BenchmarkTools
using StaticArrays
function kernelrk(f, t, y, dt)
k1 = f(t, y)
k2 = f(t + 1/2*dt, y + 1/2*dt*k1)
k3 = f(t + 3/4*dt, y + 3/4*dt*k2)
y! = y + dt*(2/9*k1 + 1/3*k2 + 4/9*k3)
# k4 = f(t + dt, y‘)
# zn1 = y + dt*(7/24*k1 + 1/4*k2 + 1/3*k3 + 1/8*k4)
@mschauer
mschauer / ode.jl
Last active August 11, 2017 07:11
zero allocation
using Bridge, Distributions, StaticArrays
using Base.Test
"""
kernelrk(f, t, y, dt, P)
Ralston (1965) update (order 3 step of the Bogacki–Shampine 1989 method)
to solve ``y(t + dt) - y(t) = \\int_t^{t+dt} f(s, y(s)) ds``.
"""
function kernelrk(f, t, y, dt, P)
@mschauer
mschauer / Bridge.md
Last active August 13, 2017 13:26
Bridge docs

Bridge.jl

Documentation for Bridge.jl

@mschauer
mschauer / Wiener
Last active August 22, 2017 18:56
Wiener
using Bridge, StaticArrays
Ps = [Wiener{Float64}(), Wiener{Complex{Float64}}(), Wiener{SVector{2,Float64}}()]
Xs = [sample([0.0, 0.5, 1.0], P) for P in Ps]