-
Notifications
You must be signed in to change notification settings - Fork 8
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
Implement MA for Base.Rational #33
Comments
I think it would be great to have efficient implementations for rationals in MA! There were three things that came to mind when I was working on the discourse post that I thought I’d mention here. First, since rationals aren’t actually immutable (but the bigints they hold are), this is just a special case of the general problem of wanting to use MA within library code that wasn’t written for it. I think it’s a worthwhile special case though, since rationals of bigint are the only way I know of getting exact results from many computations and one can easily imagine users using MA with them. But maybe the general problem can be addressed using Cassette to add Secondly, it seems like you can do a fair bit better than just copying Base and adding Or maybe one can even write a fancier version of The third point is related to the word “almost” in the previous paragraph: I found |
One other idea: MA could globally hold some buffers to be used in I think one would need to be a bit careful how they are documented and used to prevent corruption, and would also want to make sure there’s a hard cap on how many buffers are held globally to prevent memory leaks, but that it could make a really simple user API be very performant. edit: as a design idea, this could look like
where Then the I know globals are frowned on as a general rule, but I think it could be done properly with a safe API such as this |
I would do
Yes, that would make sense to add it.
What's tricky is that some types need buffer while other types do not depending on the operation. |
One way to resolve this is to just do things like function MA.add_mul!(x::BigInt, y::BigInt, z::BigInt)
with_buffer(BigInt) do buffer
MA.add_buffered_mul!(buffer, x, y, z)
end
end and never call the buffered functions manually. As long as we can grab buffers from and put them back on the global stack efficiently enough, I think we never really need to manually call the buffered methods. Then the generic things like |
Closed by #104 |
@ericphanson started it in https://discourse.julialang.org/t/memory-consumtion-rational-bigint-on-bernoulli-number-example/33812/7
The text was updated successfully, but these errors were encountered: