Casting Float64 to Float16 rounds twice through f32
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 20/100
Direzione di ricerca
Start at arrow_cast::cast and trace the Float64 to Float16 path through num_cast and the half crate conversion described in the issue. The reproduction gives a precise failing value and expected result; use it to check the conversion path and add a regression test alongside the existing cast tests. Done means the value rounds to 1.0009766 directly from f64; issue #12476 already has an open pull request.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
cast from Float64 to Float16 goes through num_cast, and the half crate's NumCast for f16 converts with to_f32().map(f16::from_f32). That rounds to f32 first and then to f16. A value just above an f16 midpoint can land exactly on the midpoint in f32, and round-half-even then picks the lower neighbour.
To Reproduce
use arrow_array::{Float64Array, cast::AsArray, types::Float16Type};
use arrow_cast::cast;
use arrow_schema::DataType;
let x = 1.0 + 2f64.powi(-11) + 2f64.powi(-40);
let out = cast(&Float64Array::from(vec![x]), &DataType::Float16).unwrap();
println!("{}", out.as_primitive::<Float16Type>().value(0)); // 1
Expected behavior
The nearest f16, 1.0009766 (1 + 2^-10). x is above 1 + 2^-11, the midpoint between 1.0 and 1 + 2^-10, so it should round up.
Additional context
Switching to f16::from_f64 is not enough on its own: on x86 with F16C, half also implements it as f64 as f32 followed by the hardware f32 to f16 conversion, so it rounds twice there too.
Integer casts to Float16 also go through f32, but they are not affected: every integer in f16's range is exact in f32.
Willingness to contribute
I plan to contribute a fix for this bug independently
- Lingua principale
- Rust
- Stelle
- 3.7k
- Fork
- 1.5k
- Merge medio
- 2g 16h
- PR unite (30g)
- 183
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/arrow-rs
-
parquet: `ArrowWriter::try_new` panics on a schema with a Union field instead of returning an errorAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
`RunArray::try_new` rejects run ends whose null buffer has no nullsForse già presa @Surajsuthar l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/arrow-rs#12427 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Variant] `variant_get` string and binary cast errors show Rust builder type namesForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/arrow-rs
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousApertamaintainer-needed p2 remote triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#4605 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno