dimforge / simba

Set of mathematical traits to facilitate the use of SIMD-based AoSoA (Array of Struct of Array) storage pattern.
Apache License 2.0
290 stars 29 forks source link

Inconsistency between f32 and f64 in convertability to RealField #54

Closed patowen closed 3 months ago

patowen commented 6 months ago

The following function compiles:

fn my_convert<T: simba::scalar::RealField>(value: f64) -> T {
    T::from_subset(&value)
}

However, the following function does not compile (replacing f64 with f32):

fn my_convert<T: simba::scalar::RealField>(value: f32) -> T {
    T::from_subset(&value)
}

The non-compiling function results in error[E0308]: mismatched types with expected `&f64`, found `&f32` as the error message.

When looking for a root cause, I noticed that complex.rs's trait definition for ComplexField has SupersetOf<f64> as one of its trait bounds but not SupersetOf<f32>. If I modify this code myself, I am able to get the f32 version of my_convert to work.

I was able to reproduce this issue in the master branch as of 2024-02-24 (commit 9d95d6df788386d602b058938068a16ca866a0f1)

sebcrozet commented 3 months ago

Fixed by #59