finch-tensor / finch-tensor-python

Sparse and Structured Tensor Programming in Python
MIT License
8 stars 3 forks source link

API: Implement indexing and slicing for `Tensor` #14

Closed mtsokol closed 7 months ago

mtsokol commented 8 months ago

Hi @willow-ahrens @hameerabbasi,

This PR implements indexing and slicing functionality to Tensor class. Following Array API standard, indexing can be performed with: ints a[1, 3], slices a[:, 1:10:2], ellipsis a[8, ...], and arrays/lists a[:, [1,1,2]]. Missing dims are expanded to :, so for 3-D array, array[4] is equal to array[4, :, :].

AFAIK Julia doesn't support Ellipsis, so I implemented expanding it to slices here. Also, Finch Tensor accepts ranges instead of slices, so I convert slice(...) to jl.range(...).

For 1-D tests to pass https://github.com/willow-ahrens/Finch.jl/issues/427 needs to be solved first.

mtsokol commented 8 months ago

Now the PR is ready from my side: It includes the fix for 1D Tensor indexing that we merged yesterday and negative indices support.

hameerabbasi commented 7 months ago

Thanks for all the work here, @mtsokol!