diff --git a/lightmotif/src/pli/platform/avx2.rs b/lightmotif/src/pli/platform/avx2.rs index d4ff09fda70e54e12237ea98120fc0ff0c391aef..b8f262cc3056ca5883e310f96c6e312b07c5df16 100644 --- a/lightmotif/src/pli/platform/avx2.rs +++ b/lightmotif/src/pli/platform/avx2.rs @@ -406,6 +406,11 @@ unsafe fn stripe_avx2<A>( let mut matrix = std::mem::take(striped).into_matrix(); matrix.resize(src_stride); + // Early exit if sequence is too empty (no allocated matrix). + if length == 0 { + return; + } + /// Get a pointer to the matrix let mut out = matrix[0].as_mut_ptr(); let out_stride = matrix.stride(); diff --git a/lightmotif/src/seq.rs b/lightmotif/src/seq.rs index 1179a226cceaa0ae933f51cbfb060a65bdda0684..023a1d12b3d1b5392e3f2e6749122b4088ea4c7f 100644 --- a/lightmotif/src/seq.rs +++ b/lightmotif/src/seq.rs @@ -347,6 +347,18 @@ mod test { use crate::abc::Dna; use crate::abc::Nucleotide::*; + #[test] + fn test_empty() { + let seq = EncodedSequence::<Dna>::from_str("").unwrap(); + + let pli = Pipeline::generic(); + let striped = <Pipeline<_, _> as Stripe<Dna, U2>>::stripe(&pli, &seq); + assert_eq!(striped.matrix().rows(), 0); + + let striped = seq.to_striped(); + assert_eq!(striped.matrix().rows(), 0); + } + #[test] fn test_stripe() { let pli = Pipeline::generic();