How to cast SIMD when the size is known at compile time

In the following minimal code snippet v cannot be assigned to v2. The error message is: cannot implicitly convert 'SIMD[si32, size]' value to 'SIMD[si32, 32]' in 'let' initializer. But size is known to be equal to 32. Question: how to convince the compiler that I'm a good citizen: trust me, this is ok, everyting will be fine...
fn x(v: SIMD[DType.int32, 32]):
pass

fn howto[size: Int](v: SIMD[DType.int32, size]) -> SIMD[DType.int32, size]:
@parameter
if size == 32:
let v2: SIMD[DType.int32, 32] = v # compile error here
x(v2)
fn x(v: SIMD[DType.int32, 32]):
pass

fn howto[size: Int](v: SIMD[DType.int32, size]) -> SIMD[DType.int32, size]:
@parameter
if size == 32:
let v2: SIMD[DType.int32, 32] = v # compile error here
x(v2)
2 Replies
Michael K
Michael K9mo ago
See rebind and specific example here.
Modular Docs - Mojo🔥 roadmap & sharp edges
A summary of our Mojo plans, including upcoming features and things we need to fix.
Henk-Jan Lebbink
@Michael K Thanx again, you saved my day!
Want results from more Discord servers?
Add your server