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

add support for f16 #888

Merged
merged 1 commit into from
Nov 29, 2021
Merged

add support for f16 #888

merged 1 commit into from
Nov 29, 2021

Conversation

jimexist
Copy link
Member

@jimexist jimexist commented Oct 31, 2021

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 use half crate to implement f16

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 31, 2021
@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2021

Codecov Report

Merging #888 (3845a11) into master (898924f) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
arrow/src/alloc/types.rs 0.00% <0.00%> (ø)
arrow/src/array/array.rs 83.13% <0.00%> (-0.25%) ⬇️
arrow/src/array/data.rs 72.92% <0.00%> (-1.20%) ⬇️
arrow/src/array/equal/mod.rs 93.13% <0.00%> (-0.33%) ⬇️
arrow/src/array/transform/mod.rs 85.16% <0.00%> (-0.36%) ⬇️
arrow/src/datatypes/native.rs 72.91% <0.00%> (-1.56%) ⬇️
arrow/src/datatypes/types.rs 88.88% <ø> (ø)
arrow/src/json/reader.rs 83.75% <ø> (+0.05%) ⬆️
arrow/src/util/data_gen.rs 77.57% <0.00%> (+0.46%) ⬆️
arrow/src/datatypes/datatype.rs 65.36% <0.00%> (-0.44%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 898924f...3845a11. Read the comment docs.

@@ -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);
Copy link
Member Author

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

@jimexist jimexist force-pushed the add-support-f16 branch 7 times, most recently from 4b9ff7c to daade70 Compare November 3, 2021 06:52
Copy link
Contributor

@alamb alamb left a 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

@@ -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")]
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same question applies below

}
#[cfg(not(feature = "f16"))]
{
unimplemented!()
Copy link
Member

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

@jimexist
Copy link
Member Author

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

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.

are you saying that we should allow for runtime error rather than compile time failures?

@jimexist jimexist force-pushed the add-support-f16 branch 2 times, most recently from bb744df to f46b312 Compare November 20, 2021 16:26
@jimexist jimexist requested a review from alamb November 20, 2021 16:26
@jimexist jimexist force-pushed the add-support-f16 branch 3 times, most recently from 61133b7 to 312b9c5 Compare November 21, 2021 06:50
Copy link
Contributor

@alamb alamb left a 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?

@jimexist
Copy link
Member Author

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?

@@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor

@alamb alamb left a 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

@jimexist
Copy link
Member Author

can I possibly get another stamp on this? I guess introducing half isn't going to be obviously all upside

@jimexist jimexist requested a review from alamb November 23, 2021 15:56
Copy link
Contributor

@alamb alamb left a 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)

@jimexist jimexist merged commit f6908bf into apache:master Nov 29, 2021
@jimexist
Copy link
Member Author

@alamb with no further reviews and concerns i have merged this pull request

@jimexist jimexist deleted the add-support-f16 branch November 29, 2021 13:08
@alamb
Copy link
Contributor

alamb commented Nov 29, 2021

Nice work @jimexist 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for half precision floats (f16)
4 participants