Cast to "int32", results in wrong output

I am trying to implement one operator, which expects integer input, during testing i observed below behavior.

I modified tutorial/nnvm/get_started.py operation as below:
z = sym.cast(sym.elemwise_add(x, x), dtype=“int32”)

and feeding input as below:
x_np = np.array([[1]]).astype(“float32”)

Post execute output is 3.e-45.

But if i modify operation as below:
z = sym.cast(sym.elemwise_add(x, x), dtype=“float32”)

Now the output is 2.0 which is expected.

My target is “LLVM”.
Anyone else has faced the same issue?
Or is it something i am doing wrong?

Check if you forgot dtype=‘int32’ while allocating ndarray for get_output !

1 Like

yes, as @srkreddy1238 mentioned earlier you missed allocated ndarray for get_output with proper casting type(int32)

instead below
out = m.get_output(0, tvm.nd.empty((1,), dtype="float32"))
you should fetch output for ‘int32’ cast
out = m.get_output(0, tvm.nd.empty((1,), dtype="int32"))
Now the output is [2] as expected