You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by sk...@apache.org on 2018/09/03 06:00:14 UTC

[incubator-mxnet] branch master updated: Add trigonometric operators (#12424)

This is an automated email from the ASF dual-hosted git repository.

skm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 307e62a  Add trigonometric operators (#12424)
307e62a is described below

commit 307e62a60099cde9d504f6fa9f6bc406ffbfb2f8
Author: Vandana Kannan <va...@users.noreply.github.com>
AuthorDate: Sun Sep 2 22:59:58 2018 -0700

    Add trigonometric operators (#12424)
---
 .../mxnet/contrib/onnx/mx2onnx/_op_translations.py | 120 +++++++++++++++++++++
 .../python-pytest/onnx/export/onnx_backend_test.py |   6 ++
 2 files changed, 126 insertions(+)

diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
index af7fedb..0960776 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 1fbfde5..19bf699 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 @@ IMPLEMENTED_OPERATORS_TEST = [
     'test_abs',
     'test_sum',
     'test_tanh',
+    'test_cos',
+    'test_sin',
+    'test_tan',
+    'test_acos',
+    'test_asin',
+    'test_atan'
     'test_ceil',
     'test_floor',
     'test_concat',