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

Fix DifferentiationInterfaceTest tutorial #335

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
More stuff
  • Loading branch information
gdalle committed Jun 26, 2024
commit 40e7ae180c20a4ab5c4e22738085e960982b0038
1 change: 0 additions & 1 deletion DifferentiationInterface/docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ makedocs(;
"Reference" => ["operators.md", "backends.md", "api.md"],
"Advanced" => ["dev_guide.md", "overloads.md"],
],
checkdocs=:exports,
plugins=[links],
)

Expand Down
1 change: 1 addition & 0 deletions DifferentiationInterfaceTest/docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
DifferentiationInterfaceTest = "a82114a7-5aa3-49a8-9643-716bb13727a3"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Expand Down
1 change: 1 addition & 0 deletions DifferentiationInterfaceTest/docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DifferentiationInterface
using DifferentiationInterfaceTest
using Documenter
using DocumenterInterLinks

using BenchmarkTools: BenchmarkTools
using DataFrames: DataFrames
Expand Down
2 changes: 1 addition & 1 deletion DifferentiationInterfaceTest/docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ xv = rand(Float32, 3)
xm = rand(Float64, 3, 2)
scenarios = [
GradientScenario(f; x=xv, y=f(xv), grad=∇f(xv), nb_args=1, place=:inplace),
GradientScenario(f; x=xm, y=f(xm), grad=∇f(xv), nb_args=1, place=:inplace)
GradientScenario(f; x=xm, y=f(xm), grad=∇f(xm), nb_args=1, place=:inplace)
];
nothing # hide
```
Expand Down
26 changes: 24 additions & 2 deletions DifferentiationInterfaceTest/src/scenarios/scenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ This generic type should never be used directly: use the specific constructor co
# Fields

$(TYPEDFIELDS)

Note that the `res1` and `res2` fields are given more meaningful names in the keyword arguments of each specialized constructor.
For example:

- the keyword `grad` of `GradientScenario` becomes `res1`
- the keyword `hess` of `HessianScenario` becomes `res2`, and the keyword `grad` becomes `res1`
"""
struct Scenario{op,args,pl,F,X,Y,D,R1,R2}
"function `f` (if `args==1`) or `f!` (if `args==2`) to apply"
Expand All @@ -35,9 +41,9 @@ struct Scenario{op,args,pl,F,X,Y,D,R1,R2}
y::Y
"seed for pushforward, pullback or HVP"
seed::D
"first-order result"
"first-order result of the operator"
res1::R1
"second-order result"
"second-order result of the operator (when it makes sense)"
res2::R2

function Scenario{op,args,pl}(
Expand Down Expand Up @@ -120,20 +126,26 @@ end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `pushforward` and its variants.
"""
function PushforwardScenario(f; x, y, dx, dy=nothing, nb_args, place=:inplace)
return Scenario{:pushforward,nb_args,place}(f; x, y, seed=dx, res1=dy, res2=nothing)
end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `pullback` and its variants.
"""
function PullbackScenario(f; x, y, dy, dx=nothing, nb_args, place=:inplace)
return Scenario{:pullback,nb_args,place}(f; x, y, seed=dy, res1=dx, res2=nothing)
end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `derivative` and its variants.
"""
function DerivativeScenario(f; x, y, der=nothing, nb_args, place=:inplace)
return Scenario{:derivative,nb_args,place}(
Expand All @@ -143,20 +155,26 @@ end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `gradient` and its variants.
"""
function GradientScenario(f; x, y, grad=nothing, nb_args, place=:inplace)
return Scenario{:gradient,nb_args,place}(f; x, y, seed=nothing, res1=grad, res2=nothing)
end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `jacobian` and its variants.
"""
function JacobianScenario(f; x, y, jac=nothing, nb_args, place=:inplace)
return Scenario{:jacobian,nb_args,place}(f; x, y, seed=nothing, res1=jac, res2=nothing)
end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `second_derivative` and its variants.
"""
function SecondDerivativeScenario(
f; x, y, der=nothing, der2=nothing, nb_args, place=:inplace
Expand All @@ -168,13 +186,17 @@ end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `hvp` and its variants.
"""
function HVPScenario(f; x, y, dx, grad=nothing, dg=nothing, nb_args, place=:inplace)
return Scenario{:hvp,nb_args,place}(f; x, y, seed=dx, res1=grad, res2=dg)
end

"""
$(SIGNATURES)

Construct a [`Scenario`](@ref) to test `hessian` and its variants.
"""
function HessianScenario(f; x, y, grad=nothing, hess=nothing, nb_args, place=:inplace)
return Scenario{:hessian,nb_args,place}(f; x, y, seed=nothing, res1=grad, res2=hess)
Expand Down
Loading