ArbNumerics.jl icon indicating copy to clipboard operation
ArbNumerics.jl copied to clipboard

specialized arithmetic and in-place functions

Open kalmarek opened this issue 4 years ago • 8 comments

by doing promote stuff simple arithmetic allocates a lot:

julia> z = ArbComplex(2)
2.0 + 0im

julia> @time z+1;
  0.000023 seconds (11 allocations: 600 bytes)

by exploiting arbs acb_add_si this can be cut to

julia> @time z+1;
  0.000010 seconds (5 allocations: 272 bytes)

Mutable arithmetic/ funcions

I'd like to see three-argument arithmetic (along the lines of mul!(out, x, y)). (related: #6)

For all the functions wrapped through @eval (ex. most of elementary.jl) we could easily expose the two argument versions

f!(out, args...) = ... #ccall to arb
function f(args...)
    res = ... #allocate the result;
    f!(res, args...)
    return res
end

Again, this for the purpose of writing more functions and cutting on the allocations/time (especially handy when evaluating the integrand)

will you accept such changes?

kalmarek avatar Dec 31 '19 10:12 kalmarek

probably

Jeffrey Sarnoff

On Dec 31, 2019, at 5:51 AM, kalmarek [email protected] wrote:

by doing promote stuff simple arithmetic allocates a lot:

julia> z = ArbComplex(2) 2.0 + 0im

julia> @time z+1; 0.000023 seconds (11 allocations: 600 bytes) by exploiting arbs acb_add_si this can be cut to

julia> @time z+1; 0.000010 seconds (5 allocations: 272 bytes) Mutable arithmetic/ funcions

I'd like to see three-argument arithmetic (along the lines of mul!(out, x, y)). (related: #6)

For all the functions wrapped through @eval (ex. most of elementary.jl) we could easily expose the two argument versions

f!(out, args...) = ... #ccall to arb function f(args...) res = ... #allocate the result; f!(res, args...) return res end Again, this for the purpose of writing more functions and cutting on the allocations/time (especially handy when evaluating the integrand)

will you accept such changes?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

JeffreySarnoff avatar Dec 31 '19 13:12 JeffreySarnoff

to the first part, those would have to be dispatch specializations .. and to have them foreach of our types and with either ordering of args; we still need the promote versions.

Jeffrey Sarnoff

On Dec 31, 2019, at 5:51 AM, kalmarek [email protected] wrote:

by doing promote stuff simple arithmetic allocates a lot:

julia> z = ArbComplex(2) 2.0 + 0im

julia> @time z+1; 0.000023 seconds (11 allocations: 600 bytes) by exploiting arbs acb_add_si this can be cut to

julia> @time z+1; 0.000010 seconds (5 allocations: 272 bytes) Mutable arithmetic/ funcions

I'd like to see three-argument arithmetic (along the lines of mul!(out, x, y)). (related: #6)

For all the functions wrapped through @eval (ex. most of elementary.jl) we could easily expose the two argument versions

f!(out, args...) = ... #ccall to arb function f(args...) res = ... #allocate the result; f!(res, args...) return res end Again, this for the purpose of writing more functions and cutting on the allocations/time (especially handy when evaluating the integrand)

will you accept such changes?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

JeffreySarnoff avatar Dec 31 '19 13:12 JeffreySarnoff

yes, I by no means intend to replace promote versions; These are supposed to be the fast-track paths for Arb & Int arithmetic

kalmarek avatar Jan 01 '20 22:01 kalmarek

do you know why arb has arf_mul in its docs, but the library does not export the symbol??

kalmarek avatar Jan 01 '20 22:01 kalmarek

(just getting back into the game -- will ask)

JeffreySarnoff avatar Jan 05 '20 14:01 JeffreySarnoff

and I will accept this as a PR

JeffreySarnoff avatar Jan 05 '20 14:01 JeffreySarnoff

arf_mul is a macro https://github.com/fredrik-johansson/arb/blob/038c3a3e0152840b311f82926855688b3a9dadfd/arf.h#L910 I've added a work-around

kalmarek avatar Jan 06 '20 15:01 kalmarek

Yes, now I remember that. Good to have the work around. Please post that itself too.

JeffreySarnoff avatar Jan 06 '20 15:01 JeffreySarnoff