56
56
\endpythondoc
57
57
"""
58
58
59
- from . import pythonization
60
- import cppyy
61
59
import sys
62
60
61
+ import cppyy
62
+
63
+ from . import pythonization
63
64
64
65
_array_interface_dtype_map = {
65
66
"Long64_t" : "i" ,
75
76
76
77
77
78
def _get_cpp_type_from_numpy_type (dtype ):
78
- cpptypes = {"i2" : "Short_t" , "u2" : "UShort_t" , "i4" : "int" , "u4" : "unsigned int" , "i8" : "Long64_t" , "u8" : "ULong64_t" , "f4" : "float" , "f8" : "double" , "b1" : "bool" }
79
+ cpptypes = {
80
+ "i2" : "Short_t" ,
81
+ "u2" : "UShort_t" ,
82
+ "i4" : "int" ,
83
+ "u4" : "unsigned int" ,
84
+ "i8" : "Long64_t" ,
85
+ "u8" : "ULong64_t" ,
86
+ "f4" : "float" ,
87
+ "f8" : "double" ,
88
+ "b1" : "bool" ,
89
+ }
79
90
80
91
if dtype not in cpptypes :
81
92
raise RuntimeError ("Object not convertible: Python object has unknown data-type '" + dtype + "'." )
@@ -95,10 +106,12 @@ def _AsRVec(arr):
95
106
interface dictionary.
96
107
Note that for arrays of strings, the input strings are copied into the RVec.
97
108
"""
98
- import ROOT
99
109
import math
110
+
100
111
import numpy as np
101
112
113
+ import ROOT
114
+
102
115
# Get array interface of object
103
116
interface = arr .__array_interface__
104
117
@@ -117,7 +130,11 @@ def _AsRVec(arr):
117
130
if dtype == "O" or dtype .startswith ("U" ):
118
131
underlying_object_types = {type (elem ) for elem in arr }
119
132
if len (underlying_object_types ) > 1 :
120
- raise TypeError ("All elements in the numpy array must be of the same type. Found types: {}" .format (underlying_object_types ))
133
+ raise TypeError (
134
+ "All elements in the numpy array must be of the same type. Found types: {}" .format (
135
+ underlying_object_types
136
+ )
137
+ )
121
138
122
139
if underlying_object_types and underlying_object_types .pop () in [str , np .str_ ]:
123
140
return ROOT .VecOps .RVec ["std::string" ](arr )
@@ -130,7 +147,7 @@ def _AsRVec(arr):
130
147
+ typestr
131
148
+ "' with invalid length unequal 3."
132
149
)
133
-
150
+
134
151
# Construct an RVec of the correct data-type
135
152
cppdtype = _get_cpp_type_from_numpy_type (dtype )
136
153
out = ROOT .VecOps .RVec [cppdtype ](ROOT .module .cppyy .ll .reinterpret_cast [f"{ cppdtype } *" ](data ), size )
0 commit comments