-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argcross and cross #78
Comments
If I recall, we were going to keep such operations as module methods like |
That's right, at the |
Here's an interesting observation: cross is a composition of broadcasting and zip. a = numpy.arange(24).reshape(6, 4)
b = numpy.array(['a', 'b'] * 6).reshape(6, 2) Then the awkward0 operation i0, i1 = numpy.broadcast_arrays(a[:, :, None], b[:, None, :])
rectype = [('i0', i0.dtype), ('i1', i1.dtype)]
out = numpy.fromiter(zip(i0.flatten(), i1.flatten()), dtype=rectype).reshape(6, 2*4) The i0 = a
i1 = numpy.broadcast_to(b[:, None, :], shape=(6, 4, 2)) In fact, with the current awkward1 master, nested cross is effectively implemented: a = ak.Array([[0, 1, 2], [3, 4], [5], []])
b = ak.Array([[1], [2, 3], [4], [5, 6, 7]])
a[:, :, None] < b[:, None, :] is the same as awkward0's a = ak0.fromiter([[0, 1, 2], [3, 4], [5], []])
b = ak0.fromiter([[1], [2, 3], [4], [5, 6, 7]])
ab = a.cross(b, nested=True)
ab.i0 < ab.i1 Non-nested cross will need a[:, :, None] < b[:, None, :]
a < b[:, None] and a simple switch of where we insert newaxis gives us a[:, None] < b |
@nsmith- I wasn't planning to, but in the end, I used your method to implement Thanks! Your observation really helped! |
Implementing
argcross
in C++ is sufficient; we can docross
in Python.This computes a Cartesian product per element. Given a list (
std::vector
) of arrays (std::shared_ptr<Content>
), it makes aListOffsetArray
ofRecordArray
of combinations. For example,This and
choose
(issue #79) are the two basic generators of particle combinatorics in HEP analyses.The text was updated successfully, but these errors were encountered: