Tony
May 16, 2019, 7:52am
1
Following is my code:
x =[2, 3, 6] # x is a list
output = tvm.compute((3,),lambda i: x[i]) #convert list x to a tvm.tensor
So I want to convert a list to a tvm.tensor, but it failed with the following error:
TypeError: list indices must be integers, not Var
You might be interested in tvm’s NDArray instead
Tony
May 16, 2019, 10:40am
3
Thanks. But I want to obtain a tvm.Tensor which contains the same value as the list x, while tvm’s NDArray returns a NDArray type.
Tony
May 16, 2019, 11:03am
5
I thought of a solution shown below:
output = tvm.compute((3,), lambda i: 0.5*(i-1)*(2-i)*x[0]+i*(2-i)*x[1]+i*(i-1)*0.5*x[2])
However, it can not be used while len(x) is large.
I don’t know any other way. But the following:
You can define your list x as tvm.placeholder
and create a module. Then, pass in your list x as tvm.ndArray to your module to compute the results.
Another way is, you could try x = tvm.convert(x)
to convert list to tvm class.
You can use tvm.expr.Select
in compute and then unroll all axes during schedule. TVM will simplify select conditions.
See examples here
Corresponding coordinate of the 1D index
"""
indices = []
for i in range(len(shape) - 1, -1, -1):
indices.append(idx % shape[i])
idx = idx // shape[i]
indices = indices[::-1]
return indices
def const_matrix(matrix, name="const_matrix"):
"""convert a const numpy 2-dimensional matrix to tvm tensor
Parameters
----------
matrix: numpy.ndarray
Const input array
name: str, optional
The name of output op
Returns
1 Like
Tony
May 19, 2019, 8:36am
8
Thanks a lot!
Could you please explain more about the function tvm.all()?
does your probelm resolved and how??? thanks!!