Skip to content

toch/np like indexig for DocumentArrayStacked #1073

@JohannesMessner

Description

@JohannesMessner

PyTorch (and numpy, too) supports a rich and flexible indexing API: https://pytorch.org/cppdocs/notes/tensor_indexing.html
DocumentArrayStacked should support the same.

Concretely, we should be able to do the following:

da = DocumentArray([... for _ in range(5)]
da[0]  # index by offset; returns doc at this position
da[0:5:2]  # index by slice; returns every other doc
da[0, 1, 2]  # index by sequence of positions; returns DocumentArray with docs at these positions
da[[0, 1, 2]]  # same as above
da[[True, False, True, True, False]]  # index by boolean mask; returns DocumentArray with "True" docs
da[None]  # returns `da`, just to conform with PyTorch convention

Metadata

Metadata

Labels

DocArray v2This issue is part of the rewrite; not to be merged into main

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions