Setting the dtype attribute is deprecated because mutating an array is unsafe if an array is shared, especially by multiple threads. As an alternative, you can create a view with a new dtype via array.view(dtype=new_dtype).
(gh-29244)
PointCloud.encode_rgb does this:
|
rgb_u32.dtype = np.float32 # type: ignore |
As does PointCloud.decode_rgb
|
rgb.dtype = np.uint32 # type: ignore |
This raises:
@staticmethod
def encode_rgb(rgb: npt.NDArray | list[npt.NDArray]) -> npt.NDArray:
"""
Encode Nx3 uint8 array with RGB values to
Nx1 float32 array with bit-packed RGB
"""
if isinstance(rgb, np.ndarray):
if rgb.ndim == 1:
rgb = rgb[:, None]
else:
rgb = np.hstack([v[:, None] if v.ndim == 1 else v for v in rgb])
rgb_u32 = rgb.astype(np.uint32)
rgb_u32 = np.array(
(rgb_u32[:, 0] << 16) | (rgb_u32[:, 1] << 8) | (rgb_u32[:, 2] << 0),
dtype=np.uint32,
)
> rgb_u32.dtype = np.float32 # type: ignore
^^^^^^^^^^^^^
E DeprecationWarning: Setting the dtype on a NumPy array has been deprecated in NumPy 2.5.
E Instead of changing the dtype on an array x, create a new array with x.view(new_dtype)
PointCloud.encode_rgbdoes this:pypcd4/src/pypcd4/pypcd4.py
Line 717 in c663042
As does
PointCloud.decode_rgbpypcd4/src/pypcd4/pypcd4.py
Line 729 in c663042
This raises: