Skip to content

Commit

Permalink
Added a mandatory type conversion of numpy array to the vector type i…
Browse files Browse the repository at this point in the history
…n StdVectorList iadd()
  • Loading branch information
lwpiotr committed Jan 23, 2025
1 parent 8be0351 commit 3233e59
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions grand/dataio/root_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def __iadd__(self, value):
# function modified by Jelena to fix the negative issue, use at own risk
try:
if isinstance(value, np.ndarray):
# Sometimes, for example, int is given in place of unsigned int, and C++ fuction does not convert it, so python conversion is needed
value = value.astype(cpp_to_numpy_typecodes[self.basic_vec_type])
if self.ndim == 1: ROOT.fill_vec_1D[self.basic_vec_type](np.ascontiguousarray(value), np.array(value.shape).astype(np.int32), self._vector)
if self.ndim == 2: ROOT.fill_vec_2D[self.basic_vec_type](np.ascontiguousarray(value), np.array(value.shape).astype(np.int32), self._vector)
if self.ndim == 3: ROOT.fill_vec_3D[self.basic_vec_type](np.ascontiguousarray(value), np.array(value.shape).astype(np.int32), self._vector)
Expand Down

0 comments on commit 3233e59

Please sign in to comment.