Skip to content

Commit

Permalink
TF frontend: add expm1 op (apache#6783)
Browse files Browse the repository at this point in the history
* TF frontend: add expm1 op

* TF frontend: add description for expm1

* TF frontend: use overload operator - instead of subtract

* TF frontend: Limits the range of input data in the Expm1 test

Co-authored-by: xup <xp224797@alibaba-inc.com>
  • Loading branch information
2 people authored and Trevor Morris committed Dec 4, 2020
1 parent 9f17c31 commit 1903b1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,15 @@ def _impl(inputs, attr, params, mod):
return _impl


def _expm1():
# op description: https://www.tensorflow.org/api_docs/python/tf/math/expm1
def _impl(inputs, attr, params, mod):
exp_out = get_relay_op("exp")(inputs[0])
return exp_out - tvm.relay.const(1.0)

return _impl


def _resize(method):
def _impl(inputs, attr, params, mod):
if attr["_output_shapes"][0] is not None:
Expand Down Expand Up @@ -2297,6 +2306,7 @@ def _impl(inputs, attr, params, mod):
"EuclideanNorm": _euclidean_norm(),
"Exp": AttrCvt("exp"),
"ExpandDims": _expand_dims(),
"Expm1": _expm1(),
"Fill": _fill(),
"Floor": AttrCvt("floor"),
"FloorDiv": _floordiv(),
Expand Down
16 changes: 16 additions & 0 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3504,6 +3504,22 @@ def test_forward_atan2():
compare_tf_with_tvm([np_data_1, np_data_2], ["in_data_1:0", "in_data_2:0"], "atan2:0")


def test_forward_expm1():
"""test operator expm1 """

def _test_forward_expm1(shape):
tf.disable_eager_execution()
np_data = np.random.uniform(1, 10, size=shape).astype(np.float32)
tf.reset_default_graph()
in_data = tf.placeholder(tf.float32, shape, name="in_data")
tf.expm1(in_data, name="expm1")
compare_tf_with_tvm([np_data], ["in_data:0"], "expm1:0")

_test_forward_expm1([1, 100])
_test_forward_expm1([1, 10, 10])
_test_forward_expm1([2, 5, 2, 5])


def test_forward_negative():
"""test tf operator Neg """
np_data = np.random.uniform(-100, 255, size=(224, 224, 3)).astype(np.float32)
Expand Down

0 comments on commit 1903b1d

Please sign in to comment.