-
Notifications
You must be signed in to change notification settings - Fork 1.3k
PyROOT multidimenstional int16_t arrays stopped working in 6.34 #17841
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
Comments
In debug mode I get:
|
@ferdymercury VarDecl 0x130ed7908 <input_line_22:10:6, col:14> col:10 used i 'int' cinit
`-IntegerLiteral 0x130ed7970 <col:14> 'int' 0
Assertion failed: (VD.isLocalVarDecl() && "Should not see file-scope variables inside a function!"), function EmitDecl, file CGDecl.cpp, line 162.
... Looking further in the stack trace, and dumping the VarDecl 0x130ed7908 <input_line_22:10:6, col:14> col:10 used i 'int' cinit
`-IntegerLiteral 0x130ed7970 <col:14> 'int' 0 which is the import cppyy
import cppyy.ll
import numpy
cppyy.cppdef(
"""
// struct Foo {
// int16_t bar[24][2];
// };
// Foo foo;
// foo.bar[0][0]=1;
// foo.bar[10][1]=1;
for(int i = 0; i < 0; i++) {
// std::cout << foo.bar[i][0] << " " << foo.bar[i][1] << std::endl;
}
"""
)
# arr = cppyy.gbl.foo.bar
# print(arr.shape)
# print(arr.typecode)
# print(arr.format)
# this cast was necessary for some reason in older ROOT versions, though it doesn't change anything here
# a = numpy.frombuffer(
# cppyy.ll.cast["int16_t*"](arr), dtype="int16", count=24 * 2
# ).reshape((24, 2))
# print(a) |
This works absolutely fine for (24, 2)
b
b
[[1 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 1]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]
[0 0]] |
A simpler reproducer: import cppyy
import numpy
cppyy.cppdef("""
struct Foo {int32_t bar[24][2] = {};};
Foo foo;
foo.bar[0][0]=1;
foo.bar[9][0]=42;
foo.bar[10][1]=1;
""")
arr = cppyy.gbl.foo.bar
print(arr)
print(arr.shape)
print(arr.typecode)
print(arr.format)
a = numpy.frombuffer(arr, dtype='int32', count=24*2).reshape((24,2))
print(a) The following PR: #18492 should fix the problem |
Check duplicate issues.
Description
We serialize some objects containing 2D int16_t arrays (these are waveforms). For our PyROOT interface, we convert them to numpy arrays using numpy.frombuffer.
Starting in ROOT 6.34, at least as distributed by Fedora and by EL9 EPEL, this no longer works. One-dimensional arrays seem fine.
Reproducer
Here is a standalone example exhibiting the problem
This gives something like
Obviously the shape and typecode are wrong, and the array is garbage, when this used to work fine.
ROOT version
ROOT 6.34.04
Installation method
dnf
Operating system
Fedora and also EPEL9
Additional context
I reported this at cppyy, but apparently this is fine in current upstream cppyy.
The text was updated successfully, but these errors were encountered: