Solved by Hamster in post #5 
              
              
                Hello, 
You’re indeed right that 2 multiplies + 1 add (+1 sub for 1-m) + the intermediary memory allocations are completely unnecessary (and also look horrible) when one could just do a CUDA kernel where the thread just looks at the boolean in m[thread_idx] and chooses either A[thread_idx] or B[thre…