How to convert tvm.relay.expr.Constant to int?

Hi all, I want to convert tvm.relay.expr.Constant() to int. which API is adapted to it. Thanks!

Would just accessing the data work? const.data returns a tvm.nd.array, does that work? Then if you know the constant is just a scalar integer, you can verify that by checking const.data.shape and get its numpy value as const.data.numpy().

Also if you need just a plain integer (assuming const.data.shape == () is True), you can just access the value as const.data.numpy()[()].

1 Like

Thanks for you kindly reply! with your help, problem soved.

1 Like