cppyy icon indicating copy to clipboard operation
cppyy copied to clipboard

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

Open guitargeek opened this issue 1 year ago • 2 comments

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.

guitargeek avatar Jul 09 '24 23:07 guitargeek

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

wlav avatar Jul 11 '24 01:07 wlav

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.

guitargeek avatar Jul 12 '24 10:07 guitargeek