From eda5c2c7766fcecf6e1b5f9d65e9a233184e19d6 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Tue, 9 May 2017 01:29:15 +0200 Subject: [PATCH 1/3] add .^ and reduction ops for tf backend --- src/backend/tensorflow/graph.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index 8d8a7f9a..167982a5 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -21,8 +21,16 @@ graph(::typeof(relu), x) = nn.relu(x) graph(::typeof(σ), x) = nn.sigmoid(x) graph(::typeof(hcat), xs...) = concat(1, xs) graph(::typeof(seq), xs, n) = TensorFlow.unpack(xs, num = n, axis = 1) +graph(::typeof(sum), x, dim) = TensorFlow.reduce_sum(x;axis=dim) +graph(::typeof(prod), x, dim) = TensorFlow.reduce_prod(x;axis=dim) +graph(::typeof(min), x, dim) = TensorFlow.reduce_min(x;axis=dim) +graph(::typeof(max), x, dim) = TensorFlow.reduce_max(x;axis=dim) +graph(::typeof(all), x, dim) = TensorFlow.reduce_all(x;axis=dim) +graph(::typeof(any), x, dim) = TensorFlow.reduce_any(x;axis=dim) +graph(::typeof(mean), x, dim) = TensorFlow.reduce_mean(x;axis=dim) -for op in (tanh, *, .*, .+) + +for op in (tanh, *, .*, .+, .^) @eval graph(::typeof($op), args...) = $op(args...) end From d5b073db7494ecc510cce52269dc1eeefd14b30b Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Tue, 9 May 2017 14:39:10 +0200 Subject: [PATCH 2/3] add more basic math ops to tf backend --- src/backend/tensorflow/graph.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index 167982a5..208a1032 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -29,8 +29,8 @@ graph(::typeof(all), x, dim) = TensorFlow.reduce_all(x;axis=dim) graph(::typeof(any), x, dim) = TensorFlow.reduce_any(x;axis=dim) graph(::typeof(mean), x, dim) = TensorFlow.reduce_mean(x;axis=dim) - -for op in (tanh, *, .*, .+, .^) +for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos, + sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj) @eval graph(::typeof($op), args...) = $op(args...) end From 92d39f9ff70b02db8d4b0144b5ed8084559e4bb1 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Tue, 9 May 2017 16:50:32 +0200 Subject: [PATCH 3/3] dim defaults to nothing for reduction ops --- src/backend/tensorflow/graph.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index 208a1032..4afc7c03 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -21,15 +21,15 @@ graph(::typeof(relu), x) = nn.relu(x) graph(::typeof(σ), x) = nn.sigmoid(x) graph(::typeof(hcat), xs...) = concat(1, xs) graph(::typeof(seq), xs, n) = TensorFlow.unpack(xs, num = n, axis = 1) -graph(::typeof(sum), x, dim) = TensorFlow.reduce_sum(x;axis=dim) -graph(::typeof(prod), x, dim) = TensorFlow.reduce_prod(x;axis=dim) -graph(::typeof(min), x, dim) = TensorFlow.reduce_min(x;axis=dim) -graph(::typeof(max), x, dim) = TensorFlow.reduce_max(x;axis=dim) -graph(::typeof(all), x, dim) = TensorFlow.reduce_all(x;axis=dim) -graph(::typeof(any), x, dim) = TensorFlow.reduce_any(x;axis=dim) -graph(::typeof(mean), x, dim) = TensorFlow.reduce_mean(x;axis=dim) +graph(::typeof(sum), x, dim=nothing) = TensorFlow.reduce_sum(x;axis=dim) +graph(::typeof(prod), x, dim=nothing) = TensorFlow.reduce_prod(x;axis=dim) +graph(::typeof(min), x, dim=nothing) = TensorFlow.reduce_min(x;axis=dim) +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) -for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos, +for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos, sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj) @eval graph(::typeof($op), args...) = $op(args...) end