cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

doug65536
Journeyman III

What is the best way to sum the members of a vector

I have a vector in my kernel, and I need to sum up all of its members.

Is there a function or at least best way to sum it up? I am doing the following right now but I wondered if there was a better way that I am not finding in the builtin functions.


float8 t = (float8)0;

// ... code to get a bunch of results into the vector members ...

// Horizontal add

t.s0 += t.s1;

t.s2 += t.s3;

t.s4 += t.s5;

t.s6 += t.s7;

t.s0 += t.s2;

t.s4 += t.s6;

t.s0 += t.s4;



Is there a better way to perform the "horizontal add" part?

Thanks

 

0 Likes
2 Replies
selva_c
Journeyman III

uh...

t.s0123 += t.s4567;

t.s01 += t.s23;

t.s0 += t.s1;

 

probably 🙂

0 Likes

t.lo += t.hi
t.lo.lo += t.hi.hi
t.s0 += t.s1
0 Likes