scikit-hep / awkward-0.x

Manipulate arrays of complex data structures as easily as Numpy.
BSD 3-Clause "New" or "Revised" License
215 stars 39 forks source link

Cyclic array? #242

Open noamzilo opened 4 years ago

noamzilo commented 4 years ago

I would like to create a bounded, cyclic array. Is that supported? Couldn't find such functionality in the doc.

jpivarski commented 4 years ago

Is the logical length finite or infinite? For infinite lengths, that's something that I hadn't considered; everything must have an int64 length, so it's a non-starter.

Do you mean this?

>>> import awkward1 as ak
>>>
>>> original = ak.Array(np.arange(7) * 1.1)
>>> original
<Array [0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6] type='7 * float64'>
>>> 
>>> ak.Array(ak.layout.IndexedArray64(ak.layout.Index64(np.roll(np.arange(7), -2)),
...                                   original.layout))
<Array [2.2, 3.3, 4.4, 5.5, 6.6, 0, 1.1] type='7 * float64'>

The IndexedArray node wraps a view of the data cyclically, and you can change the view in a rather lightweight way (only replacing the IndexedArray node, leaving all the underlying data, which can contain complex records).

But fundamentally, I don't know what it is that you want.