Skip to content

Commit

Permalink
=Add ability to import names that are already used in Base
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox authored and malmaud committed May 25, 2018
1 parent 56196cf commit 25753b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/generate_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,13 @@ Returns a reference to a Julia function corresponding to the operation.
function import_op(name)
jl_name = opname_to_jlname(name)
mod = TensorFlow.Ops
if !isdefined(mod, jl_name)
if jl_name names(mod, true)
ops = Dict(get_all_op_list())
op = ops[name]
op_desc = to_function(op)
eval(Ops, op_desc.expr)
else
warn("Import Skipped: tried to import op $name as $(mod).$(jl_name), but that already exists.")
end

return getfield(Ops, jl_name)
Expand Down
8 changes: 8 additions & 0 deletions test/ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ using Base.Test
as_string = import_op("AsString")
@test run(session, as_string(2)) == "2"
end



import_op("Atan2") #Must be outside testset as per https://github.com/JuliaLang/julia/issues/27244
@testset "Importing a name that is used by Base" begin
session = Session(Graph())
@test run(session, Ops.atan2(Tensor(1.0), Tensor(1.0))) > 0
end

0 comments on commit 25753b2

Please sign in to comment.