Skip to content

Commit

Permalink
Allow float fill values to be created from int fill value metadata.
Browse files Browse the repository at this point in the history
The cast is lossy.
  • Loading branch information
LDeakin committed Apr 26, 2024
1 parent c1f4033 commit d475b01
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Allow float fill values to be created from int fill value metadata

### Fixed
- Fix `compute_encoded_size()` for `BitroundCodec` incorrectly indicating various data types were unsupported

Expand Down
22 changes: 22 additions & 0 deletions src/array/fill_value_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ impl FillValueMetadata {
#[must_use]
pub fn try_as_float<T: FloatCore>(&self) -> Option<T> {
match self {
Self::Int(int) => num::traits::cast(*int),
Self::UInt(uint) => num::traits::cast(*uint),
Self::Float(float) => {
use FillValueFloat as F;
match float {
Expand Down Expand Up @@ -259,6 +261,16 @@ impl FillValueMetadata {
#[must_use]
pub fn try_as_float16(&self) -> Option<f16> {
match self {
Self::Int(int) =>
{
#[allow(clippy::cast_precision_loss)]
Some(f16::from_f64(*int as f64))
}
Self::UInt(uint) =>
{
#[allow(clippy::cast_precision_loss)]
Some(f16::from_f64(*uint as f64))
}
Self::Float(float) => {
use FillValueFloat as F;
match float {
Expand Down Expand Up @@ -287,6 +299,16 @@ impl FillValueMetadata {
#[must_use]
pub fn try_as_bfloat16(&self) -> Option<bf16> {
match self {
Self::Int(int) =>
{
#[allow(clippy::cast_precision_loss)]
Some(bf16::from_f64(*int as f64))
}
Self::UInt(uint) =>
{
#[allow(clippy::cast_precision_loss)]
Some(bf16::from_f64(*uint as f64))
}
Self::Float(float) => {
use FillValueFloat as F;
match float {
Expand Down

0 comments on commit d475b01

Please sign in to comment.