Skip to content

BUG: add a specialized loop for boolean matmul - #14464

Merged
seberg merged 3 commits into
numpy:masterfrom
mattip:matmul-bool
Sep 12, 2019
Merged

seberg merged 3 commits into
numpy:masterfrom
mattip:matmul-bool

Conversation

@mattip

@mattip mattip commented Sep 9, 2019

Copy link
Copy Markdown
Member

Fixes gh-14439

Not sure whether this should be labelled a bug or a regression, since the original matmul was based on dot and so most likely worked properly. If a regression the test should move to the proper place.

Comment thread numpy/core/src/umath/matmul.c.src Resolved
Comment thread numpy/core/tests/test_multiarray.py Outdated
assert np.max(a.view(np.int8)) == 1
b = np.matmul(a, a)
# matmul with boolean output should always be 0, 1
assert np.max(b.view(np.int8)) == 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be nice to have a larger than 2x2 array as well I guess. And while we are at it, ensure:

np.matmul(np.empty((2, 0), dtype=np.bool_), np.empty(0, dtype=np.bool_))

gives [False, False] (that is what dot gives, I assume it is correct, heh).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably view as uint8 here, since currently this test won't detect -1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed uint8, added more tests. np.empty gives uninitialized memory, used np.zeros instead.

@charris

charris commented Sep 9, 2019

Copy link
Copy Markdown
Member

original matmul was based on dot

If cblas couldn't be used, it was done with einsum

In [11]: a                                                                      
Out[11]: 
array([[ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True]])

In [12]: einsum('ij,jk', a, a).view(int8)                                       
Out[12]: 
array([[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]], dtype=int8)

@charris charris added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Sep 9, 2019
@charris charris added this to the 1.16.6 milestone Sep 9, 2019
@seberg seberg added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Sep 9, 2019
@seberg

seberg commented Sep 9, 2019

Copy link
Copy Markdown
Member

Put release note label, but since this is going to be backported and the backports have the shortlist, and it is pretty obvious, maybe that is unnecessary.

@mattip mattip removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Sep 9, 2019
@charris

charris commented Sep 9, 2019

Copy link
Copy Markdown
Member

There are compiler warnings...

@mattip

mattip commented Sep 10, 2019

Copy link
Copy Markdown
Member Author

grr. We should move the compiler-warning-check code from tools/travis-test.sh to runtests.py so failures will show up locally, and so that grep can be tested.

@mattip

mattip commented Sep 10, 2019

Copy link
Copy Markdown
Member Author

tests pass

@seberg

seberg commented Sep 12, 2019

Copy link
Copy Markdown
Member

OK, lets put this in. Thanks Matti!

@seberg
seberg merged commit 0006674 into numpy:master Sep 12, 2019
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 14, 2019
@charris charris removed this from the 1.16.6 milestone Sep 14, 2019
@mattip
mattip deleted the matmul-bool branch June 8, 2020 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

matmul @ of boolean arrays gives inconsistent results

4 participants