.mean() on ArrayView1<u64>: panicked at 'attempt to add with overflow'
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 42/100
Piste de recherche
Start by running the provided Rust example and inspect the ndarray implementations of mean() and sum(), since the report identifies their likely interaction. Determine how mean should behave when summing u64 values beyond that type's range, then verify that the reproduction no longer panics and still returns the expected mean.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
I wanted to calculate a mean over an ArrayView1<u64> with 1000 values and encounter a panic:
thread 'main' panicked at 'attempt to add with overflow', /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/ops/arith.rs:107:1
Is this intended? Or should the u64 values internally be casted to u128 when calculating the mean?
The following code reproduces the error:
use ndarray::*;
fn main() {
let mut data_vec: Vec<u64> = Vec::new();
for _ in 1..1000 {
data_vec.push(132542363533234561)
}
let data = data_vec.as_slice();
let view: ArrayView1<u64> = ArrayView1::from_shape(data.len(), data).unwrap();
println!("{:?}", view.mean());
}
I think the reason for this error is that mean() uses the public sum() function, which panics if the result does not fit into the element type. However, the mean result should always fit into the element type, so mean() maybe shouldn't use the public sum() function.
- Langage dominant
- Rust
- Étoiles
- 4.3k
- Forks
- 391
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rust-ndarray/ndarray
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
rust-ndarray/ndarray#1612 · 1 commentaire ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
rust-ndarray/ndarray#1617 · 1 commentaire ·
-
Stack overflow in `triu` Ouvertebug good first issue
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
rust-ndarray/ndarray#1615 · 1 commentaire ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
rust-ndarray/ndarray#1610 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
rust-ndarray/ndarray#1609 ·
Toutes les issues de rust-ndarray/ndarray
Issues similaires
-
risk:low runtime status:in-progress type:test
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
EricSpencer00/Resilient#4835 · 1 commentaire ·
-
agent:ready documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
cesarferreira/stax#890 ·
-
bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100