#absInt over vector?
1 messages · Page 1 of 1 (latest)
zig and functional programming styles are kind of orthogonal
zig is pretty solidly imperative
well, there's a @reduce 🙂
that applies to vectors, which map quite directly to hardware
and unlike arrays, vectors only hold stuff like integers, pointers, floats - not composite types
I'll be more specific - it'd be nice to have a vectorized std.math.absInt, but there's no such thing. So I'm wondering what the nicest way to deal with this is.
there's a vectorized std.math.sign, for example.
well, there is @fabs, but that only applies to vectors of floats
indeed
at any rate, there's maybe a way to do it with @select
You would select
sign() does some select() stuff, so you could go off that
I like to model my vector stuff into data transformations and reducing the movements
ty
you'd probably have something like
fn absVector(x: anytype) {
const Child = @typeInfo(@TypeOf(x)).Vector.child;
const pred = x > @splat(x.len, @as(Child, 0));
const y = -x;
return @select(Child, pred, x, y);
}
std.math.absInt could probably be doing this
yeah, that's approximately what I'm doing now. I guess maybe absInt isn't doing this because of fear of overflow.
I suppose you'd just check all the elements first.
well, Idk about fear
sure, s/fear/possibility/ 🙂
ye
absInt over vector?