GiggleLiu / NiLang.jl

A differential eDSL that can run faster than light and go back to the past.
https://giggleliu.github.io/NiLang.jl/dev
Apache License 2.0
250 stars 16 forks source link

Make GVar more clever #47

Closed GiggleLiu closed 3 years ago

GiggleLiu commented 3 years ago
julia> using NiLang

julia> struct A{T}
           x::T
           y
       end

julia> _zero(A(2.0, 3.0))
A{Float64}(0.0, 0.0)

julia> struct B{T}
           z::Vector{T}
           a::A{T}
       end

julia> _zero(B(randn(4), A(2.0, 3.0)))
B{Float64}([0.0, 0.0, 0.0, 0.0], A{Float64}(0.0, 0.0))

julia> _zero(ComplexF32)
0.0f0 + 0.0f0im

julia> NiLang.AD.GVar(_zero(B(randn(4), A(2.0, 3.0))))
B{NiLang.AD.GVar{Float64, Float64}}(NiLang.AD.GVar{Float64, Float64}[GVar(0.0, 0.0), GVar(0.0, 0.0), GVar(0.0, 0.0), GVar(0.0, 0.0)], A{NiLang.AD.GVar{Float64, Float64}}(GVar(0.0, 0.0), GVar(0.0, 0.0)))