#Is there a way to declare multiple variables at comptime besides using an array?

1 messages · Page 1 of 1 (latest)

delicate geyser
#

I have a case where I am implementing some unrolling with comptime and I need a seperate sum item for each element. I have something like this:

        // Initialize sums
        var sums: [N]@Vector(vector_width, f32) = undefined;
        inline for (0..N) |j| {
            sums[j] = @splat(0.0);
        }

        var offset: usize = 0;
        for (0..vec_len) |_| {
            const xvec: @Vector(vector_width, f32) = x[offset..][0..vector_width].*;
            inline for (0..N) |j| {
                const wvec: @Vector(vector_width, f32) = wrows[j][offset..][0..vector_width].*;
                sums[j] += xvec * wvec;
            }
            offset += vector_width;
        }

Is there a way in Zig to have the variables declared but NOT in array? I am not sure this even makes much sense as an idea I am still getting used to meta programming in zig.

shy rampart
#

arrays and slices are the only runtime indexable types

#

You can simplify the initialization: var sums = [1]@Vector(4, f32){@splat(-0.0)} ** N;

#

it would also works as a struct or something