Skip to content

Commit 3f30c4e

Browse files
authored
Adding support for Neg (#119)
* Adding support for Neg * Cleaning up Neg
1 parent 7b3c4f9 commit 3f30c4e

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/load.jl

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ function load_node!(tape::Tape, ::OpConfig{:ONNX, :Equal}, args::VarVec, attrs::
9191
return push_call!(tape, _equal, args...)
9292
end
9393

94+
function load_node!(tape::Tape, ::OpConfig{:ONNX, :Neg}, args::VarVec, attrs::AttrDict)
95+
return push_call!(tape, neg, args[1])
96+
end
97+
9498
function load_node!(tape::Tape, nd::NodeProto, backend::Symbol)
9599
args = [tape.c.name2var[name] for name in nd.input]
96100
attrs = convert(Dict{Symbol, Any}, Dict(nd.attribute))

src/ops.jl

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ end
7878

7979
add(xs...) = .+(xs...)
8080
sub(xs...) = .-(xs...)
81+
neg(x) = .-(x)
8182
_sin(x) = sin.(x)
8283
_cos(x) = cos.(x)
8384
_abs(x) = abs.(x)

src/save.jl

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function save_node!(g::GraphProto, ::OpConfig{:ONNX, typeof(_equal)}, op::Umlaut
166166
push!(g.node, nd)
167167
end
168168

169+
function save_node!(g::GraphProto, ::OpConfig{:ONNX, typeof(neg)}, op::Umlaut.Call)
170+
nd = NodeProto("Neg", op)
171+
push!(g.node, nd)
172+
end
173+
169174
function save_node!(g::GraphProto, ::OpConfig{:ONNX, typeof(*)}, op::Umlaut.Call)
170175
nd = NodeProto(
171176
input=[onnx_name(v) for v in reverse(op.args)],

test/saveload.jl

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ import ONNX: NodeProto, ValueInfoProto, AttributeProto, onnx_name
126126
ort_test(ONNX._equal, A, B)
127127
end
128128

129+
@testset "Neg" begin
130+
A = rand(3, 4)
131+
ort_test(ONNX.neg, A)
132+
end
133+
129134
@testset "Gemm" begin
130135
A, B, C = (rand(3, 4), rand(3, 4), rand(3, 3))
131136
ort_test(ONNX.onnx_gemm, A, B')

0 commit comments

Comments
 (0)