-
Notifications
You must be signed in to change notification settings - Fork 16
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
integration #32
Comments
Anything not imported from the Arb C Library is likely not to work. Provision of additional functionality requires deep integration with the extant design. Just providing a julia-side struct to go along with the C constructs and using that with calls to the library certainly will segfault. While ArbNumerics does rely on some technology that Nemo has refined, it is not intended to be just like Nemo (there would be no need for both). That said, I am happy to consider your issue a request to introduce an Arb driven integration facility. It will take me some time to see what is really involved. Every structured type that does not yet exist in ArbNumerics usually involves a fair amount of work; and when there is interplay .. representing a mathematical expression to integrate and providing for Arb's integration .. it is nontrivial at best. For a glimpse, see (for example) #27 and #30 |
thanks for the quick answer; I'm happy to work-out a PR with this functionality. As far as I understand |
I do not know anything about Arb's internal representation of functions or how best to provide a Julia perspective thereupon [I have not looked at that at all]. There are some very good Julia packages or parts of packages that work with math expressions, and one of them probably is appropriate for this use. Getting that and the Arb C side to The greatest efforts in developing ArbNumerics have been to become free of the Arb C Library manner of working and to find appropriate and much more naturally Julia ways to proceed. The greatest time in developing ArbNumerics has been to make it so anything that works for an As questions arise, do ask -- preferably with some context, and I will attempt to be of help. |
By binary compatibility I meant if Ok, so a brief explanation on what I'm attempting to do here:
On the julia side I create
I can confirm that Is there a special procedure/function for creating an |
|
I understand, but here we have the following situation: What I understand now is that the segfault happens, since w = ArbComplex(1+im)
ptrw = Base.cconvert(Ref{ArbComplex}, w)
pptrw = Base.unsafe_convert(Ref{ArbComplex}, ptrw)
# exactly what ccall does to `w::ArbComplex{P}` when specifying `Ref{ArbComplex}` as target type
# ww = unsafe_load(pptrw) # this will sefgault what works is function acb_calc_func(out::Ptr{ArbComplex}, inp::Ptr{ArbComplex},
param::Ptr{Cvoid}, order::Cint, prec::Cint)
@assert iszero(order) # || isone(order) ← we'd need to verify holomorphicity
x = unsafe_load(convert(Ptr{ArbComplex{Int(prec)}}, inp))
f = unsafe_pointer_to_objref(param)
@debug "Evaluating at" x f(x)
ccall(@libarb(acb_set), Cvoid, (Ptr{ArbComplex}, Ref{ArbComplex}), out, f(x))
return zero(Cint)
end |
For illustrative clarification, here is the source code for evaluating an elliptic integral of the first kind (which is a function in Arb C Library that takes a complex parameter). # void acb_elliptic_k(acb_t res, const acb_t m, slong prec)
"""
elliptic_k(modulus)
Computes the complete elliptic integral of the first kind K(m)
"""
function elliptic_k(modulus::ArbComplex{P}) where {P}
isone(modulus) && return ArbComplex{P}(Inf,0)
result = ArbComplex{P}()
ccall(@libarb(acb_elliptic_k), Cvoid, (Ref{ArbComplex}, Ref{ArbComplex}, Cint), result, modulus, P)
return result
end Note that, at least in this sort of use, it is unnecessary to pass And, as a practical matter, avoiding unsafe functions unless their use is required or demanded for reasons of throughput makes maintaining and upgrading the source much easier. |
I don't quite understand how this example is connected to the code for arb-based integration.
In in I don't know how to read a piece of memory and reinterpret it as |
Are you intending that the function to be integrated is developed as an |
(continued) |
Ok, I see that I did not express the intent clearly:
example syntax (which already works)
|
oh now I see what you mean |
please show me a code block that provides the supportive functions you wrote and include two simple examples of their use [I understand there is your PR, also having it this way simplifies my focus]. |
in #33 there are a couple of tests added with intended use: User facing functions are:
The internal (low-level) function is Julia function I'm not sure if this explanation is what You asked for? |
That is helpful. |
OK .. I can work with this (which is to say, I will review the PR in detail .. and try to find corner cases, suggest a few more tests and offer an example that should allow you to support ArbFloat and ArbReal integral bounds as easily as using ArbComplex is now (without the need for the user to coerce types). |
here's one example from Frederik's blog: f(x) = sech(10*(x-ArbComplex(2)/10))^2 + sech(100(x-ArbComplex(4)/10))^4 + sech(1000*(x-ArbComplex(6)/10))^6
integrate(f, 0,1) |
I made your additions -- I thought correctly (cut paste cut paste) so why do we have
|
@kalmarek If you have a local version of ArbNumerics that differs from the current master and does evaluate the above integrals correctly, please let me know what you did to
add that variation on ArbNumerics |
Are you using the draft posted above? please use the version from #33 (the draft above has immutable I have julia> tst(x) = (2*x^5-x+3)/(x^2)
tst (generic function with 1 method)
julia> integrate(x->tst(x), 1, 2) - (9 - log(ArbComplex(2)))
[+/- 1.89e-36] + 0im |
Doing as you suggest, without explicitly rebuilding the package and again with explicit rebuilding, still I do not replicate your result. It is unexpected that our two sessions differ.
|
I may try alternative code just to see if there is source from which we both obtain correct results. |
that is very strange... julia> dir = tempname()
"/tmp/jl_faVVSH"
julia> mkdir(dir)
"/tmp/jl_faVVSH"
julia> cd(dir)
julia> using Pkg
julia> Pkg.activate(".")
Activating new environment at `/tmp/jl_faVVSH/Project.toml`
julia> Pkg.add(PackageSpec(url="https://github.com/kalmarek/ArbNumerics.jl", rev="enh/arb_calc_integrate"))
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Updating git-repo `https://github.com/kalmarek/ArbNumerics.jl`
Updating git-repo `https://github.com/kalmarek/ArbNumerics.jl`
Resolving package versions...
Updating `/tmp/jl_xLit4f/Project.toml`
[7e558dbc] + ArbNumerics v1.0.1 #enh/arb_calc_integrate (https://github.com/kalmarek/ArbNumerics.jl)
Updating `/tmp/jl_xLit4f/Manifest.toml`
[7e558dbc] + ArbNumerics v1.0.1 #enh/arb_calc_integrate (https://github.com/kalmarek/ArbNumerics.jl)
[b99e7846] + BinaryProvider v0.5.8
[01680d73] + GenericSVD v0.2.2
[c145ed77] + GenericSchur v0.3.0
[efe28fd5] + OpenSpecFun_jll v0.5.3+1
[0d4725de] + Readables v0.3.3
[276daf66] + SpecialFunctions v0.9.0
[2a0f44e3] + Base64
[ade2ca70] + Dates
[8ba89e20] + Distributed
[b77e0a4c] + InteractiveUtils
[76f85450] + LibGit2
[8f399da3] + Libdl
[37e2e46d] + LinearAlgebra
[56ddb016] + Logging
[d6f4376e] + Markdown
[44cfe95a] + Pkg
[de0858da] + Printf
[3fa0cd96] + REPL
[9a3f8284] + Random
[ea8e919c] + SHA
[9e88b42a] + Serialization
[6462fe0b] + Sockets
[8dfed614] + Test
[cf7118a7] + UUIDs
[4ec0a83e] + Unicode
julia> using ArbNumerics
julia> tst(x) = (2*x^5-x+3)/(x^2)
tst (generic function with 1 method)
julia> integrate(x->tst(x), 1, 2)
8.306852819440054690582767878542 + 0im Could you please verify that
?? |
did you restart julia after adding |
yes (now) .. same result as before |
at least Travis confirms that things are working on a "generic" installation: https://travis-ci.org/JeffreySarnoff/ArbNumerics.jl/builds/630613016?utm_source=github_status&utm_medium=notification btw. i'm testing on a Linux platform |
that is good to know -- now I need to track down the problem on my end |
Arb has acb_calc, where
acb_calc_integrate
is provided.I tried to wrap the function as follows
but the function evaluation segfaults at line
y = f(x)
modifying the function to
now segfaults at first access of the value of
x
, i.e. atprintln("x = $x")
(f
works correctly).I'm quite confused, since similar code in
Nemo
https://github.com/wbhart/Nemo.jl/blob/5f96afc4af415df5985432b56bd1a972a0025d4b/src/arb/acb_calc.jl#L2 works as expected.Probably
crel_goal
and the default values here and there need adjusting as well.The text was updated successfully, but these errors were encountered: