If a GenericMap is given a value created using one of Numpy's fixed-size numeric types (e.g., int32, int64, float32, float64), pybind11 will insert these using the first integer or floating-point wrapper it has. This is not a problem if the value is read in using Python, but it causes values to have unexpected types in C++.
I've spent a day investigating this, and have learned the following:
- In C++, GenericMap treats different-sized primitive numbers as non-convertible types. This is correct behavior, because, like all C++ containers, GenericMap supports value mutation by returning references, and a float& cannot be safely used to refer to a double (or vice versa).
- The behavior is not affected by pybind11's noconvert flag: it behaves as if np.int32, np.int64, std::int32_t, and std::int64_t were all equivalent types. Possibly related, error messages for other failures triggered by noconvert list all integer overloads as int and all floating-point overloads as float.
- Pybind11 provides some special APIs for dealing with numpy arrays in C++, but none for scalar types.