Use AlmostEqual() as default EqualityComparer?

I am using a lot of Matrix<double> / Vector<double> structures, and need to deal with the idiosyncrasies of floating point calculations. Is there a way to use any of the AlmostEqual() methods as the default EqualityComparer and/or Comparable functionality for Math.NET Matrices/Vectors?

In C#, you may have some control. I don’t know about other languages.

In order to compare objects in C#, they have to be defined with the IComparable interface. See explanation and example here. Since you are coding the comparison function, I don’t see any reason that you couldn’t write it using any of the functions in MathNet.Numerics.Precision including AlmostEqual().

As I understand it, you would have to define Classes as wrappers around the Matrix and Vector types as the “car” Class wraps around the string and integer classes at the link above.

1 Like