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

Bring over tests from ChainRulesCore. And report possible bug. #1228

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 18 additions & 1 deletion test/chainrules.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
using StaticArrays, ChainRulesCore, ChainRulesTestUtils, JLArrays, Test

@testset "Chain Rules Integration" begin
@testset "ChainRules Integration" begin
@testset "Projection" begin
# There is no code for this, but when argument isa StaticArray, axes(x) === axes(dx)
# implies a check, and reshape will wrap a Vector into a static SizedVector:
pstat = ProjectTo(SA[1, 2, 3])
@test axes(pstat(rand(3))) === (SOneTo(3),)

# This recurses into structured arrays:
pst = ProjectTo(transpose(SA[1, 2, 3]))
@test axes(pst(rand(1,3))) === (SOneTo(1), SOneTo(3))
@test pst(rand(1,3)) isa Transpose

# When the argument is an ordinary Array, static gradients are allowed to pass,
# like FillArrays. Collecting to an Array would cost a copy.
pvec3 = ProjectTo([1, 2, 3])
@test pvec3(SA[1, 2, 3]) isa StaticArray
end

@testset "Constructor rrules"
oxinabox marked this conversation as resolved.
Show resolved Hide resolved
test_rrule(SMatrix{1, 4}, (1.0, 1.0, 1.0, 1.0))
test_rrule(SMatrix{4, 1}, (1.0, 1.0, 1.0, 1.0))
test_rrule(SMatrix{2, 2}, (1.0, 1.0, 1.0, 1.0))
Expand Down
Loading