sandeep-krishnamurthy closed pull request #12424: [MXNET-878] Add
trigonometric operators to onnx
URL: https://github.com/apache/incubator-mxnet/pull/12424
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
index af7fedb33cb..0960776251c 100644
--- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
+++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
@@ -308,6 +308,126 @@ def convert_tanh(node, **kwargs):
)
return [node]
+@mx_op.register("cos")
+def convert_cos(node, **kwargs):
+ """Map MXNet's cos operator attributes to onnx's Cos operator
+ and return the created node.
+ """
+ helper, _, _ = import_onnx_modules()
+ name = node["name"]
+ inputs = node["inputs"]
+ input_node_idx = kwargs["index_lookup"][inputs[0][0]]
+ proc_nodes = kwargs["proc_nodes"]
+ input_node = proc_nodes[input_node_idx].name
+
+ node = helper.make_node(
+ 'Cos',
+ [input_node],
+ [name],
+ name=name
+ )
+ return [node]
+
+@mx_op.register("sin")
+def convert_sin(node, **kwargs):
+ """Map MXNet's sin operator attributes to onnx's Sin operator
+ and return the created node.
+ """
+ helper, _, _ = import_onnx_modules()
+ name = node["name"]
+ inputs = node["inputs"]
+ input_node_idx = kwargs["index_lookup"][inputs[0][0]]
+ proc_nodes = kwargs["proc_nodes"]
+ input_node = proc_nodes[input_node_idx].name
+
+ node = helper.make_node(
+ 'Sin',
+ [input_node],
+ [name],
+ name=name
+ )
+ return [node]
+
+@mx_op.register("tan")
+def convert_tan(node, **kwargs):
+ """Map MXNet's tan operator attributes to onnx's tan operator
+ and return the created node.
+ """
+ helper, _, _ = import_onnx_modules()
+ name = node["name"]
+ inputs = node["inputs"]
+ input_node_idx = kwargs["index_lookup"][inputs[0][0]]
+ proc_nodes = kwargs["proc_nodes"]
+ input_node = proc_nodes[input_node_idx].name
+
+ node = helper.make_node(
+ 'Tan',
+ [input_node],
+ [name],
+ name=name
+ )
+ return [node]
+
+@mx_op.register("arccos")
+def convert_acos(node, **kwargs):
+ """Map MXNet's acos operator attributes to onnx's acos operator
+ and return the created node.
+ """
+ helper, _, _ = import_onnx_modules()
+ name = node["name"]
+ inputs = node["inputs"]
+ input_node_idx = kwargs["index_lookup"][inputs[0][0]]
+ proc_nodes = kwargs["proc_nodes"]
+ input_node = proc_nodes[input_node_idx].name
+
+ node = helper.make_node(
+ 'Acos',
+ [input_node],
+ [name],
+ name=name
+ )
+ return [node]
+
+@mx_op.register("arcsin")
+def convert_asin(node, **kwargs):
+ """Map MXNet's asin operator attributes to onnx's asin operator
+ and return the created node.
+ """
+ helper, _, _ = import_onnx_modules()
+ name = node["name"]
+ inputs = node["inputs"]
+ input_node_idx = kwargs["index_lookup"][inputs[0][0]]
+ proc_nodes = kwargs["proc_nodes"]
+ input_node = proc_nodes[input_node_idx].name
+
+ node = helper.make_node(
+ 'Asin',
+ [input_node],
+ [name],
+ name=name
+ )
+ return [node]
+
+@mx_op.register("arctan")
+def convert_atan(node, **kwargs):
+ """Map MXNet's atan operator attributes to onnx's atan operator
+ and return the created node.
+ """
+ helper, _, _ = import_onnx_modules()
+ name = node["name"]
+ inputs = node["inputs"]
+ input_node_idx = kwargs["index_lookup"][inputs[0][0]]
+ proc_nodes = kwargs["proc_nodes"]
+ input_node = proc_nodes[input_node_idx].name
+
+ node = helper.make_node(
+ 'Atan',
+ [input_node],
+ [name],
+ name=name
+ )
+ return [node]
+
#Basic neural network functions
@mx_op.register("sigmoid")
def convert_sigmoid(node, **kwargs):
diff --git a/tests/python-pytest/onnx/export/onnx_backend_test.py
b/tests/python-pytest/onnx/export/onnx_backend_test.py
index 1fbfde5977e..19bf6993e7c 100644
--- a/tests/python-pytest/onnx/export/onnx_backend_test.py
+++ b/tests/python-pytest/onnx/export/onnx_backend_test.py
@@ -45,6 +45,12 @@
'test_abs',
'test_sum',
'test_tanh',
+ 'test_cos',
+ 'test_sin',
+ 'test_tan',
+ 'test_acos',
+ 'test_asin',
+ 'test_atan'
'test_ceil',
'test_floor',
'test_concat',
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services