Skip to content

PyROOT multidimenstional int16_t arrays stopped working in 6.34 #17841

Open
@cozzyd

Description

@cozzyd

Check duplicate issues.

  • Checked for duplicates

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

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 < 24; 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 gives something like

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
(268435455, -1)
L
L
[[  7424  -5267]
 [-14155 -14397]
 [-11728 -28243]
 [ 32764      0]
 [  2288 -32302]
 [ 32521      0]
 [ 25856 -32290]
 [ 32521      0]
 [  1856 -32275]
 [ 32521      0]
 [     0      0]
 [     0      0]
 [  7424  -5267]
 [-14155 -14397]
 [-11712 -28243]
 [ 32764      0]
 [-29904  25230]
 [ 32521      0]
 [     1      0]
 [     0      0]
 [-13552  -8813]
 [ 32520      0]
 [     0      0]
 [     0      0]]

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions