-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. test common 2. docs
- Loading branch information
Showing
6 changed files
with
314 additions
and
6 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
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,66 @@ | ||
module CommonTest | ||
|
||
using Test | ||
using TrixiEnzyme | ||
using TrixiEnzyme:Enzyme | ||
using ForwardDiff | ||
|
||
# %% | ||
|
||
function foo!(y, x, cache) | ||
cache .= x.^2 | ||
y .= 2cache | ||
return nothing | ||
end | ||
|
||
function foo!(y, x) | ||
y .= 2*(x.^2) | ||
return nothing | ||
end | ||
# %% | ||
|
||
|
||
x = ones(3) | ||
y = similar(x) | ||
cache = similar(x) | ||
|
||
dx = Enzyme.onehot(x) | ||
dy = ntuple(_->zeros(size(x)), length(x)) | ||
dcache = ntuple(_->zeros(size(x)), length(x)) | ||
|
||
dcache1 = similar(x) | ||
dx1 = zero(x) | ||
dx1[1] = 1.0 | ||
dy1 = similar(x) | ||
|
||
autodiff(Forward, foo!, BatchDuplicated(y, dy), BatchDuplicated(x, dx)) | ||
J1 = stack(dy) | ||
|
||
autodiff(Forward, foo!, BatchDuplicated(y, dy), BatchDuplicated(x, dx), BatchDuplicatedNoNeed(cache, dcache)) | ||
J2 = stack(dy) | ||
|
||
autodiff(Forward, foo!, BatchDuplicated(y, dy), BatchDuplicated(x, dx), BatchDuplicated(cache, dcache)) | ||
J3 = stack(dy) | ||
|
||
autodiff(Forward, foo!, Duplicated(y, dy1), Duplicated(x, dx1), DuplicatedNoNeed(cache, dcache1)) | ||
|
||
|
||
# %% | ||
@info "testing foo!(y, x, cache)" | ||
|
||
|
||
# cfg = ForwardDiff.JacobianConfig(nothing, y, x, ForwardDiff.Chunk(2)) | ||
cfg = ForwardDiff.JacobianConfig(nothing, y, x) | ||
uEltype = eltype(cfg) | ||
nan_uEltype=convert(uEltype, NaN) | ||
cache=fill(nan_uEltype, length(x)) | ||
|
||
J = ForwardDiff.jacobian(y, x, cfg) do y,x | ||
foo!(y, x, cache) | ||
end | ||
|
||
@test J == J1 == J2 == J3 | ||
|
||
@test J[:, 1] == dy1 | ||
|
||
end |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[deps] | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
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,3 +1,11 @@ | ||
using Test, TrixiEnzyme | ||
|
||
@test out == 5 | ||
@testset "TrixiEnzyme.jl" begin | ||
t0 = time() | ||
@testset "Common" begin | ||
println("##### Testing Common...") | ||
t = @elapsed include("CommonTest.jl") | ||
println("##### done (took $t seconds).") | ||
end | ||
println("##### Running all TrixiEnzyme tests took $(time() - t0) seconds.") | ||
end |