import tvm
from tvm import relay
from tvm.contrib import graph_executor
import numpy as np
x=relay.var("x",shape=[2,2],dtype="int32")
t1=relay.cast(x,"bool")
y=relay.sum(t1)
f = relay.Function([x],relay.Tuple([t1,y]))
mod = tvm.IRModule({"main":f})
target = "llvm"
with tvm.transform.PassContext(opt_level=3 ):
lib = relay.build(mod, target=target)
m = graph_executor.GraphModule(lib['default'](tvm.cpu()))
x = np.ones((2,2)).astype("int32")
m.set_input("x",x)
print(m.get_output(0))
print(m.get_output(1))
The code snippets above should be equivalent to below:
x = np.ones((2,2)).astype("int32").astype(bool)
print(x)
print(np.sum(x,dtype=bool))
Expected behavior
The relay program should always produce t1 all true and y true just like the numpy-based code outputs below. In common sense, it is expected to view non-zero elements as True and sum should perform reduction by OR operation for bool data type.
[[ True True]
[ True True]]
True
Actual behavior
However, the relay-based code produce rather random results.
[[ True False]
[False False]]
True
Or
[[False False]
[False False]]
False
Even
[[False False]
[False False]]
True
Environment
commit id: 1258863
OS: ubuntu 20.04 or macos
LLVM 14
Steps to reproduce
Run the code snippets above.
The code snippets above should be equivalent to below:
Expected behavior
The relay program should always produce t1 all true and y true just like the numpy-based code outputs below. In common sense, it is expected to view non-zero elements as True and sum should perform reduction by OR operation for bool data type.
Actual behavior
However, the relay-based code produce rather random results.
Or
Even
Environment
commit id: 1258863
OS: ubuntu 20.04 or macos
LLVM 14
Steps to reproduce
Run the code snippets above.