8000 Native unboxed floats · Issue #966 · mypyc/mypyc · GitHub
[go: up one dir, main page]

Skip to content
Native unboxed floats #966
@JukkaL

Description

@JukkaL

Mypyc currently uses heap allocated (boxed) CPython objects to represent float values. This is both slow and can waste memory, especially once we support packed arrays (#840). Instead, represent float values 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 math functions such as math.sqrt to avoid unnecessary boxing/unboxing and slow CPython calls. We don't need to cover all math functions -- just the most common/fundamental ones are sufficient.

Open issues:

  • How should we handle interactions with NumPy floating point types such as numpy.float64?
  • Which are the most important functions in math to support using primitives?
  • What to do with the ** operator which can produce Any types? 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.

Metadata

Metadata

Assignees

Labels

area-native-typesUnboxed types.featureSupporting previously unsupported Python, new native types, new features, etc.speed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0