#Copy vector into array

1 messages · Page 1 of 1 (latest)

grave vault
#

What's the "right" way to copy a vector into an array of its type? The length of the slice and vector are comptime known. Is there a one-liner that will do that assignment, or am I just as well off using a for loop?

I see there's a way to copy the vector out from the array. Found that here: #1160600566548926615 message

But I see no discussion of the reverse, placing the processed result array back from whence it came or into a different "result" array.

I guess that a @memcpy might accomplish it but is that heavy-handed and/or stupid?

ionic plover
#
var src: @Vector(4, 32) = ...;
var dst: [4]u32 = src;
grave vault
#

Thanks for the reply. I should have been more explicit, I'm trying to get the data to land at an offset from zero... So,

const vec: @Vector(4, f32) = my_array[i..][0..4];

Then I want to get processed data to land back at the same location either in my_array or at the same index in a result array.

ionic plover
#

my_array[i..][0..4].* = vec;

#

slicing the array turns it into a slice (pointer) so you need a deref to get back to an array