Skip to content

[cppyy] Conversion of signed char pointer / vector into int8 numpy array #21434

@AlkaidCheng

Description

@AlkaidCheng

Check duplicate issues.

  • Checked for duplicates

Description

For common data types, e.g. int, double, we can convert a pointer / vector to numpy array with a direct construction:

import numpy as np
import cppyy
import cppyy.ll

vec = cppyy.gbl.std.vector([-1, 0, 1])
# works
arr = np.array(vec)
# also works
arr = np.array(vec.data())

Reproducer

However for int8 (or signed char in C++), the conversion only works for a pointer, but not for a vector:

import numpy as np
import cppyy
import cppyy.ll

arr = np.array([-1, 0, 1], dtype=np.int8)
view = cppyy.ll.cast[f"signed char*"](arr.ctypes.data)
view.reshape((3,))
vec = cppyy.gbl.std.vector['signed char'](view)
# does not work (OverflowError: character argument not in range(0x110000))
arr = np.array(vec)
# works
arr = np.array(vec.data())

ROOT version

cppyy==3.5.0

Installation method

conda (bundled with root)

Operating system

Linux

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions