Hey everyone!
I’m running into an issue with VariadicList initialization in Mojo #3987
Here’s a minimal example of what I’m trying:
fn main():
alias shape_type = __mlir_type[`!kgen.variadic<`, Int, `>`]
# Case 1: Direct initialization (works)
var shape1 = __mlir_op.`pop.variadic.create`[_type = shape_type](Int(0), Int(0))
# Case 2: Expected to prepopulate with 5 elements (doesn’t work)
alias rank = 5
var shape2 = __mlir_op.`pop.variadic.create`[_type = shape_type, size = rank](Int(0))
# Case 3: Trying to append elements (no such op?)
var shape3 = __mlir_op.`pop.variadic.create`[_type = shape_type]()
for _ in range(rank):
shape3 = __mlir_op.`pop.variadic.append`(shape3, Int(0)) # Doesn't seem to exist
print(VariadicList(shape1).__len__()) # Output: 2
print(VariadicList(shape2).__len__()) # Output: 0 (Expected: 5)
print(VariadicList(shape3).__len__()) # Output: 0 (Expected: 5)
Is there a way to repeat elements when using pop.variadic.create for a VariadicList?
For example, instead of manually passing multiple values like this:
var shape = __mlir_op.`pop.variadic.create`[_type = shape_type](Int(0), Int(0), Int(0), Int(0), Int(0))
Is there a way to dynamically repeat an element n times inside create itself, without manually listing them?