Skip to main content

faer/row/
row_index.rs

1use super::*;
2use crate::into_range::IntoRange;
3use crate::{Idx, IdxInc, assert, debug_assert};
4impl<'a, C: Shape, T, Cs: Stride, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>>
5	RowIndex<ColRange> for RowRef<'a, T, C, Cs>
6{
7	type Target = RowRef<'a, T, ColRange::Len<C>, Cs>;
8
9	#[track_caller]
10	#[inline]
11	fn get(this: Self, col: ColRange) -> Self::Target {
12		let col = col.into_range(C::start(), this.ncols().end());
13		assert!(all(col.start <= col.end, col.end <= this.ncols()));
14		let ncols = unsafe {
15			ColRange::Len::<C>::new_unbound(
16				col.end.unbound() - col.start.unbound(),
17			)
18		};
19		this.subcols(col.start, ncols)
20	}
21
22	#[track_caller]
23	#[inline]
24	unsafe fn get_unchecked(this: Self, col: ColRange) -> Self::Target {
25		let col = col.into_range(C::start(), this.ncols().end());
26		debug_assert!(all(col.start <= col.end, col.end <= this.ncols(),));
27		let ncols = unsafe {
28			ColRange::Len::<C>::new_unbound(
29				col.end.unbound() - col.start.unbound(),
30			)
31		};
32		this.subcols(col.start, ncols)
33	}
34}
35impl<'a, C: Shape, T, Cs: Stride, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>>
36	RowIndex<ColRange> for RowMut<'a, T, C, Cs>
37{
38	type Target = RowMut<'a, T, ColRange::Len<C>, Cs>;
39
40	#[track_caller]
41	#[inline]
42	fn get(this: Self, col: ColRange) -> Self::Target {
43		let col = col.into_range(C::start(), this.ncols().end());
44		assert!(all(col.start <= col.end, col.end <= this.ncols()));
45		let ncols = unsafe {
46			ColRange::Len::<C>::new_unbound(
47				col.end.unbound() - col.start.unbound(),
48			)
49		};
50		this.subcols_mut(col.start, ncols)
51	}
52
53	#[track_caller]
54	#[inline]
55	unsafe fn get_unchecked(this: Self, col: ColRange) -> Self::Target {
56		let col = col.into_range(C::start(), this.ncols().end());
57		debug_assert!(all(col.start <= col.end, col.end <= this.ncols(),));
58		let ncols = unsafe {
59			ColRange::Len::<C>::new_unbound(
60				col.end.unbound() - col.start.unbound(),
61			)
62		};
63		this.subcols_mut(col.start, ncols)
64	}
65}
66macro_rules! idx_impl {
67    ($C:ty $(, $tt:tt)?) => {
68        impl <'a $(, $tt)?, T, Cs : Stride > RowIndex < Idx <$C >> for RowRef <'a, T, $C,
69        Cs > { type Target = &'a T; #[track_caller] #[inline] fn get(this : Self, col :
70        Idx <$C >) -> Self::Target { this.at(col) } #[track_caller] #[inline] unsafe fn
71        get_unchecked(this : Self, col : Idx <$C >) -> Self::Target { this
72        .at_unchecked(col) } } impl <'a $(, $tt)?, T, Cs : Stride > RowIndex < Idx <$C >>
73        for RowMut <'a, T, $C, Cs > { type Target = &'a mut T; #[track_caller] #[inline]
74        fn get(this : Self, col : Idx <$C >) -> Self::Target { this.at_mut(col) }
75        #[track_caller] #[inline] unsafe fn get_unchecked(this : Self, col : Idx <$C >)
76        -> Self::Target { this.at_mut_unchecked(col) } }
77    };
78}
79idx_impl!(usize);
80idx_impl!(Dim <'N >, 'N);