While working on a article for doing regression based on "Math::Matrix" I found out that the method inverted uses the (lazy) attribute determinant.
Since determinant can be quite slow, I think that the singularity check with determinant should be replaced with a singularity check while pivoting. For example, the main loop can start with:
for ^$!row-count -> $c {
my $swap_row_nr = $c; # make sure that diagonal element != 0, later == 1
$swap_row_nr++ while $swap_row_nr < $!row-count && @clone[$swap_row_nr][$c] == 0;
fail "Matrix is not invertible, or singular because defect (determinant = 0)" if $swap_row_nr >= $!row-count;
...
While working on a article for doing regression based on "Math::Matrix" I found out that the method
inverteduses the (lazy) attributedeterminant.Since
determinantcan be quite slow, I think that the singularity check withdeterminantshould be replaced with a singularity check while pivoting. For example, the main loop can start with: