Skip to content
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

Type promotion regression #73

Closed
wants to merge 5 commits into from

Conversation

mwiebe
Copy link
Member

@mwiebe mwiebe commented Apr 13, 2011

This is my fix for ticket #1798.

@mwiebe
Copy link
Member Author

mwiebe commented Apr 14, 2011

Hmmm, there's still a bad corner case as follows:

>>> import numpy as np
>>> a = np.arange(6, dtype='f4')
>>> t = a % 2 == 1
>>> t
array([False,  True, False,  True, False,  True], dtype=bool)
>>> t*a
array([ 0.,  1.,  0.,  3.,  0.,  5.], dtype=float32)
>>> (1-t)*a
array([ 0.,  0.,  2.,  0.,  4.,  0.])

Since 64-bit Linux has the integer as 64-bits, and t is a boolean kind, (1-t) becomes a 64-bit integer array. Since it's an array, now it doesn't trigger scalar_array rules, so (1-t)_a becomes float64 instead of float32.

I think the categories for this should be reduced further from the three I did into just two: boolean/uint/int and float/complex, to fix this.

@charris
Copy link
Member

charris commented Apr 19, 2011

Integer is still 32 bits on 64 bit Linux, it's the long that is 64. That doesn't affect the problem though ;) Numpy 1.5.x also behaves this way, so it is backward compatible. Something like (1 - t) should really be done as ~t to preserve the boolean type.

@mwiebe
Copy link
Member Author

mwiebe commented Apr 22, 2011

I didn't do a change for the (1-t)*a corner case, since getting it to behave right in general requires some additional trickiness. I did put in a commented-out test for it, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants