Skip to content

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

@aplund

Description

@aplund

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions