Return type Matrix3 from function

Hello everyone!
I am new to Rust and new to nalgebra as well.

I am having problem with returning the type Matrix3 from a function.

Suppose I have this:

fn calculate( a: f64, b:f64) -> Matrix3 {
    //calculations here
    let m = Matrix3::new(values); 
    return m 
}

I think I might have misunderstood something because I get the following error:

error[E0107] : wrong number of type arguments: expected 1, found 0

Can someone help me?

Hi!

What is the type of values?

The Matrix3::new expects 9 arguments, that is, the 9 components of the 3x3 matrix:

Matrix3::new(1.0, 2.0, 3.0,
             4.0, 5.0, 6.0,
             7.0, 8.0, 9.0)

You will find some examples of construction functions on the user guide.

I think the specific error you got is referring to your return type. Matrix3 has a generic type argument, which is the type of the values that are being stored in it (i.e. f32 or f64). The easiest way to solve this is to just specify this type argument, and since your input values are f64s, Iā€™m assuming you want a Matrix3<f64>, i.e.

fn calculate( a: f64, b:f64) -> Matrix3<f64> {
    //calculations here
    let m = Matrix3::new(values); 
    return m 
}
2 Likes

This is exactly it! Thank you very much!