-
Notifications
You must be signed in to change notification settings - Fork 135
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 traits for generic norms and distances. #121
Comments
It's a reasonable idea. Can you open it as a PR for discussion? One thing to consider is that there are multiple possible definitions of norm, especially when more dimensions are added like in |
Are you sure that it must be the responsibility of num-traits? The problem is not even that num-traits may end up becoming too of a heavy dependency in attempts to fit all needs but that num-traits' purpose statement ("Numeric traits for generic mathematics in Rust"), would, in this case, become unclear to me and, perhaps, someone else. |
Not at all. If there are interested parties like yourself who want to explore this in a new crate (and not get bogged down in |
In many iterative numerical algorithms, one has to calculate the distance between a solution candidate and a reference value in order to check for convergence. But currently there is no trait which would enable the computation of such a distance generically.
There is
Signed
which provides anabs
function, but this trait can only be implemented for types with a notion of signedness. The correct mathematical concept, however, are norms and metrics, with the latter being reasonable for basically any numeric type.So I propose adding two traits,
Norm
andDistance
, each with one method of the same name. Thenorm
-function of theNorm
trait returns the norm of a single value, thedistance
-function of theDistance
trait returns the distance between two values.In my branch dist I have written a draft of these traits and implemented them for the primitive numeric types.
The text was updated successfully, but these errors were encountered: