-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use generic broadcasting for complex numbers
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "LuxLib" | ||
uuid = "82251201-b29d-42c6-8e01-566dec8acb11" | ||
authors = ["Avik Pal <[email protected]> and contributors"] | ||
version = "1.3.9" | ||
version = "1.3.10" | ||
|
||
[deps] | ||
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@testitem "complex differentiation: issue #977" tags=[:misc] begin | ||
using Lux, Zygote, Random | ||
|
||
rng = Random.default_rng() | ||
Random.seed!(rng, 666) | ||
|
||
rbf(x) = exp.(-(x .^ 2)) | ||
|
||
U = Lux.Chain( | ||
Lux.Dense(1, 10, rbf), | ||
Lux.Dense(10, 3, rbf) | ||
) | ||
|
||
θ, st = Lux.setup(rng, U) | ||
|
||
function complex_step_differentiation(f::Function, x::Float64, ϵ::Float64) | ||
return imag(f(x + ϵ * im)) / ϵ | ||
end | ||
|
||
loss(t) = sum(complex_step_differentiation(τ -> U([τ], θ, st)[begin], t, 1e-5)) | ||
|
||
if pkgversion(LuxLib) ≥ v"1.3.10" | ||
@test only(Zygote.gradient(loss, 1.0)) isa Float64 | ||
else | ||
@test_broken only(Zygote.gradient(loss, 1.0)) isa Float64 | ||
end | ||
end |