huggingface/ratchet

Improve slicing

開放

#91 建立於 2024年2月19日

 (0 則留言) (0 個反應) (0 位負責人)Rust (44 個分叉)auto 404
enhancementhelp wanted

倉庫指標

星標
 (768 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Currently our slice definition looks as follows:

    pub fn slice<D: std::ops::RangeBounds<usize>>(&self, ranges: &[D]) -> anyhow::Result<Tensor> {
        ///...impl...
    }

This is very user hostile, as the user must provide a homogeneous collection of ranges.

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

let y = x.slice(&[.., 0..6, ..]);

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

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

let y = x.slice(s![.., 0..6, ..]);

This API gives the illusion of heterogeneous collections, which is what we want.

貢獻者指南