Created
February 27, 2022 20:41
-
-
Save agoose77/6c6771e814669338d0f7a3e3ae7c47fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def choose(a, choices, mode="raise", highlevel=True, behavior=None): | |
def getfunction(inputs, depth): | |
if not all(x.purelist_depth == 1 for x in inputs): | |
return | |
arrays = [nplike.asarray(x) for x in inputs] | |
a = arrays[0] | |
choices = arrays[1:] | |
out = np.choose(a, choices, mode=mode) | |
return lambda: (ak.layout.NumpyArray(out),) | |
arrays = [a, *choices] | |
inputs = [ak.to_layout(x) for x in arrays] | |
nplike = ak.nplike.of(arrays) | |
behavior = ak._util.behaviorof(arrays, behavior=behavior) | |
out, = ak._util.broadcast_and_apply(inputs, getfunction, behavior) | |
return ak._util.maybe_wrap(out, behavior, highlevel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment