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

Remove duplicate bound check in function shift #1408

Closed
HaoYang670 opened this issue Mar 8, 2022 · 0 comments · Fixed by #1409
Closed

Remove duplicate bound check in function shift #1408

HaoYang670 opened this issue Mar 8, 2022 · 0 comments · Fixed by #1409
Labels
enhancement Any new improvement worthy of a entry in the changelog

Comments

@HaoYang670
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
https://github.com/apache/arrow-rs/blob/master/arrow%2Fsrc%2Fcompute%2Fkernels%2Fwindow.rs#L61-L66

    if offset == 0 {
        Ok(make_array(array.data_ref().clone()))
    } else if offset == i64::MIN || abs(offset) >= value_len {
        Ok(new_null_array(array.data_type(), array.len()))
    } else {
        let slice_offset = clamp(-offset, 0, value_len) as usize;
        ...

When calculate slice_offset, we don't need to compare -offset with value_len, because we have checked abs(offset) >= value_len before.

Describe the solution you'd like
slice_offset should be 0 when offset > 0 (shift left) and -offset when offset < 0 (shift right). Maybe we can use clamp_min

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@HaoYang670 HaoYang670 added the enhancement Any new improvement worthy of a entry in the changelog label Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant