Open 8d1h opened 3 years ago
So I am just now adding ZZi and QQi and will add more of these ! operations for ZZ (fmpz) and QQ (fmpq) in the process. AbstractAlgebra has fallbacks for add! and addeq!, but in general the usage of ! in generic code is a mess.
let me also mention issue Nemocas/AbstractAlgebra.jl#1000
Hi!
I recently discovered that inplace operators can save a lot of memory allocations and in certain cases vastly improve performance.
However many inplace operators from FLINT are not yet wrapped in Nemo or only wrapped as non-inplace (here I'm mainly talking about
fmpz
andfmpq
, haven't looked at other types yet).Also some operators for example
fmpq_add
are wrapped multiple times aswhile certain ad hoc operators are not defined at all and hence fallback to generic implementations
I purpose to systematically wrap all such operators as "unsafe" and base the safe ones on them. So for
fmpq_add
this isThis way we can make all the inplace/"unsafe" operators available should one need to use them, and it's also easier to keep track of the ones that are already wrapped. And similarly ad hoc operators like
+(a::fmpq, b::Int)
should beadd!(fmpq(), a, b)
whereadd!
wrapsfmpq_add_si
.Also maybe some general interface could be implemented like
and then one can define macros like
@! a += b
that expands intoa = addeq!(a, b)
to preserve the readability of the code.