wlav / cppyy

Other
411 stars 42 forks source link

Converters from numpy types to corresponding C++ types gone missing #249

Open guitargeek opened 4 months ago

guitargeek commented 4 months ago

Reported originally on the ROOT forum: https://root-forum.cern.ch/t/numpy-ints-not-accepted-in-ttree-getentry-in-root-6-32/59712/8

Reproducer:

import cppyy
import numpy as np

cppyy.cppdef("""
   std::int64_t foo(std::int64_t x) { return x; }
""")

print(cppyy.gbl.foo(np.int64(10)))

Output:

Traceback (most recent call last):
  File "/home/rembserj/root-support/forum/numpy-ints-not-accepted-in-ttree-getentry-in-root-6-32/repro.py", line 8, in <module>
    print(cppyy.gbl.foo(np.int64(10)))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: long ::foo(std::int64_t x) =>
    TypeError: could not convert argument 1 (int/long conversion expects an integer object)

Expected output:

10

In fact, the expected behavior was occurring with a previous cppyy version used before ROOT 6.32. Therefore, this issue is a behavior regression that catches uses by surprise.

wlav commented 4 months ago

Was support for numpy types added to the ROOT fork of cppyy? AFAIK, this has never worked in master.

guitargeek commented 4 months ago

At least I couldn't identify a commit of patch that explicitly added support for it. I will try out a few different ROOT and cppyy versions to understand what is going on.