I want to compute the kronecker delta (i = j returns 1, otherwise 0) for each element of a stream of type uint4. If I recall correctly, conditionals operate only on the first element of a vector type, so anything based on a conditional is out. I tried abs(sign(i - j)) but abs() will not accept a uint4, presumably because it has a conditional buried in it. The best I've come up with is:

kernel uint4 kronecker_delta(uint4 i<>, uint j<>

{

int4 k_d = sign((int4) i - (int4)j);

return (uint4)(k_d * k_d);

}

My Brook+ experience is near zero, so I wonder if I'm missing some much easier/faster way to do this.

just make it in 4 separate if

afaik that's the only way

btw, in brook+ you need to specifiy output variable explicitly

and there is no return, all basic kernel in brook+ is void

kernel void kronecker_delta(unit i<>, unit j<>, out unit4 k<>

you do the rest