Skip to content

BUG: add a specialized loop for boolean matmul #14464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2019
Merged

Conversation

mattip
Copy link
Member

@mattip mattip commented Sep 9, 2019

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.

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
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
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
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
Copy link
Member

charris commented Sep 9, 2019

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
Copy link
Member

seberg commented Sep 9, 2019

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
Copy link
Member

charris commented Sep 9, 2019

There are compiler warnings...

@mattip
Copy link
Member Author

mattip commented Sep 10, 2019

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
Copy link
Member Author

mattip commented Sep 10, 2019

tests pass

@seberg
Copy link
Member

seberg commented Sep 12, 2019

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