sarah-ek / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.8k stars 58 forks source link

Clone instead of Copy bound for `faer::Entity`? #144

Open saona-raimundo opened 1 month ago

saona-raimundo commented 1 month ago

Is your feature request related to a problem? Please describe. I had to work on exact solvers for Linear programming. The main problem with linear algebra libraries was that the numbers had to be Copy, but arbitrary precision numbers are usually represented by rationals with a Vec behind, which is not Copy.

Describe the solution you'd like Replacing the Copy bound by a Clone bound.

Describe alternatives you've considered I have no alternative since Rust does not allow to bypass this restriction.

Additional context Although it adds many .clone() in the code, I managed to implement a few routines without the Copy bound. I am not sure how possible it would be to do in faer.

sarah-ek commented 1 month ago

i considered it for a while, but that would require a more elaborate design

the main issue with arbitrary precision numbers is that the precision can vary between elements of the same matrix. for example 1.25 can be represented with a handful of bits, while finer values would need more.

for unary/binary operations, we can just take the max precision of the operands, but for things like sqrt(2.0), faer needs a way to know the precision of the computation, which would require carrying around a "context" type that we can use to perform the operations. this would require a redesign of the Entity trait, and might also make the implementation a lot more verbose unless i figure out a good abstraction for it.

it's something i plan on doing eventually, but it'll take time