Skip to content

Instantly share code, notes, and snippets.

@felixrehren
felixrehren / cumul.jl
Created April 22, 2018 09:39
multidimensional accumulation-decumulation for + and *
argtail(x, rest...) = rest
tail(x::Tuple) = argtail(x...)
# cumul.jl
inverse(::typeof(+),x::T) where {T} = -x
inverse(::typeof(*),x::T) where {T} = 1/x
accum(op,A) = accum!(op,zero(A),A)
accum!(op, B, A) = accum!(op,B,A,1:ndims(A))