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

from_fn cannot be used with dimensions from typenum::U* #590

Closed
aplund opened this issue Apr 26, 2019 · 1 comment · Fixed by #820
Closed

from_fn cannot be used with dimensions from typenum::U* #590

aplund opened this issue Apr 26, 2019 · 1 comment · Fixed by #820

Comments

@aplund
Copy link
Contributor

aplund commented Apr 26, 2019

The following code for generating large random complex matrices doesn't seem to work.

extern crate rand;
extern crate typenum;
extern crate nalgebra;

use num::complex::Complex64;
use rand::prelude::*;

fn main() {
    let mut r = rand::thread_rng();
    let c = nalgebra::MatrixMN::<Complex64,typenum::U6,typenum::U1024>::from_fn(
        |_,_| Complex64 { re: r.gen(), im: r.gen() }
        );
    println!("Matrix {}", c);
}

The compiler output is:

error[E0599]: no function or associated item named from_fn found for type nalgebra::Matrix<num::Complex<f64>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, nalgebra::ArrayStorage<num::Complex<f64>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>>> in the current scope
--> src/main.rs:11:73
|
11 | let c = nalgebra::MatrixMN::<Complex64,typenum::U6,typenum::U1024>::from_fn(
| ------------------------------------------------------------^^^^^^^
| |
| function or associated item not found in nalgebra::Matrix<num::Complex<f64>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, nalgebra::ArrayStorage<num::Complex<f64>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>>>
|
= note: the method from_fn exists but the following trait bounds were not satisfied:
nalgebra::DefaultAllocator : nalgebra::allocator::Allocator<num::Complex<f64>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>>
typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0> : nalgebra::DimName

error[E0277]: the trait bound typenum::UTerm: nalgebra::DimName is not satisfied
--> src/main.rs:11:13
|
11 | let c = nalgebra::MatrixMN::<Complex64,typenum::U6,typenum::U1024>::from_fn(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait nalgebra::DimName is not implemented for typenum::UTerm
|
= note: required because of the requirements on the impl of nalgebra::DimName for typenum::UInt<typenum::UTerm, typenum::B1>
= note: required because of the requirements on the impl of nalgebra::DimName for typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>
= note: required because of the requirements on the impl of nalgebra::DimName for typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>
= note: required because of the requirements on the impl of nalgebra::allocator::Allocator<num::Complex<f64>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B1>, typenum::B0>, typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UInt<typenum::UTerm, typenum::B1>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>, typenum::B0>> for nalgebra::DefaultAllocator

error: aborting due to 2 previous errors

Some errors occurred: E0277, E0599.
For more information about an error, try rustc --explain E0277.
error: Could not compile complex.

To learn more, run the command again with --verbose.

@sebcrozet
Copy link
Member

sebcrozet commented Apr 26, 2019

Hi! For static dimensions up to 127 (included), you need to use the nalgebra type-level const: nalgebra::MatrixMN::<Complex64, nalgebra::U6, typenum::U1024>::from_fn(

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

Successfully merging a pull request may close this issue.

2 participants