-
Notifications
You must be signed in to change notification settings - Fork 784
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
add support for f16 #888
add support for f16 #888
Conversation
d584029
to
2e89d6a
Compare
Codecov Report
@@ Coverage Diff @@
## master #888 +/- ##
==========================================
- Coverage 82.45% 82.42% -0.03%
==========================================
Files 168 168
Lines 48231 48244 +13
==========================================
Hits 39767 39767
- Misses 8464 8477 +13
Continue to review full report at Codecov.
|
arrow/src/datatypes/numeric.rs
Outdated
@@ -333,6 +335,8 @@ make_numeric_type!(UInt8Type, u8, u8x64, m8x64); | |||
make_numeric_type!(UInt16Type, u16, u16x32, m16x32); | |||
make_numeric_type!(UInt32Type, u32, u32x16, m32x16); | |||
make_numeric_type!(UInt64Type, u64, u64x8, m64x8); | |||
#[cfg(feature = "f16")] | |||
make_numeric_type!(Float16Type, f16, f16x32, m16x32); |
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.
I wish there were support for this but apparently there isn't
4b9ff7c
to
daade70
Compare
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.
Looks pretty cool to me. I am not sure how widely used the Float16
type is but seems like a reasonable feature to add
I think it would be good to add some basic tests for Float16Array
(like, for example, creating it from an iterator) as well as an example as a doc comment).
I also was wondering if there was some way to avoid the sprinkled #[cfg(feature = "f16")]
throughout the code (for example, can we possible always define Float16Array
even if the f16
type is not defined, but provide some implementation that always errors when it is constructed.
Then we could have one or two #[cfg(feature = "f16")]
checks rather than them throughout the code
arrow/src/json/reader.rs
Outdated
@@ -1015,7 +1015,15 @@ impl Decoder { | |||
DataType::UInt32 => self.read_primitive_list_values::<UInt32Type>(rows), | |||
DataType::UInt64 => self.read_primitive_list_values::<UInt64Type>(rows), | |||
DataType::Float16 => { | |||
return Err(ArrowError::JsonError("Float16 not supported".to_string())) | |||
#[cfg(feature = "f16")] |
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.
this seems redundant -- both branches do the same thing. Was this an oversight? Or perhaps just a future TODO that will be clearer when separated like this?
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.
Same question applies below
arrow/src/array/data.rs
Outdated
} | ||
#[cfg(not(feature = "f16"))] | ||
{ | ||
unimplemented!() |
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.
unimplemented!("Float16 datatype not supported")
as in the other places
daade70
to
90120d6
Compare
are you saying that we should allow for runtime error rather than compile time failures? |
bb744df
to
f46b312
Compare
61133b7
to
312b9c5
Compare
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.
Looks pretty cool to me -- thanks @jimexist
One major questions for other reviewers: Are we ok with adding a new dependency (on half
?) -- in the IOx project, it turns out we already have half
because serde_cbor
depends on it, because criterion depends on it
🤷
I think some basic tests are in order -- perhaps a doctest showing how to construct an F16Array
perhaps?
do you mean this: https://github.com/apache/arrow-rs/pull/888/files#diff-dd779d74625591eb0e2a5648a76db5b714f4135ee094afd77e87a584f9f264fbR199? |
312b9c5
to
e51c1d9
Compare
e51c1d9
to
1dced1c
Compare
@@ -192,6 +192,14 @@ pub type UInt64Array = PrimitiveArray<UInt64Type>; | |||
/// | |||
/// # Example: Using `collect` | |||
/// ``` | |||
/// # use arrow::array::Float16Array; | |||
/// use half::f16; | |||
/// let arr : Float16Array = [Some(f16::from_f64(1.0)), Some(f16::from_f64(2.0))].into_iter().collect(); |
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.
❤️
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.
Looks good -- thanks @jimexist
can I possibly get another stamp on this? I guess introducing |
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.
Sorry -- I meant to approve this earlier. I think half is ok (as it is a transitive dependency for criterion)
@alamb with no further reviews and concerns i have merged this pull request |
Nice work @jimexist 👍 |
Which issue does this PR close?
Closes #890
Rationale for this change
float16 was not properly supported
What changes are included in this PR?
include optional feature
f16
to usehalf
crate to implement f16Are there any user-facing changes?