2017-02-23 22:28:18 +00:00
|
|
|
using TensorFlow
|
|
|
|
Flux.loadtf()
|
|
|
|
|
|
|
|
@testset "TensorFlow" begin
|
|
|
|
|
2017-05-01 15:12:46 +00:00
|
|
|
xs, ys = rand(1, 20), rand(1, 20)
|
2017-02-23 22:28:18 +00:00
|
|
|
d = Affine(20, 10)
|
|
|
|
|
|
|
|
dt = tf(d)
|
|
|
|
@test d(xs) ≈ dt(xs)
|
|
|
|
|
2017-05-04 12:52:31 +00:00
|
|
|
test_tupleio(tf)
|
|
|
|
test_recurrence(tf)
|
|
|
|
test_stacktrace(tf)
|
2017-05-30 16:23:34 +00:00
|
|
|
test_anon(tf)
|
2017-05-01 17:05:17 +00:00
|
|
|
|
2017-02-23 22:28:18 +00:00
|
|
|
@testset "Tensor interface" begin
|
|
|
|
sess = TensorFlow.Session()
|
|
|
|
X = placeholder(Float32)
|
2017-06-05 15:32:16 +00:00
|
|
|
Y = Flux.TF.astensor(d, X)
|
2017-04-27 11:48:11 +00:00
|
|
|
run(sess, global_variables_initializer())
|
2017-02-23 22:28:18 +00:00
|
|
|
|
2017-05-01 17:27:52 +00:00
|
|
|
@test run(sess, Y, Dict(X=>xs)) ≈ d(xs)
|
2017-02-23 22:28:18 +00:00
|
|
|
end
|
|
|
|
|
2017-06-08 05:05:31 +00:00
|
|
|
@testset "Ops" begin
|
2017-06-09 05:23:54 +00:00
|
|
|
A = randn(Float32,(5,5))
|
2017-08-01 05:28:14 +00:00
|
|
|
# u,s,v = tf(@net x -> svd(x))(A)
|
|
|
|
# @test A ≈ u*diagm(s)*transpose(v)
|
2017-06-09 05:05:09 +00:00
|
|
|
@test tf(@net x -> inv(x))(A) ≈ inv(A)
|
|
|
|
@test tf(@net x -> det(x))(A) ≈ det(A)
|
2017-06-09 05:36:38 +00:00
|
|
|
A = randn(Float32,(6,3))
|
|
|
|
@test tf(@net x -> transpose(x))(A) ≈ transpose(A)
|
2017-06-09 06:25:47 +00:00
|
|
|
A = randn(Float32,(6,3,2))
|
|
|
|
@test tf(@net (x,y) -> permutedims(x,y))(A,[3,2,1]) ≈ permutedims(A,[3,2,1])
|
2017-06-09 10:06:37 +00:00
|
|
|
A1 = randn(Float32,(4,1))
|
|
|
|
A2 = randn(Float32,(4,1))
|
|
|
|
@test tf(@net (x,y) -> cat(2,x,y))(A1,A2) ≈ cat(2,A1,A2)
|
2017-06-09 10:13:30 +00:00
|
|
|
@test tf(@net x -> length(x))(A1) == length(A1)
|
2017-06-09 19:17:54 +00:00
|
|
|
A = randn(Float32,(5,5))
|
|
|
|
@test tf(@net x -> diag(x))(A) ≈ diag(A)
|
2017-06-09 19:32:50 +00:00
|
|
|
A = randn(Float32,(5,))
|
|
|
|
@test tf(@net x -> diagm(x))(A) ≈ diagm(A)
|
2017-06-09 19:42:38 +00:00
|
|
|
A = randn(4,5)
|
|
|
|
@test tf(@net x -> size(x))(A) == [4,5]
|
|
|
|
@test tf(@net (x,y) -> size(x,y))(A,1) == 4
|
2017-06-09 19:50:25 +00:00
|
|
|
A = randn(6,5)
|
|
|
|
A = A'*A
|
|
|
|
@test tf(@net x -> chol(x))(A) ≈ chol(A)
|
2017-06-08 18:59:46 +00:00
|
|
|
end
|
2017-06-08 05:05:31 +00:00
|
|
|
|
2017-02-23 22:28:18 +00:00
|
|
|
end
|