Skip to content

Allowing int and float as types #1107

@certik

Description

@certik

A question came up to support float to mean f64. We can allow it, except that we support f64[5, 6] and f64[:,:] syntax for multidimensional arrays, and that does not work with the intrinsic type (float[:,:] or float[5,6] is an error in CPython).

Three approaches are available:

  • Only support float for scalar types, not arrays (so LPython would give an error message, as would CPython, for float[:,:])
  • Create our own float type in ltypes. For scalar values you can use it interchangeably with the builtin float, but for arrays you have to import it from ltypes, then float[:,:] would work
  • Use built-in float, allow for scalars, not allow float[:,:], but allow a more complicated syntax such a Array[float, 4, 5] and Array[float, :, :]. This might be a good idea, but we need to explore how to properly design this. Then f32[:,:] is just a syntactic sugar for Array[f32, :, :]. This longer syntax will become very verbose once you have a function that accepts 5 array arguments, each with multiple dimensions.

It seems we should encourage using f32 and f64, and then we avoid all these issues. We can allow float for only scalars, and for arrays LPython would say / recommend to use f64.

For more background, see:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions