-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an overload of equals #43
Comments
Agreed. One can simply use One thing to consider here is that floating point equality will rarely behave as one expects, because numerical issues can cause things that should be equal to be slightly different. Thus it may make sense to admit an optional epsilon be set somewhere similar to assertMatrixEquals, perhaps a new property in options. Alternatively, |
Indeed floating point equality is something that may incur a great level of frustration, especially for people new to floating point arithmetic. However, Kotlin prescribes a fairly strict floating point standard (unlike e.g. C++) and therefore I believe that the user should be able to demand a strict floating point comparison. Therefore I suggest the second option:
|
Numpy has an operation numpy.allclose(a, b, some_epsilon) which returns true if abs(a-b) < eps for all a,b. Unfortunately it's not possible to pass an epsilon value to the equals operator and still have it be overloadable, so @OverRide fun equals(b, epsilon=1e-6) isn't doable, but maybe a static class-level float that can be set in advance and tweaked according to needs? Or, barring that, do something like AdaGrad and takes the magnitude of the global vector and returns true if all values are within 1% of the standard deviation. I'm not as keen on the second approach because it's more computationally expensive AND it doesn't always behave as one might expect. [0, 1, 0] and [0, 1.1, 0] could sometimes turn out to be close. That doesn't seem acceptable to me. Perhaps instead of adding what I think of as a kinda' gross global epsilon we can just add a method called 'allclose' to match Numpy? Or we can default to something like 1e-8 and take that as good enough. |
It sounds like everyone is on board with going the
|
This program:
Produces
false
, because it just compares whethera
andb
refer to the same Kotlin object.It would be very useful to have an overload that would compare matrices in the mathematical sense. That is, two matrices are the same if they have the same dimensions and each element of one matrix is equal to the element in the other matrix in the same column and row.
The text was updated successfully, but these errors were encountered: