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

Trait bounds were not satisfied with nalgebra #99

Closed
chen-qingyu opened this issue Jan 17, 2024 · 2 comments
Closed

Trait bounds were not satisfied with nalgebra #99

chen-qingyu opened this issue Jan 17, 2024 · 2 comments

Comments

@chen-qingyu
Copy link

When I want to use Fraction in nalgebra (a linear algebra library), there are some traits that do not meet the requirements:

fn main() {
    type Fraction = fraction::Fraction;
    type Matrix = nalgebra::Matrix2<Fraction>;

    let a = Matrix::new(
        Fraction::from(1),
        Fraction::from(2),
        Fraction::from(3),
        Fraction::from(4),
    );

    println!("{:.3}", a.try_inverse().unwrap());
}

Error message:

  --> src\main.rs:15:25
   |
15 |     println!("{:.3}", a.try_inverse().unwrap());
   |                         ^^^^^^^^^^^ method cannot be called due to unsatisfied trait bounds
53 | pub enum GenericFraction<T>
   | ---------------------------
   | |
   | doesn't satisfy `<_ as SimdValue>::Element = GenericFraction<u64>`
   | doesn't satisfy `<_ as SimdValue>::SimdBool = bool`
   | doesn't satisfy `GenericFraction<u64>: ComplexField`
   | doesn't satisfy `GenericFraction<u64>: Field`
   | doesn't satisfy `GenericFraction<u64>: FromPrimitive`
   | doesn't satisfy `GenericFraction<u64>: SimdValue`
   | doesn't satisfy `_: SubsetOf<GenericFraction<u64>>`
   | doesn't satisfy `_: SupersetOf<f64>`
   |
   = note: the following trait bounds were not satisfied:
           `GenericFraction<u64>: ComplexField`
           `<GenericFraction<u64> as SimdValue>::SimdBool = bool`
           which is required by `GenericFraction<u64>: ComplexField`
           `<GenericFraction<u64> as SimdValue>::Element = GenericFraction<u64>`
           which is required by `GenericFraction<u64>: ComplexField`
           `GenericFraction<u64>: Field`
           which is required by `GenericFraction<u64>: ComplexField`
           `GenericFraction<u64>: SimdValue`
           which is required by `GenericFraction<u64>: ComplexField`
           `GenericFraction<u64>: FromPrimitive`
           which is required by `GenericFraction<u64>: ComplexField`
           `GenericFraction<u64>: simba::scalar::subset::SupersetOf<f64>`
           which is required by `GenericFraction<u64>: ComplexField`
           `GenericFraction<u64>: simba::scalar::subset::SubsetOf<GenericFraction<u64>>`
           which is required by `GenericFraction<u64>: ComplexField`

Is there any way to solve this problem?

@dnsl48
Copy link
Owner

dnsl48 commented Jan 19, 2024

Hi @chen-qingyu, sorry to hear you have some troubles.
Unfortunately, it doesn't look like this would work, as nalgebra has a bunch of its own traits that it implements for most of the primitive types. Given that, Fraction is not among those implementations and also does not have integration with nalgebra at this stage.

I am not saying the integration between the two projects would not be possible.
However, it is not implemented at the moment and won't work out of the box without you providing those missing trait implementations.

@chen-qingyu
Copy link
Author

Thank you for your reply.

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

No branches or pull requests

2 participants