Comments (7)
The struct for ArbVector
, AcbVector
and the such should not really depend on how we choose to handle mutability and non-allocation right? What I might do is to start implementing the simpler parts, defining the types and such.
from arblib.jl.
Nice! So this would be an example where indexing does not required allocations right? And then it would be the users responsibility to not use any variables gotten from indexing after the vector is freed.
I have some ideas for how we could do the unsafe indexing in Arblib, I'll write about it in the other issue.
from arblib.jl.
Never mind, I'll just write it here. If we define an ArbVector
as a Ptr{arb_struct}
(plus some metadata) then one way to allow inplace operations would be to rewrite our arbcall
to not only work on Arb
but also on arb_struct
. Then you could work directly on the Ptr{arb_struct}
using the same low-level methods as for Arb
, one issue is that we would not know which precision to use but we could maybe just default to the global precision and if you want something else you have to be explicit about it. I think this would be fine to do for the low-level methods, if you use them you should expect some friction. So you could do something like
v = ArbVector([1, 2, 3])
Arblib.add!(Arblib.unsafe_getindex(v, 1), Arblib.unsafe_getindex(v, 1), 5, prec = precision(v))
It should also work for referencing radius and midpoint
x = Arb(pi)
r = Mag(1e-10)
Arblib.cmp(x.radius, r)
The higher level interface, v[1]
and radius(x)
, could then be written in a safe way with allocations.
from arblib.jl.
unsafe_load
does copy the data, so it's not allocation free.
I just tried
v = [1,2,3]
CC = AcbField(256)
jlv = CC.(v)
arbv = AcbVector(jlv)
unsafe_wrap(Array, arbv.ptr, (3,)) # ← truly non-allocating
but it crashes instantly :D
from arblib.jl.
Okay, so it does allocation for the struct but does not call arb_init
and thus doesn't need to allocate space for the pointers in the struct at least? I hope to have time to experiment a bit more with this in the weekend.
from arblib.jl.
@Joel-Dahne that is correct: unsafe_load
allocates a julia object and copies the corresponding fields to it. However the arblib
s data (the fields are pointing to) are not copied, therefore the result is an unsafe object.
To be precise, this is the correct syntax to add 5
to the first coordinate:
v = ArbVector([1, 2, 3])
GC.@preserve v
Arblib.add!(Arblib.unsafe_getindex(v, 1), Arblib.unsafe_getindex(v, 1), 5, prec = precision(v))
b = Arblib.unsafe_getindex(v, 1)
# do something with b, but never leak it out of @preserve block:
(b > 1 ? true : false)
end
I'm not sure if unsafe_getindex
is the right name here: in julia unsafe_*
means that the arguments need to be checked for validity, but the result is a safe julia object. Here, it's the opposite...
from arblib.jl.
One problem I see if we copy the struct is that some of the data is stored directly in the struct and some of it where the fields are pointing to, which data is stored in the struct also depends on the data. So if we copy the struct and update the fields the original copy might or might not be updated correctly.
from arblib.jl.
Related Issues (20)
- AbstractFloat interface functions HOT 3
- user friendly interface to find_roots! HOT 1
- update Arblib HOT 1
- Cannot set Int128 HOT 1
- non-operability with Nemo arbs HOT 2
- using MutableArithmetic api? HOT 2
- A*A' significantly slower than A*A for ArbMatrices HOT 3
- Arb * ArbMatrix becomes Matrix{Arb} instead of ArbMatrix HOT 2
- How can we enable multi-threaded Flint via Arblib.jl? HOT 2
- Cannot convert BigInt to Arb HOT 4
- Flag for enabling warnings when converting from `AbstractFloat` HOT 13
- Many allocations when calculating hypergeometric functions HOT 3
- update arbcalls HOT 6
- Could you bump the Arb_jll version? HOT 4
- Why Acb is not a subtype of Complex? HOT 3
- Mega-Flint HOT 1
- Towards v1.0 HOT 1
- Enable GitHub page for documentation HOT 3
- Possibly use ScopedValues for precision (and rounding?)
- Arblib.setprecision broken for AcbRefMatrix HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arblib.jl.