-
Notifications
You must be signed in to change notification settings - Fork 48
Native unboxed floats #966
Copy link
Copy link
Closed
python/mypy
#14880Labels
area-native-typesUnboxed types.Unboxed types.featureSupporting previously unsupported Python, new native types, new features, etc.Supporting previously unsupported Python, new native types, new features, etc.speed
Metadata
Metadata
Assignees
Labels
area-native-typesUnboxed types.Unboxed types.featureSupporting previously unsupported Python, new native types, new features, etc.Supporting previously unsupported Python, new native types, new features, etc.speed
Mypyc currently uses heap allocated (boxed) CPython objects to represent
floatvalues. This is both slow and can waste memory, especially once we support packed arrays (#840). Instead, representfloatvalues as C double values, similar to how we are going to support native integers (#837).Native floats will use an overlapping error value, similar to native integers. We could potentially also reserve a specific NaN value to be used as an error value, but overlapping error values seem cleaner and they might even be more efficient, at least on some architectures.
We'll also need some primitives for
mathfunctions such asmath.sqrtto avoid unnecessary boxing/unboxing and slow CPython calls. We don't need to cover allmathfunctions -- just the most common/fundamental ones are sufficient.Open issues:
numpy.float64?mathto support using primitives?**operator which can produceAnytypes? The simplest thing is to just go with the types mypy can infer, and sometimes the result will be boxed.The open issues don't need to be resolved to land an initial implementation.