From a7680b09bc4373e7cdb09932b69dc81e1ba26b4c Mon Sep 17 00:00:00 2001 From: Olivier Thill Date: Sun, 11 Nov 2018 13:44:26 +0000 Subject: [PATCH 1/5] Make unary "-" work with @tf --- src/ops/math.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ops/math.jl b/src/ops/math.jl index a626df19..e5a5b9ea 100644 --- a/src/ops/math.jl +++ b/src/ops/math.jl @@ -167,7 +167,7 @@ function Base.round(::Type{T}, value::AbstractTensor) where T end --(n::AbstractTensor) = negative(n) +-(n::AbstractTensor; kwargs...) = negative(n; kwargs...) @op function Base.complex(x_r::AbstractTensor, x_i::AbstractTensor; kwargs...) Ops.complex(x_r, x_i; kwargs...) From 05922ad4daed7d962e186e1adbd72e3cc7f1fbd4 Mon Sep 17 00:00:00 2001 From: Olivier Thill Date: Sun, 11 Nov 2018 15:04:24 +0000 Subject: [PATCH 2/5] To much syntactic sugar it seems. --- src/ops/math.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ops/math.jl b/src/ops/math.jl index e5a5b9ea..2af051d9 100644 --- a/src/ops/math.jl +++ b/src/ops/math.jl @@ -167,7 +167,9 @@ function Base.round(::Type{T}, value::AbstractTensor) where T end --(n::AbstractTensor; kwargs...) = negative(n; kwargs...) +function -(n::AbstractTensor; kwargs...) + negative(n; kwargs...) +end @op function Base.complex(x_r::AbstractTensor, x_i::AbstractTensor; kwargs...) Ops.complex(x_r, x_i; kwargs...) From e19434840c66d141f5e15640b2cbb25ad6c759f0 Mon Sep 17 00:00:00 2001 From: Olivier Thill Date: Sun, 11 Nov 2018 20:49:11 +0000 Subject: [PATCH 3/5] add test for unary - --- test/meta.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/meta.jl b/test/meta.jl index ac90d87c..f7e7e746 100644 --- a/test/meta.jl +++ b/test/meta.jl @@ -60,7 +60,11 @@ end end end - +@testset "Negating and @tf" begin + a = tf.constant(1) + @tf b = -a + @test true # Above line would have errored if unary - didn't work with @tf +end @testset "Naming Big Demo" begin let From f1ec34f7973537b84d10f4a823c6a50c5a355c51 Mon Sep 17 00:00:00 2001 From: Olivier Thill Date: Sun, 11 Nov 2018 21:03:16 +0000 Subject: [PATCH 4/5] prefix the function with @op --- src/ops/math.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ops/math.jl b/src/ops/math.jl index 2af051d9..a7a52e72 100644 --- a/src/ops/math.jl +++ b/src/ops/math.jl @@ -167,7 +167,7 @@ function Base.round(::Type{T}, value::AbstractTensor) where T end -function -(n::AbstractTensor; kwargs...) +@op function -(n::AbstractTensor; kwargs...) negative(n; kwargs...) end From f044718b102e0219fa87e15635ae93ebe9cbded2 Mon Sep 17 00:00:00 2001 From: Olivier Thill Date: Sun, 11 Nov 2018 21:15:38 +0000 Subject: [PATCH 5/5] fix typo in test --- test/meta.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/meta.jl b/test/meta.jl index f7e7e746..4ef1adb1 100644 --- a/test/meta.jl +++ b/test/meta.jl @@ -61,7 +61,7 @@ end end @testset "Negating and @tf" begin - a = tf.constant(1) + a = constant(1) @tf b = -a @test true # Above line would have errored if unary - didn't work with @tf end