kno10 / rust-kmedoids

k-Medoids clustering in Rust with the FasterPAM algorithm
GNU General Public License v3.0
20 stars 3 forks source link

Arbitrary precision distances: could Copy be replaced with Clone? #7

Open sleemans opened 4 months ago

sleemans commented 4 months ago

Thanks for the cool library!

For my use case, I need to work with distances of arbitrary precision. These distances can be so small, that the built-in types of Rust may not suffice. The fasterpam function, to my benefit, requires traits that are mostly compatible with unlimited-precision fraction libraries, such as fraction::BigFraction or num_rational. However, the only exception is the Copy trait, which, if I understand the documentation correctly, indicates that a bitwise copy is possible. I suspect it may not be possible to implement Copy for any arbitrary-precision fraction struct, as such a struct would need some kind of grow-shrink storage, and hence some bookkeeping that would be inherently incompatible with Copy.

Therefore my question: would it be possible to use the Clone trait instead of the Copy trait for the N and L type parameters in the function fasterpam? I'm fairly new to Rust programming, so please forgive me if this is not possible at all.

kno10 commented 4 months ago

We are not Rust experts either, but I do not see why Clone should not be possible, except that it potentially is more expensive and needs to be made explicit. But only a few places should need it, you should give it a try.