-
Notifications
You must be signed in to change notification settings - Fork 58
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
Towards single parent balls #1367
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1367 +/- ##
==========================================
- Coverage 89.32% 88.42% -0.91%
==========================================
Files 82 88 +6
Lines 30748 34260 +3512
==========================================
+ Hits 27467 30294 +2827
- Misses 3281 3966 +685
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I added the missing types. To change the global precision one can invoke one of the following calls (they all do the same):
I added the The only thing missing is documentation. Any other thoughts @fieker? |
It is useful to have a default global RR with a mutable precision, but just to clarify, it is still possible to create new ArbField instances with their own precision? The latter being useful for library code. |
No, the plan is to have only one In our experience, having different What we will add is the "raw" interface, where one does |
return ARB_DEFAULT_PRECISION[] | ||
end | ||
|
||
function set_precision!(f, ::Type{Balls}, prec::Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about calling this with_precision
instead, matching withenv
?
function set_precision!(f, ::Type{Balls}, prec::Int) | ||
arb_check_precision(prec) | ||
old = precision(Balls) | ||
set_precision!(Balls, prec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this function is not thread safe (I am not sure if other parts of Nemo are thread safe, though it sure would be nice if they were :-) ).
If ARB_DEFAULT_PRECISION
is only used by Julia code, I guess this could be rectified (now or in a future update) by making ARB_DEFAULT_PRECISION
thread local. (E.g. by changing it to a Vector{Int}
, indexed by Threads.threadid()
)
Regarding |
On Sun, Jan 01, 2023 at 11:20:37PM -0800, Max Horn wrote:
@fingolfin commented on this pull request.
> +struct Balls
+end
+
+# arb as in arblib
+const ARB_DEFAULT_PRECISION = Ref{Int}(64)
+
+function set_precision!(::Type{Balls}, n::Int)
+ arb_check_precision(n)
+ ARB_DEFAULT_PRECISION[] = n
+end
+
+function Base.precision(::Type{Balls})
+ return ARB_DEFAULT_PRECISION[]
+end
+
+function set_precision!(f, ::Type{Balls}, prec::Int)
How about calling this `with_precision` instead, matching `withenv`?
Name is, essentially, inherited from julia's setprecision for BigFloat
Does not mean that with_precision might not be better, but setprecision
is Julia's choice
…
--
Reply to this email directly or view it on GitHub:
#1367 (review)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
On Sun, Jan 01, 2023 at 11:28:47PM -0800, Max Horn wrote:
@fingolfin commented on this pull request.
> +# arb as in arblib
+const ARB_DEFAULT_PRECISION = Ref{Int}(64)
+
+function set_precision!(::Type{Balls}, n::Int)
+ arb_check_precision(n)
+ ARB_DEFAULT_PRECISION[] = n
+end
+
+function Base.precision(::Type{Balls})
+ return ARB_DEFAULT_PRECISION[]
+end
+
+function set_precision!(f, ::Type{Balls}, prec::Int)
+ arb_check_precision(prec)
+ old = precision(Balls)
+ set_precision!(Balls, prec)
So this function is not thread safe (I am not sure if other parts of Nemo are thread safe, though it sure would be nice if they were :-) ).
If `ARB_DEFAULT_PRECISION` is only used by Julia code, I guess this could be rectified (now or in a future update) by making `ARB_DEFAULT_PRECISION` thread local. (E.g. by changing it to a `Vector{Int}`, indexed by `Threads.threadid()`)
From the Julia help:
elp?> setprecision
search: setprecision setprecision! set_precision!
setprecision([T=BigFloat,] precision::Int; base=2)
Set the precision (in bits, by default) to be used for T arithmetic. If base
is specified, then the precision is the minimum required to give at least
precision digits in the given base.
│ Warning
│
│ This function is not thread-safe. It will affect code running on
│ all threads, but its behavior is undefined if called concurrently
│ with computations that use the setting.
│ Julia 1.8
│
│ The base keyword requires at least Julia 1.8.
I think the thread safety can be (could be) fixed - eveltually Julia needs to have a sensible model for thread-local stuff
… --
Reply to this email directly or view it on GitHub:
#1367 (review)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
Yes, the name is inherited from julia, although slightly more correct with the underscore. Regarding thread safety, it is slightly more complicated since julia now allows to change the number of threads at runtime. It is also painful since the threads interface changed between julia versions. To have an idea how it is done nowadays, have a look at https://github.com/JuliaLang/julia/blob/master/base/pcre.jl#L34. It is also not clear how performance will be effected, but since there are locks and
OK. I think we will go with the helpful error message. |
OK, next iteration. We keep the old
I don't want to hear any discussions about the names. If they need to be adjusted, it can be done during the "big rename" (@fieker, I could not use This is still breaking, since before we had For this PR I also don't care about coverage, since I just moved things around. |
Sounds good.
…On Sun, 8 Jan 2023, 11:23 Tommy Hofmann, ***@***.***> wrote:
OK, next iteration. We keep the old ArbField/arb, AcbField/acb and call
them "fixed precision ball arithmetic". The new "arbitrary precision ball
arithmetic" is done using the following types:
Parent Element
RealField RealElem
RealMat RealMatSpace
RealPoly RealPolyRing
ComplexField ComplexElem
ComplexMat ComplexMatSpace
ComplexPoly ComplexPolyRing
I don't want to hear any discussions about the names. If they need to be
adjusted, it can be done during the "big rename" ***@***.***
<https://github.com/fieker>, I could not use Real or Complex since this
is already an exported type in julia Base).
This is still breaking, since before we had RealField = ArbField and ComplexField
= AcbField.
For this PR I also don't care about coverage, since I just moved things
around.
—
Reply to this email directly, view it on GitHub
<#1367 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA36CV4FWRYRILMBWUTJKXLWRKIQ3ANCNFSM6AAAAAATH2R2NM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Note that the try/catch and lock are only in the "slow path", which allocates the TLS data the first time it is accessed in any given thread. So they are negligible. I am not saying there won't be an overhead, just that it might not be that bad; we should measure. Although, I don't see an alternative? Unless we are willing to risk crazy threading bugs? |
@tthsqe12 @fieker
At the moment, there is a new type
RealField
and the corresponding elements are calledarb_t
(temporarily). I will rename them toArbField
andarb
later.(There is also
set_precision!(RealField, 1000)
for permanent change of the global precision).We will also add the layer where one can specify the precision directly, e.g.,
z = sin(x, 32)
.Here are some questions:
set_precision
syntax use the an instance ofRealField
orRealField
itself? That is, should it beset_precision(RR, 100)
orset_precision(RealField, 100)
? At the moment I went with the former, but I am happy to change it.roots(f, RealField)
orroots(f, RealField())
.arb
, but it is quite ambiguous in certain functions. For exampleroots(f::fmpz_poly, R::RealField, prec::Int)
. Does that mean that we want the computation done withprec
bits of precision? Or do we want the resulting balls to have a certain radius, e.g,radius(r) <= 2^-prec
? Does anyone have a good name for the second application? We should get away from the term "precision" in this case.TODO
arb
.acb
arb_poly
acb_poly
arb_mat
acb_mat