Skip to content

Wrong dtype when initializing Tensor with NumPy-compatible object #101

Closed
@AyoubMDL

Description

@AyoubMDL

Hi, when initializing a Tensor using a numpy compatible scalar with an explicit dtype, the resulting numpy() call returns the wrong data type:

import numpy as np
from onnx_ir import DataType, Tensor

tensor = Tensor(value=np.float32(0.5), dtype=DataType.FLOAT)
print(tensor.numpy().dtype) # outputs float64 instead of float32

Potential fix

Maybe pass the dtype of _raw here

return self.__array__()
?
return self.__array__(self._raw.dtype)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions