Two questions about DMatrix


#1

Hello!

I wonder what is the best way to:

  1. initialize a new DMatrix with all zeros, I used DMatrix::from_element(theta_axis_size as usize, rho_axis_size as usize, 0) but maybe there is a way with the Zero trait that I couldn’t find from the source code
  2. find the max/min element of a DMatrix? Currently i get the data as vector and then use iter().min() but maybe there is another way how the library allows for that

Thanks!


#2

Hi !

Your guesses are both correct.

  1. initialize a new DMatrix with all zeros, I used DMatrix::from_element(theta_axis_size as usize, rho_axis_size as usize, 0) but maybe there is a way with the Zero trait that I couldn’t find from the source code

The Zero trait cannot be used for dynamically-sized matrices because there would be no way to specify its size (Zero::zero() takes zero arguments). So you have to use ::from_element indeed.

  1. find the max/min element of a DMatrix? Currently i get the data as vector and then use iter().min() but maybe there is another way how the library allows for that

There is no dedicated method for that. But this seems to be a common operation so maybe we could add one in future versions of nalgebra !