sarah-ek / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.75k stars 56 forks source link

Add a "ones" method for initializing a matrix filled with ones. #125

Closed pleepleus closed 2 months ago

pleepleus commented 2 months ago

Is your feature request related to a problem? Please describe. This is a QOL feature to make it simple to create a matrix that is filled with the same value. So you want to create a 10 x 10 matrix filled with the value 5. This feature would allow one to write:

let a = scale(5.0) * Mat::<f64>::ones(10, 10);

Rather than:

let a =Mat::<f64>::from_fn(10, 10, |_, _| 5.0)

Or

let mut a = Mat::<f64>::zeros(10, 10);
a.fill(5.0);

Describe the solution you'd like A new matrix creation method called "ones" which creates a matrix of specified dimensions filled with ones.

Describe alternatives you've considered This is a QOL feature. There are certainly options to do the same thing outlined above.

Additional context N/A

pleepleus commented 2 months ago

To be consistent with numpy, we could also add a method called "full" which does this without the need for the additional multiplication.

sarah-ek commented 2 months ago

merged in #126