Flux.jl/test/basic.jl
Mike J Innes ced8d80135 hmm
2017-05-30 17:23:42 +01:00

41 lines
893 B
Julia
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

syntax(v::Vertex) = prettify(DataFlow.syntax(v))
syntax(x) = syntax(graph(x))
@testset "Basics" begin
xs = randn(1, 10)
d = Affine(10, 20)
@test d(xs) (xs*d.W.x + d.b.x)
d1 = @net x -> x * d.W + d.b
@test Flux.infer(d, (1, 10)) == (1,20)
# Skip this before new DataFlow is released.
# let
# @test @capture(syntax(d), _Frame(_Line((+).(x_[1] * W_, b_))))
# @test isa(x, DataFlow.Input) && isa(W, Param) && isa(b, Param)
# end
test_anon(identity)
let a1 = Affine(10, 20), a2 = Affine(20, 15)
tlp = TLP(a1, a2)
@test tlp(xs) softmax(a2(σ(a1(xs))))
@test Flux.interpmodel(tlp, xs) softmax(a2(σ(a1(xs))))
@test Flux.infer(tlp, (1, 10)) == (1,15)
end
let tlp = TLP(Affine(10, 21), Affine(20, 15))
e = try
Flux.interpmodel(tlp, rand(1, 10))
catch e
e
end
@test e.trace[end].func == :TLP
@test e.trace[end-1].func == Symbol("Flux.Affine")
end
end