Skip to content

Enforce dtype for empty() #1790

Closed
Closed

Description

@certik

LPython should give an error message:

    x: i32[4, 5, 2] = empty([4, 5, 2])
    y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5])

Since in CPython the arrays would be both float (?) arrays of the default kind. Instead, it needs to enforce something like this:

    from numpy import int32, float64
    x: i32[4, 5, 2] = empty([4, 5, 2], dtype=int32)
    y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5], dtype=float64)

Activity

  1. ubaidsk commented on May 12, 2023

    @ubaidsk
    Collaborator

    I think we can enforce it. In CPython, I think it is optional.

  2. certik commented on May 12, 2023

    @certik
    ContributorAuthor

    What I mean by that is that if dtype is not specified, then it will use the same dtype as CPython (I think it's float64).

    Consequently, this x: i32[4, 5, 2] = empty([4, 5, 2]) must fail, because the RHS is f64 and the LHS is i32.

    The issue is that if we don't do that, then the above code has different types in CPython and LPython, so LPython behaves differently, which is breaching our contract that if LPython compiles the code (and runs), then CPython will behave 100% the same.

  3. certik commented on Aug 2, 2023

    @certik
    ContributorAuthor

    I am assigning this to @czgdp1807, since he implemented #2118 for i8, so it just needs to be extended for all dtypes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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