-
This is a follow-up to #24 of sorts, in which I've
The following diff (against 90d2445, for specificity) reproduces what I'm up against within the context of the nanobind test suite: diff --git a/tests/test_functions.cpp b/tests/test_functions.cpp
index c545656..f11da84 100644
--- a/tests/test_functions.cpp
+++ b/tests/test_functions.cpp
@@ -125,4 +125,7 @@ NB_MODULE(test_functions_ext, m) {
result[k] = v;
return result;
});
+
+ // Function taking an unsigned type, for numpy compatbiility testing
+ m.def("test_11", [](unsigned x) -> unsigned { return x; });
}
diff --git a/tests/test_functions.py b/tests/test_functions.py
index 8788fe2..3f535ef 100644
--- a/tests/test_functions.py
+++ b/tests/test_functions.py
@@ -185,3 +185,6 @@ def test21_numpy_overloads():
assert t.test_05(np.int32(0)) == 1
assert t.test_05(np.float64(0.0)) == 2
+
+ # a function taking an unsigned type
+ assert t.test_11(np.int32(17)) == 17 Running the tests ends up with
I don't quite know what to make of this. This is borne out by the CPython source, where but While that seems weirdly inconsistent, the behavior is as documented: https://docs.python.org/3/c-api/long.html?highlight=pylong_asunsignedlong#c.PyLong_AsUnsignedLong in that @wjakob I'd be grateful for your take on this. Edit: To be clear, as far as workarounds go, I am not lobbying for a revival of #24. I agree that that is too blunt an instrument. But something lighter-weight, such as attempting to cast unsigned types via (signed) long long upon failure, seems somewhat reasonable to me. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
This is now fixed on master. |
Beta Was this translation helpful? Give feedback.
-
I am currently facing a similar issue involving numpy.uint32. My C++ class signature is described in the following wrapping code: .def("randGaussian", static_cast<vector<double> (SiPMRandom::*)(const double, const double, const uint32_t)>(&SiPMRandom::randGaussian))
And i call it in python with the following code: t = rng.randGaussian(25.0, 0.01, npe[i]) Where npe[i] is a np.array with dtype=np.uint32. I get the following error even thou the signature and the arguments passed are correct to me (here I am calling the second overload)
|
Beta Was this translation helpful? Give feedback.
This is now fixed on master.