huggingface / huggingface/ratchet

Improve slicing

Open
#91 0 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Rust
Stars
771
Forks
44
Avg merge
40m
Merged PRs (30d)
1

Description

Currently our slice definition looks as follows:
```rust
pub fn slice>(&self, ranges: &[D]) -> anyhow::Result {
///...impl...
}
```

This is very user hostile, as the user must provide a homogeneous collection of ranges.
```rust
let y = x.slice(&[0..5, 0..6, 0..7]);
```

This is very annoying, as you may only care about one of the dimensions, it would be better to have something like
```rust
let y = x.slice(&[.., 0..6, ..]);
```

Unfortunately, this doesn't work, because the collection is now heterogeneous (i.e is made up of 2x`RangeFull` and 1x`Range`).

Therefore, we need to use a macro, much like `ndarray`.

```rust
let y = x.slice(s![.., 0..6, ..]);
```
This API gives the illusion of heterogeneous collections, which is what we want.

Contributor guide

Open the contributing guide

Research direction

Start at the Tensor::slice API shown in the issue and study how ndarray's s! macro represents heterogeneous ranges. Define the macro-based slicing interface and verify that examples such as s![.., 0..6, ..] work while preserving the intended slicing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.