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

ruihangl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new d013dad06d [TOPI] Support integer type input for log and log2 (#18426)
d013dad06d is described below

commit d013dad06d38cf0e011ac065815db2609d2c3efe
Author: Qingchao Shen <[email protected]>
AuthorDate: Thu Nov 13 00:11:03 2025 +0800

    [TOPI] Support integer type input for log and log2 (#18426)
    
    Adds support for integer inputs in `topi.log` and `topi.log2` by
    automatically converting them to float32, aligning with NumPy's
    implicit float promotion behavior.
---
 python/tvm/topi/math.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/python/tvm/topi/math.py b/python/tvm/topi/math.py
index fb306f9e59..61b39aad91 100644
--- a/python/tvm/topi/math.py
+++ b/python/tvm/topi/math.py
@@ -450,7 +450,6 @@ def round(x):
     return te.compute(x.shape, lambda *i: te.round(x(*i)))
 
 
[email protected]_scope(tag=tag.ELEMWISE)
 def log(x):
     """Take logarithm of input x.
 
@@ -464,10 +463,11 @@ def log(x):
     y : tvm.te.Tensor
         The result.
     """
-    return te.compute(x.shape, lambda *i: te.log(x(*i)))
+    if x.dtype.startswith("int"):
+        x = te.compute(x.shape, lambda *i: x(*i).astype("float32"))
+    return te.compute(x.shape, lambda *i: te.log(x(*i)), tag=tag.ELEMWISE)
 
 
[email protected]_scope(tag=tag.ELEMWISE)
 def log2(x):
     """Take logarithm to the base 2 of input x.
 
@@ -481,7 +481,9 @@ def log2(x):
     y : tvm.te.Tensor
         The result.
     """
-    return te.compute(x.shape, lambda *i: te.log2(x(*i)))
+    if x.dtype.startswith("int"):
+        x = te.compute(x.shape, lambda *i: x(*i).astype("float32"))
+    return te.compute(x.shape, lambda *i: te.log2(x(*i)), tag=tag.ELEMWISE)
 
 
 def log10(x):

Reply via email to