mathnet-numerics icon indicating copy to clipboard operation
mathnet-numerics copied to clipboard

Bug in MathNet.Numerics.Providers.LinearAlgebra.ManagedLinearAlgebraProvider line 758

Open ibasin opened this issue 1 year ago • 1 comments

In the method "public void LUFactor(float[] data, int order, int[] ipiv)", you have in your code:

// Compute multipliers. if (j < order & data[indexjj] != 0.0) { ... }

You are missing the second & in your AND operation - otherwise you are doing a bitwise AND instead of the logical AND which is what you want. In your case it might actually work but it is misleading and error prone. It should be:

// Compute multipliers. if (j < order && data[indexjj] != 0.0) { ... }

Cheers!

Ilya

ibasin avatar Aug 05 '24 18:08 ibasin

This is not a bug. The first is a logical AND operator and the second is a conditional logical AND operator. In principle, using the conditional logical AND will be slightly faster than the logical AND operation as the data[indexjj] != 0.0 evaluation would not be done when j >= order. However, this effect is likely small.

sdpenner avatar Sep 11 '25 17:09 sdpenner