-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Overload pybind11 type_caster from int to C++ uint types to support -1 for pycolmap id types #3071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This update only supports -1 and positive values and add explicit logs. Example: |
|
The stub seems to break after this update since it cannot parse uint32_t and uint64_t: https://github.com/colmap/colmap/actions/runs/12454820180/job/34766524324?pr=3071. No idea on this since I never used this stub feature. Help needed : ) |
ahojnnes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks very much.
| return false; \ | ||
| } \ | ||
| int64_t val = py::cast<int64_t>(src); \ | ||
| if (val == -1) { \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach accepts -1 as valid input for any function that expects uint*_t, while this is valid only for ID setters. Instead, how about wrapping Set{Image,Camera,...}Id with a templated function that accepts an int and casts appropriately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of pycolmap ids actually happen in a lot of places in the bindings (not only for the setters). For example, one can do grep -r '_id' ./src/pycolmap/ and find a lot of relevant bindings. And the logic is also not consistent (e.g., here there is explicit casting supported for only one method: https://github.com/colmap/colmap/blob/main/src/pycolmap/sfm/incremental_mapper.cc#L358).
Actually I have a different proposal: how about we not supporting -1 as input and always recommend users to use ctypes to convert from the Python side themselves, as the solution I suggested in the issue:
import pycolmap
import ctypes
p = pycolmap.Point2D()
p.point3D_id = ctypes.c_uint64(-1).value
|
The fix in this PR actually limits the range of uint64_t from 2^64 - 1 to 2^63 - 1 due to the int64_t in the middle. This will also be the case for explicit casting with int as input. So I suggest we not go ahead with the update and stick with |
|
How about an explicit INVALID_POINT3D_ID Python/C++ type? |
|
Using ctypes requires knowing the C++ type of the attribute (utin32 vs uint64), which is not reflected in the Python doc (int only) and cannot be asked users to know. Binding the invalid values seems like a better option, since we can then provide a nicer representation (e.g. colmap/src/colmap/util/types.h Lines 98 to 103 in cd97b65
colmap/src/pycolmap/scene/image.cc Lines 46 to 51 in cd97b65
|
) Fixes: colmap#3070 Per discussion from colmap#3071
No description provided.