mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 11:08:52 +00:00
Small tweak: remove the macro usage for the range indexing trait. (#1376)
This commit is contained in:
@ -104,37 +104,31 @@ impl From<&Tensor> for TensorIndexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_from_range {
|
trait RB: RangeBounds<usize> {}
|
||||||
($range_type:ty) => {
|
impl RB for Range<usize> {}
|
||||||
impl From<$range_type> for TensorIndexer {
|
impl RB for RangeFrom<usize> {}
|
||||||
fn from(range: $range_type) -> Self {
|
impl RB for RangeFull {}
|
||||||
use std::ops::Bound::*;
|
impl RB for RangeInclusive<usize> {}
|
||||||
|
impl RB for RangeTo<usize> {}
|
||||||
|
impl RB for RangeToInclusive<usize> {}
|
||||||
|
|
||||||
|
impl<T: RB> From<T> for TensorIndexer {
|
||||||
|
fn from(range: T) -> Self {
|
||||||
|
use std::ops::Bound::*;
|
||||||
let start = match range.start_bound() {
|
let start = match range.start_bound() {
|
||||||
Included(idx) => Included(*idx),
|
Included(idx) => Included(*idx),
|
||||||
Excluded(idx) => Excluded(*idx),
|
Excluded(idx) => Excluded(*idx),
|
||||||
Unbounded => Unbounded,
|
Unbounded => Unbounded,
|
||||||
};
|
};
|
||||||
|
|
||||||
let end = match range.end_bound() {
|
let end = match range.end_bound() {
|
||||||
Included(idx) => Included(*idx),
|
Included(idx) => Included(*idx),
|
||||||
Excluded(idx) => Excluded(*idx),
|
Excluded(idx) => Excluded(*idx),
|
||||||
Unbounded => Unbounded,
|
Unbounded => Unbounded,
|
||||||
};
|
};
|
||||||
|
|
||||||
TensorIndexer::Narrow(start, end)
|
TensorIndexer::Narrow(start, end)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_from_range!(Range<usize>);
|
|
||||||
impl_from_range!(RangeFrom<usize>);
|
|
||||||
impl_from_range!(RangeFull);
|
|
||||||
impl_from_range!(RangeInclusive<usize>);
|
|
||||||
impl_from_range!(RangeTo<usize>);
|
|
||||||
impl_from_range!(RangeToInclusive<usize>);
|
|
||||||
|
|
||||||
/// Trait used to implement multiple signatures for ease of use of the slicing
|
/// Trait used to implement multiple signatures for ease of use of the slicing
|
||||||
/// of a tensor
|
/// of a tensor
|
||||||
pub trait IndexOp<T> {
|
pub trait IndexOp<T> {
|
||||||
|
Reference in New Issue
Block a user