From edbf698ed940ecce9d6d224e20fde3fb5e937f64 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Fri, 9 Jun 2017 23:45:16 +0200 Subject: [PATCH] add cast --- src/backend/tensorflow/graph.jl | 1 + src/ops.jl | 3 ++- test/backend/tensorflow.jl | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/tensorflow/graph.jl b/src/backend/tensorflow/graph.jl index 562252d9..2b8f24bd 100644 --- a/src/backend/tensorflow/graph.jl +++ b/src/backend/tensorflow/graph.jl @@ -34,6 +34,7 @@ graph(::typeof(chol), args...) = TensorFlow.transpose(TensorFlow.cholesky(args.. graph(::typeof(reshape), x, dims) = TensorFlow.reshape(x,convert(Tensor{Int32},dims)) graph(::typeof(Flux.tile), args...) = TensorFlow.tile(args...) graph(::typeof(fill), x, dims) = Ops.fill(convert(Tensor{Int32}, dims), Tensor(x)) +graph(::typeof(Flux.cast), args...) = TensorFlow.cast(args...) 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/src/ops.jl b/src/ops.jl index b76ef203..a4c6c4e7 100644 --- a/src/ops.jl +++ b/src/ops.jl @@ -1,7 +1,8 @@ -export reshape, tile, fill +export reshape, tile, fill, cast import Base: reshape, fill reshape(x::AbstractArray, dims::AbstractArray) = reshape(x,tuple(dims...)) tile(x::AbstractArray, mult::AbstractArray) = repeat(x,outer=tuple(mult...)) fill{T}(x::T, dims::AbstractArray) = fill(x,tuple(dims...)) +cast{T}(x::AbstractArray, ::Type{T}) = convert(Array{T},x) diff --git a/test/backend/tensorflow.jl b/test/backend/tensorflow.jl index 531bf38b..7d09eccd 100644 --- a/test/backend/tensorflow.jl +++ b/test/backend/tensorflow.jl @@ -52,6 +52,7 @@ end A = randn(Float32,(4,3,1)) @test tf(@net (x,y) -> Flux.tile(x,y))(A,[1,1,3]) ≈ repeat(A,outer=(1,1,3)) @test tf(@net (x,y) -> fill(x,y))(3.2,[3,2]) ≈ convert(Array{Float32},3.2*ones(3,2)) + @test typeof(tf(@net x -> Flux.cast(x,Int32))(A)) == Array{Int32,3} end end