p3_matrix/
strided.rs
1use crate::row_index_mapped::{RowIndexMap, RowIndexMappedView};
2use crate::Matrix;
3
4#[derive(Debug)]
5pub struct VerticallyStridedRowIndexMap {
6 height: usize,
8 stride: usize,
9 offset: usize,
10}
11
12pub type VerticallyStridedMatrixView<Inner> =
13 RowIndexMappedView<VerticallyStridedRowIndexMap, Inner>;
14
15impl VerticallyStridedRowIndexMap {
16 pub fn new_view<T: Send + Sync, Inner: Matrix<T>>(
17 inner: Inner,
18 stride: usize,
19 offset: usize,
20 ) -> VerticallyStridedMatrixView<Inner> {
21 let h = inner.height();
22 let full_strides = h / stride;
23 let remainder = h % stride;
24 let final_stride = offset < remainder;
25 let height = full_strides + final_stride as usize;
26 RowIndexMappedView {
27 index_map: Self {
28 height,
29 stride,
30 offset,
31 },
32 inner,
33 }
34 }
35}
36
37impl RowIndexMap for VerticallyStridedRowIndexMap {
38 fn height(&self) -> usize {
39 self.height
40 }
41 fn map_row_index(&self, r: usize) -> usize {
42 r * self.stride + self.offset
43 }
44}