mars-project / mars-project/mars
[BUG] Fail to slice tensors with tensors in slice indices
- Dominant language
- Python
- Stars
- 2.7k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Failed to slice tensors with tensors in slice indices. Sample code:
```python
import mars.tensor as mt
arr = mt.tensor([1, 4, 5, 7, 9])
pos = mt.searchsorted(arr, 6)
arr[:pos + 1].execute()
```
Error stack:
```
Traceback (most recent call last):
File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
arr[:pos + 1].execute()
File "/Users/wenjun/Code/mars/mars/tensor/indexing/getitem.py", line 344, in _getitem
return _getitem_nocheck(a, item)
File "/Users/wenjun/Code/mars/mars/tensor/indexing/getitem.py", line 330, in _getitem_nocheck
shape = calc_shape(a.shape, index)
File "/Users/wenjun/Code/mars/mars/tensor/indexing/core.py", line 65, in calc_shape
shape.append(calc_sliced_size(tensor_shape[in_axis], ind))
File "/Users/wenjun/Code/mars/mars/tensor/utils.py", line 304, in calc_sliced_size
start, stop, step = sliceobj.indices(size)
TypeError: slice indices must be integers or None or have an __index__ method
```
Contributor guide
Research direction
Start with the failing reproduction and trace the named files mars/tensor/indexing/getitem.py, mars/tensor/indexing/core.py, and mars/tensor/utils.py, especially calc_shape and calc_sliced_size. Confirm the current failure, then verify that arr[:pos + 1].execute() succeeds and produces the expected slice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100