weld icon indicating copy to clipboard operation
weld copied to clipboard

Bitwise operation unexpected output

Open radujica opened this issue 7 years ago • 2 comments

Evaluating this, where the inputs are np.arrays of dtype np.bool and return type WeldBIt:

result(
    for(zip(_inp0, _inp1), 
        appender, 
        |b, i, n| 
            merge(b, n.$0 & n.$1)
    )
) {'_inp1': array([ True, False,  True, False]), '_inp0': array([ True,  True, False, False])} []

Returns a np.array of dtype np.bool [False, False, False, False]. I was, of course, expecting [True, False, False, False]. Using && works fine though.

Interestingly, passing arrays of dtype np.int64 returns the correct result (see below), even if the return type is WeldLong (returning [1, 0, 0, 0]) or WeldBit (returning [True, False, False, False]).

result(
    for(zip(_inp0, _inp1), 
        appender, 
        |b, i, n| 
            merge(b, n.$0 & n.$1)
    )
) {'_inp1': array([1, 0, 1, 0]), '_inp0': array([1, 1, 0, 0])} []

Is this expected behavior?

radujica avatar Apr 23 '18 13:04 radujica

Hmm, this is a known issue I believe, and if I remember correctly we had traced to a bug in LLVM unfortunately — when LLVM puts vectorized code that has Booleans in a struct, it produces some incorrect behavior. If you want to confirm that this is the issue, you can try setting the weld.optimization.passes flag to not include the vectorize transform and see if it gives you the correct answer.

On Mon, Apr 23, 2018 at 6:36 AM Radu [email protected] wrote:

Evaluating this, where the inputs are np.arrays of dtype np.bool and return type WeldBIt:

result( for(zip(_inp0, _inp1), appender, |b, i, n| merge(b, n.$0 & n.$1) ) ) {'_inp1': array([ True, False, True, False]), '_inp0': array([ True, True, False, False])} []

Returns a np.array of dtype np.bool [False, False, False, False]. I was, of course, expecting [True, False, False, False]. Using && works fine though.

Interestingly, passing arrays of dtype np.int64 returns the correct result (see below), even if the return type is WeldLong (returning [1, 0, 0, 0]) or WeldBit (returning [True, False, False, False]).

result( for(zip(_inp0, _inp1), appender, |b, i, n| merge(b, n.$0 & n.$1) ) ) {'_inp1': array([1, 0, 1, 0]), '_inp0': array([1, 1, 0, 0])} []

Is this expected behavior?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/weld-project/weld/issues/346, or mute the thread https://github.com/notifications/unsubscribe-auth/ABTCY1uU2qWsu14j_pMmOTPbYrTq02xGks5trdjWgaJpZM4Tf6KU .

-- Shoumik

sppalkia avatar Apr 23 '18 15:04 sppalkia

Disabling vectorize indeed gives the correct result! Nevertheless, more robust to just use &&.

This could be closed.

radujica avatar Apr 26 '18 08:04 radujica