Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neuralpde #65

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesOverloadGeneration = "f51149dc-2911-5acf-81fc-2076a2a81d4f"
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
SliceMap = "82cb661a-3f19-5665-9e27-df437c7e54c8"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Expand All @@ -19,7 +18,6 @@ ChainRules = "1"
ChainRulesCore = "1"
ChainRulesOverloadGeneration = "0.1"
IrrationalConstants = "0.2"
SliceMap = "0.2"
SpecialFunctions = "2"
SymbolicUtils = "1"
Zygote = "0.6.55"
Expand Down
11 changes: 11 additions & 0 deletions src/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function rrule(::typeof(*), A::AbstractMatrix{S},
return A * t, gemv_pullback
end

function rrule(::typeof(*), A::AbstractMatrix{S},
B::AbstractMatrix{TaylorScalar{T, N}}) where {N, S, T}
project_A = ProjectTo(A)
project_B = ProjectTo(B)
function gemm_pullback(x̄)
= unthunk(x̄)
NoTangent(), @thunk(project_A(X̄ * transpose(B))), @thunk(project_B(transpose(A) * X̄))
end
return A * B, gemm_pullback
end

@adjoint function +(t::Vector{TaylorScalar{T, N}}, v::Vector{T}) where {N, T}
project_v = ProjectTo(v)
t + v, x̄ -> (x̄, project_v(x̄))
Expand Down
7 changes: 4 additions & 3 deletions src/derivative.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using SliceMap
export derivative

"""
Expand Down Expand Up @@ -56,10 +55,12 @@ end

@inline function derivative(f, x::AbstractMatrix{T}, vN::Val{N}) where {T <: TN, N}
size(x)[1] != 1 && @warn "x is not a row vector."
mapcols(u -> derivative(f, u[1], vN), x)
t = make_taylor.(x, one(N), vN)
return extract_derivative.(f(t), N)
end

@inline function derivative(f, x::AbstractMatrix{T}, l::AbstractVector{S},
vN::Val{N}) where {T <: TN, S <: TN, N}
mapcols(u -> derivative(f, u, l, vN), x)
t = make_taylor.(x, l, vN)
return extract_derivative.(f(t), N)
end
Loading