Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions vortex-compute/src/lane_kernels/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
/// reads carry no inter-iteration data dependency — the autovectorizer treats each
/// lane independently.
pub trait IndexedSource {
/// The per-lane item type. Must be `Copy` so the kernels can pass it through
/// the closure by value without extra moves.
type Item: Copy;
/// The per-lane item type passed through the kernel by value.
type Item;
/// Logical lane count.
fn len(&self) -> usize;
/// Returns true when there are no lanes.
Expand Down Expand Up @@ -55,10 +54,10 @@ impl<T: Copy> IndexedSource for &mut [T] {

/// Pair of two [`IndexedSource`]s of equal length. Yields `(A::Item, B::Item)` per lane.
///
/// Use this to drive a binary kernel from two columns. Length equality is enforced
/// at construction.
/// Use this to drive a binary kernel from two columns. Length equality is enforced at
/// construction, and the private fields prevent callers from bypassing that check.
#[derive(Clone, Copy)]
pub struct LaneZip<A, B>(pub A, pub B);
pub struct LaneZip<A, B>(A, B);

impl<A: IndexedSource, B: IndexedSource> LaneZip<A, B> {
/// Build a `LaneZip` from two equal-length sources.
Expand All @@ -80,7 +79,6 @@ impl<A: IndexedSource, B: IndexedSource> IndexedSource for LaneZip<A, B> {
type Item = (A::Item, B::Item);
#[inline]
fn len(&self) -> usize {
debug_assert_eq!(self.0.len(), self.1.len());
self.0.len()
}
#[inline]
Expand All @@ -89,3 +87,14 @@ impl<A: IndexedSource, B: IndexedSource> IndexedSource for LaneZip<A, B> {
unsafe { (self.0.get_unchecked(i), self.1.get_unchecked(i)) }
}
}

#[cfg(test)]
mod tests {
use super::LaneZip;

#[test]
#[should_panic(expected = "LaneZip operands must have the same length")]
fn rejects_mismatched_lengths() {
_ = LaneZip::new(&[1_u8][..], &[2_u8, 3][..]);
}
}
Loading