-
Notifications
You must be signed in to change notification settings - Fork 853
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
Overflow-checking variant of arithmetic scalar kernels #2650
Changes from 4 commits
5a48454
be51743
bd55844
44b9202
f4a02a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ | |||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
use crate::array::{Array, ArrayData, ArrayRef, DictionaryArray, PrimitiveArray}; | ||||||||||||||||||||||||||||||||
use crate::buffer::Buffer; | ||||||||||||||||||||||||||||||||
use crate::datatypes::native_op::ArrowNativeTypeOp; | ||||||||||||||||||||||||||||||||
use crate::datatypes::{ | ||||||||||||||||||||||||||||||||
ArrowNumericType, ArrowPrimitiveType, DataType, Int16Type, Int32Type, Int64Type, | ||||||||||||||||||||||||||||||||
Int8Type, UInt16Type, UInt32Type, UInt64Type, UInt8Type, | ||||||||||||||||||||||||||||||||
|
@@ -83,6 +84,41 @@ where | |||||||||||||||||||||||||||||||
PrimitiveArray::<O>::from(data) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/// A overflow-checking variant of `unary`. | ||||||||||||||||||||||||||||||||
pub(crate) fn unary_checked<I, F, O>( | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting to rename it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought is to align with the method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what you mean to "align with the method Based on these comments, let me try to guess what you are suggesting, are you suggesting to change returning type of I'm okay for the change, but where do you think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the confused comments for your PR. I think the |
||||||||||||||||||||||||||||||||
array: &PrimitiveArray<I>, | ||||||||||||||||||||||||||||||||
op: F, | ||||||||||||||||||||||||||||||||
) -> Result<PrimitiveArray<O>> | ||||||||||||||||||||||||||||||||
where | ||||||||||||||||||||||||||||||||
I: ArrowPrimitiveType, | ||||||||||||||||||||||||||||||||
O: ArrowPrimitiveType, | ||||||||||||||||||||||||||||||||
F: Fn(I::Native) -> Option<O::Native>, | ||||||||||||||||||||||||||||||||
I::Native: ArrowNativeTypeOp, | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? There is a reason that the return type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result of |
||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||
let values = array.values().iter().map(|v| { | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is correct, as it will evaluate for null slots which might have arbitrary values. I think you have to consult the null mask... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #2666 contains a more "correct" version of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will add a null mask yes, but as the operation is fallible it can't be blindly called on slots without first checking those slots aren't null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the default bytes or '0' will be inserted into the null slot. The default value or '0' may cause fail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Got it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The null slot may have any value, not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, good point. I was thought that |
||||||||||||||||||||||||||||||||
let result = op(*v); | ||||||||||||||||||||||||||||||||
if let Some(r) = result { | ||||||||||||||||||||||||||||||||
Ok(r) | ||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||
// Overflow | ||||||||||||||||||||||||||||||||
Err(ArrowError::ComputeError(format!( | ||||||||||||||||||||||||||||||||
"Overflow happened on: {:?}", | ||||||||||||||||||||||||||||||||
*v | ||||||||||||||||||||||||||||||||
))) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
// JUSTIFICATION | ||||||||||||||||||||||||||||||||
// Benefit | ||||||||||||||||||||||||||||||||
// ~60% speedup | ||||||||||||||||||||||||||||||||
// Soundness | ||||||||||||||||||||||||||||||||
// `values` is an iterator with a known size because arrays are sized. | ||||||||||||||||||||||||||||||||
let buffer = unsafe { Buffer::try_from_trusted_len_iter(values) }?; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
let data = into_primitive_array_data::<_, O>(array, buffer); | ||||||||||||||||||||||||||||||||
Ok(PrimitiveArray::<O>::from(data)) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/// A helper function that applies an unary function to a dictionary array with primitive value type. | ||||||||||||||||||||||||||||||||
#[allow(clippy::redundant_closure)] | ||||||||||||||||||||||||||||||||
fn unary_dict<K, F, T>(array: &DictionaryArray<K>, op: F) -> Result<ArrayRef> | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after this https://github.com/apache/arrow-rs/pull/2650/files#r963221429
you can define characteristic error message for this closures