Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/tvm/topi/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ def fast_exp(x):
y : tvm.te.Tensor
The result.
"""
if x.dtype.startswith('int') or x.dtype.startswith('uint'):
x = cast(x, 'float32')
return cpp.fast_exp(x, x.dtype, tag.ELEMWISE)


Expand All @@ -799,6 +801,8 @@ def fast_tanh(x):
y : tvm.te.Tensor
The result.
"""
if x.dtype.startswith('int') or x.dtype.startswith('uint'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This condition can be made more concise. The startswith method can accept a tuple of strings to check for multiple prefixes.

Suggested change
if x.dtype.startswith('int') or x.dtype.startswith('uint'):
if x.dtype.startswith(('int', 'uint')):

x = cast(x, 'float32')
return cpp.fast_tanh(x, x.dtype, tag.ELEMWISE)


Expand Down
Loading