-
Notifications
You must be signed in to change notification settings - Fork 316
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
Add Half-Precision Type #509
Conversation
related: numba/numba#4402 |
CI failures seem spurious? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch, couple of comments to resolve then this is good to go.
return struct.unpack('e', struct.pack('e', value))[0] | ||
except struct.error: | ||
# 'e' only added in Python 3.6+ | ||
return _as_float(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might this be a source of confusion, a user asks for a half but when formatted it appears to not have been correctly truncated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use numpy to round it (the logic is complicated!), but I don't think llvmlite depends on that at the minute. Is that OK? I'd rather use a library to do the rounding - especially as python 2.x is decreasing in popularity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sklam do you have a view on this. Perhaps just documenting that it's different or issuing a warning is the easiest thing to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not rounded properly, at parse_assembly()
, it will raise RuntimeError
with:
RuntimeError: LLVM IR parsing error
<string>:5:27: error: floating point constant invalid for type
@"myhalf" = constant half 0x3f87006680000000
I think we should just document it. Telling user to consider doing something like float(np.float16(1.12312321e-2))
to make sure the value can be exactly represented as half.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sklam @stuartarchibald I've pushed a change to the documentation that covers this
llvmlite/tests/test_valuerepr.py
Outdated
from . import TestCase | ||
|
||
|
||
int8 = IntType(8) | ||
int16 = IntType(16) | ||
|
||
|
||
PY36 = sys.version_info[:2] >= (3, 6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PY36 = sys.version_info[:2] >= (3, 6) | |
PY36_OR_LATER = sys.version_info[:2] >= (3, 6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed this
Close/Open to restart all of CI easily. Apologies for the noise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes.
In the style of Float and Double