From ee2e388228121d3401592a0642a0a26f5779c938 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Thu, 8 Jun 2017 07:05:31 +0200 Subject: [PATCH 1/6] add svd --- src/backend/tensorflow/graph.jl | 1 + test/backend/tensorflow.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index 71499ac8..c27ffec4 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -27,6 +27,7 @@ graph(::typeof(max), x, dim=nothing) = TensorFlow.reduce_max(x;axis=dim) graph(::typeof(all), x, dim=nothing) = TensorFlow.reduce_all(x;axis=dim) graph(::typeof(any), x, dim=nothing) = TensorFlow.reduce_any(x;axis=dim) graph(::typeof(mean), x, dim=nothing) = TensorFlow.reduce_mean(x;axis=dim) +graph(::typeof(svd), x) = svd(x) for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos, sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj) diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index 00f45c95..fd5e6a93 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -23,4 +23,18 @@ test_anon(tf) @test run(sess, Y, Dict(X=>xs)) ≈ d(xs) end +@testset "Ops" begin + +error_margin = 1e-4 + +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +# svd +A = convert(Array{Float32},randn(5,5)) +@net f(x) = svd(x) +m = tf(f) +u,s,v = m(A) +@test maximum(abs.(u*diagm(s)*transpose(v) - A)) < error_margin + +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + end From 92616a8c3dc74f11e60e2eca62a4c2080b8fc510 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Thu, 8 Jun 2017 07:31:23 +0200 Subject: [PATCH 2/6] add inv --- src/backend/tensorflow/graph.jl | 3 ++- test/backend/tensorflow.jl | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index c27ffec4..49daf657 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -30,7 +30,8 @@ graph(::typeof(mean), x, dim=nothing) = TensorFlow.reduce_mean(x;axis=dim) graph(::typeof(svd), x) = svd(x) for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos, - sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj) + sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj, + inv) @eval graph(::typeof($op), args...) = $op(args...) end diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index fd5e6a93..6fdef6cd 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -35,6 +35,12 @@ m = tf(f) u,s,v = m(A) @test maximum(abs.(u*diagm(s)*transpose(v) - A)) < error_margin +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +# inv +@net f(x) = inv(x) +m = tf(f) +@test maximum(abs.(m(A)-inv(A))) < error_margin + #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end From 547ca64206aeefa18310882481232fc1ae9ec6fd Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Thu, 8 Jun 2017 08:16:12 +0200 Subject: [PATCH 3/6] add det --- src/backend/tensorflow/graph.jl | 2 +- test/backend/tensorflow.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index 49daf657..63c4f4e2 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -31,7 +31,7 @@ graph(::typeof(svd), x) = svd(x) for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos, sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj, - inv) + inv, det) @eval graph(::typeof($op), args...) = $op(args...) end diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index 6fdef6cd..61f700f6 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -41,6 +41,12 @@ u,s,v = m(A) m = tf(f) @test maximum(abs.(m(A)-inv(A))) < error_margin +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +# det +@net f(x) = det(x) +m = tf(f) +@test maximum(abs.(m(A)-det(A))) < error_margin + #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end From 6a3f02b8e849e0f8313ebf77d474dfff6f62e468 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Thu, 8 Jun 2017 20:59:46 +0200 Subject: [PATCH 4/6] update tests --- test/backend/tensorflow.jl | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index 61f700f6..8a2096c1 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -25,28 +25,26 @@ end @testset "Ops" begin -error_margin = 1e-4 + @testset "svd" begin + A = convert(Array{Float32},randn(5,5)) + @net f(x) = svd(x) + m = tf(f) + u,s,v = m(A) + @test A ≈ u*diagm(s)*transpose(v) + end -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# svd -A = convert(Array{Float32},randn(5,5)) -@net f(x) = svd(x) -m = tf(f) -u,s,v = m(A) -@test maximum(abs.(u*diagm(s)*transpose(v) - A)) < error_margin + @testset "inv" begin + @net f(x) = inv(x) + m = tf(f) + @test m(A) ≈ inv(A) + end -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# inv -@net f(x) = inv(x) -m = tf(f) -@test maximum(abs.(m(A)-inv(A))) < error_margin - -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# det -@net f(x) = det(x) -m = tf(f) -@test maximum(abs.(m(A)-det(A))) < error_margin - -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + @testset "det" begin + @net f(x) = det(x) + m = tf(f) + @test m(A) ≈ det(A) + end + +end end From f399179c022d7873ee1f63cb4a8db9c43317c033 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Fri, 9 Jun 2017 07:05:09 +0200 Subject: [PATCH 5/6] update tests --- test/backend/tensorflow.jl | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index 8a2096c1..4cdb353b 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -24,27 +24,11 @@ test_anon(tf) end @testset "Ops" begin - - @testset "svd" begin - A = convert(Array{Float32},randn(5,5)) - @net f(x) = svd(x) - m = tf(f) - u,s,v = m(A) - @test A ≈ u*diagm(s)*transpose(v) - end - - @testset "inv" begin - @net f(x) = inv(x) - m = tf(f) - @test m(A) ≈ inv(A) - end - - @testset "det" begin - @net f(x) = det(x) - m = tf(f) - @test m(A) ≈ det(A) - end - + A = convert(Array{Float32},randn(5,5)) + u,s,v = tf(@net x -> svd(x))(A) + @test A ≈ u*diagm(s)*transpose(v) + @test tf(@net x -> inv(x))(A) ≈ inv(A) + @test tf(@net x -> det(x))(A) ≈ det(A) end end From 60e3a94952fde5cb76c1ebb979a4df51a1a30ca9 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Fri, 9 Jun 2017 07:23:54 +0200 Subject: [PATCH 6/6] update tests --- test/backend/tensorflow.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index 4cdb353b..178de761 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -24,7 +24,7 @@ test_anon(tf) end @testset "Ops" begin - A = convert(Array{Float32},randn(5,5)) + A = randn(Float32,(5,5)) u,s,v = tf(@net x -> svd(x))(A) @test A ≈ u*diagm(s)*transpose(v) @test tf(@net x -> inv(x))(A) ≈ inv(A)