Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip FoR decompression if min and scalar are 0 #1618

Merged
merged 3 commits into from
Dec 9, 2024
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
28 changes: 18 additions & 10 deletions encodings/fastlanes/src/for/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ pub fn decompress(array: FoRArray) -> VortexResult<PrimitiveArray> {
.as_primitive()
.typed_value::<$T>()
.ok_or_else(|| vortex_err!("expected reference to be non-null"))?;
PrimitiveArray::from_vec(
decompress_primitive(encoded.into_maybe_null_slice::<$T>(), min, shift),
validity,
)
if min == 0 && shift == 0 {
encoded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to cast? (real question)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this context we know that min is T so I think compiler will cast 0 to T implicitly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no, I mean cast encoded... is it the right dtype/ptype? since FoR converts to unsigned

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast happens above when we extract the encoded array

} else {
PrimitiveArray::from_vec(
decompress_primitive(encoded.into_maybe_null_slice::<$T>(), min, shift),
validity,
)
}
}
}))
}
Expand All @@ -130,15 +134,19 @@ fn decompress_primitive<T: NativePType + WrappingAdd + PrimInt>(
shift: usize,
) -> Vec<T> {
if shift > 0 {
values
.into_iter()
.map(|v| v << shift)
.map(|v| v.wrapping_add(&min))
.collect_vec()
if min == T::zero() {
values.into_iter().map(move |v| v << shift).collect_vec()
} else {
values
.into_iter()
.map(move |v| v << shift)
.map(move |v| v.wrapping_add(&min))
.collect_vec()
}
} else {
values
.into_iter()
.map(|v| v.wrapping_add(&min))
.map(move |v| v.wrapping_add(&min))
.collect_vec()
}
}
Expand Down
Loading