Skip to content

fix: coerce numpy scalars in colmap write_next_bytes for NumPy 2.x - #3774

Open
f-dy wants to merge 1 commit into
nerfstudio-project:mainfrom
f-dy:fix-numpy2-struct-packing
Open

fix: coerce numpy scalars in colmap write_next_bytes for NumPy 2.x#3774
f-dy wants to merge 1 commit into
nerfstudio-project:mainfrom
f-dy:fix-numpy2-struct-packing

Conversation

@f-dy

@f-dy f-dy commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Problem

build CI (Core Tests) fails on current dependencies:

tests/process_data/test_process_images.py::test_process_images_skip_colmap
tests/process_data/test_process_images.py::test_process_images_recursively_skip_colmap
...
struct.error: required argument is not a float
  nerfstudio/data/utils/colmap_parsing_utils.py:99 in write_next_bytes

NumPy 2.x no longer implicitly converts a size-1 ndarray (or a NumPy scalar) to a Python scalar inside struct.pack. So writing a COLMAP binary model where a field is a NumPy array (e.g. Point3D.error = np.array([0])) now raises.

Fix

Coerce ndarray/np.generic to a Python scalar via .item() in the single-value branch of write_next_bytes before packing. One-line, no behavior change on Python scalars/lists/tuples.

Testing

Reproduced the failing path against the real module and confirmed write + round-trip read now succeed:

write_points3D_binary OK -> 67 bytes
read back OK, ids: [1] error: 0.0
write_cameras_binary OK -> 112 bytes

NumPy 2.x no longer implicitly converts a size-1 ndarray or a NumPy
scalar to a Python scalar inside struct.pack, so writing COLMAP binary
models (e.g. Point3D.error passed as np.array([0])) raised
'struct.error: required argument is not a float'. Coerce ndarray/generic
to a Python scalar via .item() before packing.

Fixes the failing tests/process_data/test_process_images.py cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant