2008/7/13 Nikolay Sivov bunglehead@gmail.com:
What do you think about matrix comparison or in general float comparison implementation? What is the best way to implement this. We have two cases now:
- GdipIsMatrixEqual which compares two matrices (with simple bitwise
operation now)
Is this the way it works on Windows? You have 4 basic cases: a. exactly equal; b. equal + epsilon for rounding/representation errors; c. equal - epsilon for rounding/representation errors; d. not equal.
The code at the moment covers a and d (is there a test for d?), but what about b and c? These would be useful, because if the Windows version of GdipIsMatrixEqual *is* catering for error of a given epsilon, then you can use that function for validation. If not, you have tests that prove that Windows is using a simplistic comparison method.
- GdipIsMatrixInvertible which contains a check for 'not above zero'
determinant.
It has been a while since I have done any matrix math. I'll assume that the above is the correct definition/check for invertible (makes sense because you have inv(a(ij)) = a(ij)/det(A), so can't have det(A) == 0).
Now here, you have several 'classes' of matrices w.r.t. whether they are invertible or not: a. det(A) > 0 b. det(A) == 0 c. det(A) < 0
So does Windows match your assumption for the answer to these (a ==> yes; b, c ==> no).
I think first of all we should choose an appropriate method to do so and only after that try to compare results with native. What do you think of that?
Are you saying that GdipIsMatrixInvertible should be used for comparison of two matrices? If so, you can have two different matrices that are invertible, so it does not make sense.
A good first step would be to print out the expected and returned values for the matrices, and keep the GdipIsMatrixEqual check. This will allow you to determine if the reason this is failing is due to rounding errors, or that they are completely different results.
- Reece