I guess it is doable, but there is only very limited sample about how to use prelude.foldr()
It’ll be appreciated if there can be some tutorial or introduction about this. Thanks a lot.
def test_myfoldr():
input_tensor = relay.var("input", shape=[1, 2], dtype='float32')
mylist = cons(input_tensor, cons(input_tensor, nil()))
x = relay.var("x", shape=[1, 2], dtype='float32')
y = relay.var("y", shape=[1, 2], dtype='float32')
concat = relay.Function([x, y], relay.op.concatenate([x, y], axis=0))
func = foldr(concat, mylist, nil())
print(func)
res = intrp.evaluate(func, binds={input_tensor: relay.Constant(tvm.ndarray.empty(shape=(1, 2)))})
This is my test code, it gets an error:
v0.0.1
E %13 = fn () {
E %11 = fn () {
E %10 = {
E let %input: Tensor[(1, 2), float32] = meta[relay.Constant][0] //
E %2 = fn (%x: Tensor[(1, 2), float32], %y: Tensor[(1, 2), float32]) {
E %0 = (%x, %y)
E %1 = concatenate(%0) //
E %1
E }
E %3 = nil
E %4 = %3() //
E %5 = cons
E %6 = %5(%input, %4) //
E %7 = %5(%input, %6) // Error unifying `IncompleteTypeNode(0, 0x2376da0)` and `TypeCallNode(GlobalTypeVarNode(list, 5), [IncompleteTypeNode(0, 0x1d277b0)])`: [23:56:49] /LocalRun/xiaoquan.li/tvm/src/relay/pass/type_solver.cc:100: Check failed: resolved.defined(): Unable to unify parent types: TypeCallNode(GlobalTypeVarNode(list, 5), [IncompleteTypeNode(0, 0x1d277b0)]) and TensorType([1, 2], float32)
E ;
E %8 = %3() //
E %9 = @foldr(%2, %7, %8) //
E %9
E }
E %10
E }
E %12 = %11() //
E %12
E }
E %13