Skip to content

Confusion about TypeMustMatch and f64 #444

Open
@legendre6891

Description

@legendre6891

Hi! I have a question about why the following code seems to work without throwing an assert error.

On the Rust side:

#[pyfunction]
fn sum_up<'py>(py: Python<'py>, array: PyArrayLike1<'py, f64, TypeMustMatch>) -> f64 {
    array.as_array().sum()
}

On the python side

>>> A = np.array([2**63, 2**63+1], dtype=np.uint64)
>>> sum_up(A)
1.8446744073709552e+19

It seems like A is being converted to a f64, and then addition is carried out. (For reference, A.sum() = 1.) I thought that the TypeMustMatch means that the array's dtype must be f64.

Either I'm misunderstanding TypeMustMatch or perhaps there is a bug here?

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