I am not sure if it is possible to do so at the first place, but would be great to know if there is a way for it. The language reference (https://ziglang.org/documentation/master/#Vectors) has examples for creating a @Vector with compile-time known length. Are there any docs or blogs that elaborates more on the usage of @Vector? One workaround that I could think of is creating @Vectors of fixed length(s) and rely on metadata for dealing with dynamic length(s), but can immediately sense the challenges that it would introduce.
How to create a `@Vector` with a runtime known length in Zig?
126 Views Asked by quettabit At
1
No. Vector is exactly like array except in that regard. In fact is is almost exactly like array in almost every respect but doesn't have things like a
lenfield so you can't find out the length at runtime.It is supposed to be used for SIMD stuff, but with auto vectorising this isn't even true. Since the length have to be fixed at comptime it doesn't even make is easier - if you have a dynamically sized array you still need to chunk it into the Vector repeatedly.
I tried to use it, but found it a huge pain and stopped and just wrote simd ops over arrays instead. It was almost impossible to write generic code over it too since you couldnt even get static information about it at runtime.
It also makes some questionable decisions such as always opting for the largest simd size the hardware supports even if the bus size isn't large enough or data isn't long enough to warrant it.