Skip to content

Commit 78cd02f

Browse files
authored
perf: reduce python overhead for awkward backend (#554)
* awkward backend: reduce python overhead by applying multiple operations in one single broadcasting traversal * add a fast path for noops, otherwise ak.transform does a non-negligible overhead...
1 parent a61d2ef commit 78cd02f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+402
-118
lines changed

src/vector/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _import_awkward() -> None:
7676
if not typing.TYPE_CHECKING:
7777
VectorAwkward = None
7878
else:
79-
from vector.backends.awkward import VectorAwkward
79+
from vector.backends.awkward import VectorAwkward, awkward_transform
8080

8181
try:
8282
import sympy # type: ignore[import-untyped]
@@ -143,6 +143,7 @@ def _import_awkward() -> None:
143143
"arr",
144144
"array",
145145
"awk",
146+
"awkward_transform",
146147
"dim",
147148
"obj",
148149
"register_awkward",

src/vector/_compute/lorentz/Et.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def dispatch(v: typing.Any) -> typing.Any:
114114
with numpy.errstate(all="ignore"):
115115
return v._wrap_result(
116116
_flavor_of(v),
117-
function(
117+
v._wrap_dispatched_function(function)(
118118
v.lib,
119119
*v.azimuthal.elements,
120120
*v.longitudinal.elements,

src/vector/_compute/lorentz/Et2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def dispatch(v: typing.Any) -> typing.Any:
116116
with numpy.errstate(all="ignore"):
117117
return v._wrap_result(
118118
_flavor_of(v),
119-
function(
119+
v._wrap_dispatched_function(function)(
120120
v.lib,
121121
*v.azimuthal.elements,
122122
*v.longitudinal.elements,

src/vector/_compute/lorentz/Mt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def dispatch(v: typing.Any) -> typing.Any:
110110
with numpy.errstate(all="ignore"):
111111
return v._wrap_result(
112112
_flavor_of(v),
113-
function(
113+
v._wrap_dispatched_function(function)(
114114
v.lib,
115115
*v.azimuthal.elements,
116116
*v.longitudinal.elements,

src/vector/_compute/lorentz/Mt2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def dispatch(v: typing.Any) -> typing.Any:
111111
with numpy.errstate(all="ignore"):
112112
return v._wrap_result(
113113
_flavor_of(v),
114-
function(
114+
v._wrap_dispatched_function(function)(
115115
v.lib,
116116
*v.azimuthal.elements,
117117
*v.longitudinal.elements,

src/vector/_compute/lorentz/add.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ def dispatch(v1: typing.Any, v2: typing.Any) -> typing.Any:
201201
),
202202
)
203203
with numpy.errstate(all="ignore"):
204-
return _handler_of(v1, v2)._wrap_result(
204+
handler = _handler_of(v1, v2)
205+
return handler._wrap_result(
205206
_flavor_of(v1, v2),
206-
function(
207+
handler._wrap_dispatched_function(function)(
207208
_lib_of(v1, v2),
208209
*v1.azimuthal.elements,
209210
*v1.longitudinal.elements,

src/vector/_compute/lorentz/beta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def dispatch(v: typing.Any) -> typing.Any:
153153
with numpy.errstate(all="ignore"):
154154
return v._wrap_result(
155155
_flavor_of(v),
156-
function(
156+
v._wrap_dispatched_function(function)(
157157
v.lib,
158158
*v.azimuthal.elements,
159159
*v.longitudinal.elements,

src/vector/_compute/lorentz/boostX_beta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def dispatch(beta: typing.Any, v: typing.Any) -> typing.Any:
243243
with numpy.errstate(all="ignore"):
244244
return v._wrap_result(
245245
_flavor_of(v),
246-
function(
246+
v._wrap_dispatched_function(function)(
247247
v.lib,
248248
beta,
249249
*v.azimuthal.elements,

src/vector/_compute/lorentz/boostX_gamma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def dispatch(gamma: typing.Any, v: typing.Any) -> typing.Any:
243243
with numpy.errstate(all="ignore"):
244244
return v._wrap_result(
245245
_flavor_of(v),
246-
function(
246+
v._wrap_dispatched_function(function)(
247247
v.lib,
248248
gamma,
249249
*v.azimuthal.elements,

src/vector/_compute/lorentz/boostY_beta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def dispatch(beta: typing.Any, v: typing.Any) -> typing.Any:
243243
with numpy.errstate(all="ignore"):
244244
return v._wrap_result(
245245
_flavor_of(v),
246-
function(
246+
v._wrap_dispatched_function(function)(
247247
v.lib,
248248
beta,
249249
*v.azimuthal.elements,

0 commit comments

Comments
 (0)