Skip to content

[REQ] Warn When Constructing Array With Explicit Dtype Is Incompatible With Source Array #670

@christophercrouzet

Description

@christophercrouzet

Description

It's currently possible to reinterpret an array passed to wp.array() as a different dtype, for example to cast triples of float32 values to a wp.vec3 type:

arr = np.array((1.1, 2.2, 3.3), dtype=np.float32)
src = cp.asarray(arr)
dst = wp.array(src, dtype=wp.vec3)
print(dst.numpy())
# [[1.1 2.2 3.3]]

However, explicitly setting an errorneous dtype can sometimes cause an undesired casting, which could then lead to bugs, e.g.:

arr = np.array((1.1, 2.2, 3.3), dtype=np.float32)
src = cp.asarray(arr)
dst = wp.array(src, dtype=wp.int32)
print(dst.numpy())
# [1066192077 1074580685 1079194419]

Here there is likely an indesired casting from float32 to int32 which should be logged as a warning.

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions