Skip to content

Commit

Permalink
V0.1.2 (#9)
Browse files Browse the repository at this point in the history
* add keyword arguments in frule (#8)

* Update ForwardDiffChainRules.jl

add keyword arguments in frule

* Update runtests.jl

update kwargs test

* Update src/ForwardDiffChainRules.jl

Co-authored-by: Mohamed Tarek <[email protected]>

* Update runtests.jl

keywords should have default values

Co-authored-by: ThummeTo <[email protected]>
Co-authored-by: Mohamed Tarek <[email protected]>

* updated test (keyword argeuments)

* rm derivative along keyword

Co-authored-by: Xiaoming Fu <[email protected]>
Co-authored-by: Mohamed Tarek <[email protected]>
  • Loading branch information
3 people committed Dec 12, 2022
1 parent 7e11c82 commit 1ee1f68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ForwardDiffChainRules"
uuid = "c9556dd2-1aed-4cfe-8560-1557cf593001"
authors = ["MT <[email protected]>", "TT <[email protected]>"]
version = "0.1.1"
version = "0.1.2"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
2 changes: 1 addition & 1 deletion src/ForwardDiffChainRules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function _fd_frule(sig)
flat_ypartials1, _ = ForwardDiffChainRules.DifferentiableFlatten.flatten(ypartials1)
flat_ypartials = hcat(reshape(flat_ypartials1, :, 1), ntuple(Val(CS - 1)) do i
xpartialsi = unflattenx(flat_xpartials[:, i+1])
_, ypartialsi = ChainRulesCore.frule((NoTangent(), xpartialsi...), f, xprimals...)
_, ypartialsi = ChainRulesCore.frule((NoTangent(), xpartialsi...), f, xprimals...; ks...)
return ForwardDiffChainRules.DifferentiableFlatten.flatten(ypartialsi)[1]
end...)

Expand Down
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ SOFTWARE.
@test norm(g - I) < 1e-6
end
@testset "kwargs" begin
fkwarg(x; a = 2.0) = x * a
fkwarg(x1, x2; a = 2.0) = x1 * x2 * a
frule_count = 0
function ChainRulesCore.frule((_, Δx), ::typeof(fkwarg), x::Real; a = 2.0)
function ChainRulesCore.frule((_, Δx1, Δx2), ::typeof(fkwarg), x1::Real, x2::Real; a)
global frule_count += 1
println("frule was called")
return fkwarg(x; a), a * Δx
return fkwarg(x1, x2; a), a * x2 * Δx1 + a * x1 * Δx2
end
@ForwardDiff_frule fkwarg(x::ForwardDiff.Dual; kwargs...)
@test ForwardDiff.derivative(x -> fkwarg(x, a = 3.0), 2.0) == 3
@test frule_count == 1
@ForwardDiff_frule fkwarg(x1::ForwardDiff.Dual, x2::ForwardDiff.Dual; kwargs...)
@test ForwardDiff.gradient(x -> fkwarg(x[1], x[2], a = 3.0), [1.0, 2.0]) == [6, 3]
@test frule_count == 2
end
end

2 comments on commit 1ee1f68

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/73957

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 1ee1f685856eca6bcea9fda0ad547e6fc5857347
git push origin v0.1.2

Please sign in to comment.