From 1db5b5bbbe9ab03a95f89a2f61678a82868b82f7 Mon Sep 17 00:00:00 2001 From: rkansal47 Date: Wed, 9 Nov 2022 14:06:30 +0000 Subject: [PATCH 1/3] fix memory allocation --- src/_ext.cpp | 6 +++--- src/fastjet/_generalevent.py | 10 +++++----- src/fastjet/_multievent.py | 6 +++--- src/fastjet/_singleevent.py | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 4b6cf921..36d7b9dd 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -186,7 +186,7 @@ PYBIND11_MODULE(_ext, m) { auto bufparid = parid.request(); int *ptrid = (int *)bufparid.ptr; - auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len}, {sizeof(int)})); + auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len+1}, {sizeof(int)})); auto bufeventoffsets = eventoffsets.request(); int *ptreventoffsets = (int *)bufeventoffsets.ptr; size_t eventidx = 0; @@ -315,7 +315,7 @@ PYBIND11_MODULE(_ext, m) { auto bufparid = parid.request(); int *ptrid = (int *)bufparid.ptr; - auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len}, {sizeof(int)})); + auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len+1}, {sizeof(int)})); auto bufeventoffsets = eventoffsets.request(); int *ptreventoffsets = (int *)bufeventoffsets.ptr; size_t eventidx = 0; @@ -1477,7 +1477,7 @@ PYBIND11_MODULE(_ext, m) { auto parid = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {jk}, {sizeof(int)})); auto bufparid = parid.request(); int *ptrid = (int *)bufparid.ptr; - auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len}, {sizeof(int)})); + auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len+1}, {sizeof(int)})); auto bufeventoffsets = eventoffsets.request(); int *ptreventoffsets = (int *)bufeventoffsets.ptr; size_t eventidx = 0; diff --git a/src/fastjet/_generalevent.py b/src/fastjet/_generalevent.py index 8bf4968e..5dab7794 100644 --- a/src/fastjet/_generalevent.py +++ b/src/fastjet/_generalevent.py @@ -608,7 +608,7 @@ def constituents(self, min_pt): self._input_flag = 0 for i in range(len(self._clusterable_level)): np_results = self._results[i].to_numpy_with_constituents(min_pt) - off = np.insert(np_results[-1], 0, 0) + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), @@ -637,7 +637,7 @@ def exclusive_jets_constituents(self, njets): np_results = self._results[i].to_numpy_exclusive_njet_with_constituents( njets ) - off = np.insert(np_results[-1], 0, 0) + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), @@ -661,7 +661,7 @@ def constituent_index(self, min_pt): self._input_flag = 0 for i in range(len(self._clusterable_level)): np_results = self._results[i].to_numpy_with_constituents(min_pt) - off = np.insert(np_results[-1], 0, 0) + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), @@ -687,7 +687,7 @@ def exclusive_jets_constituent_index(self, njets): np_results = self._results[i].to_numpy_exclusive_njet_with_constituents( njets ) - off = np.insert(np_results[-1], 0, 0) + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), @@ -873,7 +873,7 @@ def unique_history_order(self): self._input_flag = 0 for i in range(len(self._clusterable_level)): np_results = self._results[i].to_numpy_unique_history_order() - off = np.insert(np_results[-1], 0, 0) + off = np_results[-1] self._out.append( ak.Array( ak.layout.ListOffsetArray64( diff --git a/src/fastjet/_multievent.py b/src/fastjet/_multievent.py index 92794d24..1bc3e1a9 100644 --- a/src/fastjet/_multievent.py +++ b/src/fastjet/_multievent.py @@ -175,7 +175,7 @@ def exclusive_jets_ycut(self, ycut): def constituent_index(self, min_pt): np_results = self._results.to_numpy_with_constituents(min_pt) - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -189,7 +189,7 @@ def exclusive_jets_constituent_index(self, njets): raise ValueError("Njets cannot be <= 0") np_results = self._results.to_numpy_exclusive_njet_with_constituents(njets) - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -200,7 +200,7 @@ def exclusive_jets_constituent_index(self, njets): def unique_history_order(self): np_results = self._results.to_numpy_unique_history_order() - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(off), ak.layout.NumpyArray(np_results[0]) diff --git a/src/fastjet/_singleevent.py b/src/fastjet/_singleevent.py index 81e8af39..7be5580a 100644 --- a/src/fastjet/_singleevent.py +++ b/src/fastjet/_singleevent.py @@ -163,7 +163,7 @@ def exclusive_jets_ycut(self, ycut): def constituent_index(self, min_pt): np_results = self._results.to_numpy_with_constituents(min_pt) - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -177,7 +177,7 @@ def exclusive_jets_constituent_index(self, njets): raise ValueError("Njets cannot be <= 0") np_results = self._results.to_numpy_exclusive_njet_with_constituents(njets) - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -193,7 +193,7 @@ def unique_history_order(self): def constituents(self, min_pt): np_results = self._results.to_numpy_with_constituents(min_pt) - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -214,7 +214,7 @@ def exclusive_jets_constituents(self, njets): np_results = self._results.to_numpy_exclusive_njet_with_constituents(njets) - off = np.insert(np_results[-1], 0, 0) + off = np.results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) From 7cc7115be8985997fa99a5b743836aa4ca04cfe4 Mon Sep 17 00:00:00 2001 From: rkansal47 Date: Wed, 9 Nov 2022 14:20:28 +0000 Subject: [PATCH 2/3] bug fix --- src/fastjet/_multievent.py | 6 +++--- src/fastjet/_singleevent.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fastjet/_multievent.py b/src/fastjet/_multievent.py index 1bc3e1a9..7552b9d3 100644 --- a/src/fastjet/_multievent.py +++ b/src/fastjet/_multievent.py @@ -175,7 +175,7 @@ def exclusive_jets_ycut(self, ycut): def constituent_index(self, min_pt): np_results = self._results.to_numpy_with_constituents(min_pt) - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -189,7 +189,7 @@ def exclusive_jets_constituent_index(self, njets): raise ValueError("Njets cannot be <= 0") np_results = self._results.to_numpy_exclusive_njet_with_constituents(njets) - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -200,7 +200,7 @@ def exclusive_jets_constituent_index(self, njets): def unique_history_order(self): np_results = self._results.to_numpy_unique_history_order() - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(off), ak.layout.NumpyArray(np_results[0]) diff --git a/src/fastjet/_singleevent.py b/src/fastjet/_singleevent.py index 7be5580a..25efe05a 100644 --- a/src/fastjet/_singleevent.py +++ b/src/fastjet/_singleevent.py @@ -163,7 +163,7 @@ def exclusive_jets_ycut(self, ycut): def constituent_index(self, min_pt): np_results = self._results.to_numpy_with_constituents(min_pt) - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -177,7 +177,7 @@ def exclusive_jets_constituent_index(self, njets): raise ValueError("Njets cannot be <= 0") np_results = self._results.to_numpy_exclusive_njet_with_constituents(njets) - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -193,7 +193,7 @@ def unique_history_order(self): def constituents(self, min_pt): np_results = self._results.to_numpy_with_constituents(min_pt) - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) @@ -214,7 +214,7 @@ def exclusive_jets_constituents(self, njets): np_results = self._results.to_numpy_exclusive_njet_with_constituents(njets) - off = np.results[-1] + off = np_results[-1] out = ak.Array( ak.layout.ListOffsetArray64( ak.layout.Index64(np_results[0]), ak.layout.NumpyArray(np_results[1]) From 9e48b164a573c1683e30a8acb75cc7e899ab0435 Mon Sep 17 00:00:00 2001 From: rkansal47 Date: Wed, 9 Nov 2022 14:31:53 +0000 Subject: [PATCH 3/3] initial 0 in event offsets --- src/_ext.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/_ext.cpp b/src/_ext.cpp index 36d7b9dd..651b6aa7 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -191,6 +191,9 @@ PYBIND11_MODULE(_ext, m) { int *ptreventoffsets = (int *)bufeventoffsets.ptr; size_t eventidx = 0; + ptreventoffsets[eventidx] = 0; + eventidx++; + auto jetoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {jk}, {sizeof(int)})); auto bufjetoffsets = jetoffsets.request(); int *ptrjetoffsets = (int *)bufjetoffsets.ptr; @@ -320,6 +323,9 @@ PYBIND11_MODULE(_ext, m) { int *ptreventoffsets = (int *)bufeventoffsets.ptr; size_t eventidx = 0; + ptreventoffsets[eventidx] = 0; + eventidx++; + auto jetoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {jk}, {sizeof(int)})); auto bufjetoffsets = jetoffsets.request(); int *ptrjetoffsets = (int *)bufjetoffsets.ptr; @@ -1481,6 +1487,8 @@ PYBIND11_MODULE(_ext, m) { auto bufeventoffsets = eventoffsets.request(); int *ptreventoffsets = (int *)bufeventoffsets.ptr; size_t eventidx = 0; + ptreventoffsets[eventidx] = 0; + eventidx++; size_t idxh = 0; auto eventprev = 0; for (unsigned int i = 0; i < css.size(); i++){