Skip to content

Commit

Permalink
Merge pull request #152 from kalmarek/1.6-cleanup
Browse files Browse the repository at this point in the history
1.6 cleanup
  • Loading branch information
Joel-Dahne authored Jun 7, 2022
2 parents 8644974 + 7d7f749 commit 89e8f0d
Show file tree
Hide file tree
Showing 33 changed files with 254 additions and 289 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Arblib"
uuid = "fb37089c-8514-4489-9461-98f9c8763369"
authors = ["Marek Kaluba <[email protected]>", "Sascha Timme <Sascha Timme <[email protected]>", "Joel Dahne <[email protected]>"]
version = "0.7.0"
version = "0.7.1"

[deps]
Arb_jll = "d9960996-1013-53c9-9ba4-74a4155039c3"
Expand Down
7 changes: 0 additions & 7 deletions src/Arblib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ using Arb_jll
import LinearAlgebra
import SpecialFunctions

if VERSION >= v"1.5.0-DEV.639"
import Base: contains
end
if VERSION >= v"1.6"
import Base: sincospi
end

export Mag,
MagRef,
Arf,
Expand Down
24 changes: 12 additions & 12 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Base.abs(x::ArfOrRef) = abs!(zero(x), x)
Base.:(-)(x::ArfOrRef) = neg!(zero(x), x)
for (jf, af) in [(:+, :add!), (:-, :sub!), (:*, :mul!), (:/, :div!)]
@eval function Base.$jf(x::ArfOrRef, y::Union{ArfOrRef,_BitInteger})
z = Arf(prec = _precision((x, y)))
z = Arf(prec = _precision(x, y))
$af(z, x, y)
return z
end
Expand Down Expand Up @@ -77,29 +77,29 @@ end
### Arb and Acb
for (jf, af) in [(:+, :add!), (:-, :sub!), (:*, :mul!), (:/, :div!)]
@eval Base.$jf(x::ArbOrRef, y::Union{ArbOrRef,ArfOrRef,_BitInteger}) =
$af(Arb(prec = _precision((x, y))), x, y)
$af(Arb(prec = _precision(x, y)), x, y)
@eval Base.$jf(x::AcbOrRef, y::Union{AcbOrRef,ArbOrRef,_BitInteger}) =
$af(Acb(prec = _precision((x, y))), x, y)
$af(Acb(prec = _precision(x, y)), x, y)
if jf == :(+) || jf == :(*)
@eval Base.$jf(x::Union{ArfOrRef,_BitInteger}, y::ArbOrRef) =
$af(Arb(prec = _precision((x, y))), y, x)
$af(Arb(prec = _precision(x, y)), y, x)
@eval Base.$jf(x::Union{ArbOrRef,_BitInteger}, y::AcbOrRef) =
$af(Acb(prec = _precision((x, y))), y, x)
$af(Acb(prec = _precision(x, y)), y, x)
end
end

Base.:(-)(x::Union{ArbOrRef,AcbOrRef}) = neg!(zero(x), x)
Base.abs(x::ArbOrRef) = abs!(zero(x), x)
Base.:(/)(x::_BitUnsigned, y::ArbOrRef) = ui_div!(zero(y), x, y)

Base.:(^)(x::ArbOrRef, y::ArbOrRef) = pow!(Arb(prec = _precision((x, y))), x, y)
Base.:(^)(x::ArbOrRef, y::ArbOrRef) = pow!(Arb(prec = _precision(x, y)), x, y)
function Base.:(^)(x::ArbOrRef, y::_BitInteger)
z = zero(x)
x, n = (y >= 0 ? (x, y) : (inv!(z, x), -y))
return pow!(z, x, convert(UInt, n))
end
Base.:(^)(x::AcbOrRef, y::Union{AcbOrRef,ArbOrRef,_BitInteger}) =
pow!(Acb(prec = _precision((x, y))), x, y)
pow!(Acb(prec = _precision(x, y)), x, y)

# We define the same special cases as Arb does, this avoids some
# overhead
Expand All @@ -110,7 +110,7 @@ Base.literal_pow(::typeof(^), x::Union{ArbOrRef,AcbOrRef}, ::Val{0}) = one(x)
Base.literal_pow(::typeof(^), x::Union{ArbOrRef,AcbOrRef}, ::Val{1}) = copy(x)
Base.literal_pow(::typeof(^), x::Union{ArbOrRef,AcbOrRef}, ::Val{2}) = sqr(x)

Base.hypot(x::ArbOrRef, y::ArbOrRef) = hypot!(Arb(prec = _precision((x, y))), x, y)
Base.hypot(x::ArbOrRef, y::ArbOrRef) = hypot!(Arb(prec = _precision(x, y)), x, y)

root(x::Union{ArbOrRef,AcbOrRef}, k::Integer) = root!(zero(x), x, convert(UInt, k))

Expand Down Expand Up @@ -156,14 +156,14 @@ cotpi(x::Union{ArbOrRef,AcbOrRef}) = cot_pi!(zero(x), x)
cscpi(x::Union{ArbOrRef,AcbOrRef}) = csc_pi!(zero(x), x)
# Julias definition of sinc is equivalent to Arbs definition of sincpi
Base.sinc(x::Union{ArbOrRef,AcbOrRef}) = sinc_pi!(zero(x), x)
Base.atan(y::ArbOrRef, x::ArbOrRef) = atan2!(Arb(prec = _precision((y, x))), y, x)
Base.atan(y::ArbOrRef, x::ArbOrRef) = atan2!(Arb(prec = _precision(y, x)), y, x)

function Base.sincos(x::Union{ArbOrRef,AcbOrRef})
s, c = zero(x), zero(x)
sin_cos!(s, c, x)
return (s, c)
end
function sincospi(x::Union{ArbOrRef,AcbOrRef})
function Base.sincospi(x::Union{ArbOrRef,AcbOrRef})
s, c = zero(x), zero(x)
sin_cos_pi!(s, c, x)
return (s, c)
Expand All @@ -189,8 +189,8 @@ function Base.:(*)(x::AcbOrRef, y::Complex{Bool})
end
Base.:(*)(x::Complex{Bool}, y::AcbOrRef) = y * x

Base.real(z::AcbLike; prec = _precision(z)) = get_real!(Arb(prec = prec), z)
Base.imag(z::AcbLike; prec = _precision(z)) = get_imag!(Arb(prec = prec), z)
Base.real(z::AcbLike; prec = _precision(z)) = get_real!(Arb(; prec), z)
Base.imag(z::AcbLike; prec = _precision(z)) = get_imag!(Arb(; prec), z)
Base.conj(z::AcbLike) = conj!(Acb(prec = _precision(z)), z)
Base.abs(z::AcbLike) = abs!(Arb(prec = _precision(z)), z)

Expand Down
72 changes: 36 additions & 36 deletions src/calc_integrate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ function _acb_calc_func!(
prec::Int,
)
@assert iszero(order) || isone(order)
x = AcbRef(inp, nothing, prec = prec)
res = AcbRef(out, nothing, prec = prec)
x = AcbRef(inp, nothing; prec)
res = AcbRef(out, nothing; prec)
f! = unsafe_pointer_to_objref(param)

f!(res, x, analytic = isone(order), prec = prec)
f!(res, x, analytic = isone(order); prec)

return zero(Cint)
end
Expand Down Expand Up @@ -189,9 +189,9 @@ function integrate!(
if !check_analytic && !take_prec
g! = (res, x; analytic, prec) -> f!(res, x)
elseif !check_analytic && take_prec
g! = (res, x; analytic, prec) -> f!(res, x, prec = prec)
g! = (res, x; analytic, prec) -> f!(res, x; prec)
elseif check_analytic && !take_prec
g! = (res, x; analytic, prec) -> f!(res, x, analytic = analytic)
g! = (res, x; analytic, prec) -> f!(res, x; analytic)
else
g! = f!
end
Expand All @@ -200,12 +200,12 @@ function integrate!(
g!,
res,
a,
b,
prec = prec,
rel_goal = rel_goal,
b;
prec,
rel_goal,
abs_tol = convert(Mag, atol),
warn_on_no_convergence = warn_on_no_convergence,
opts = opts,
warn_on_no_convergence,
opts,
)
end

Expand All @@ -225,15 +225,15 @@ function integrate!(
return integrate!(
f!,
res,
Acb(a, prec = prec),
Acb(b, prec = prec),
check_analytic = check_analytic,
take_prec = take_prec,
prec = prec,
rtol = rtol,
atol = atol,
warn_on_no_convergence = warn_on_no_convergence,
opts = opts,
Acb(a; prec),
Acb(b; prec);
check_analytic,
take_prec,
prec,
rtol,
atol,
warn_on_no_convergence,
opts,
)
end

Expand Down Expand Up @@ -331,20 +331,20 @@ function integrate(
opts::Union{Ptr{Cvoid},calc_integrate_opt_struct} = C_NULL,
)
f! = (res, x; kwargs...) -> set!(res, f(x; kwargs...))
res = Acb(prec = prec)
res = Acb(; prec)

return integrate!(
f!,
res,
a,
b;
check_analytic = check_analytic,
take_prec = take_prec,
rtol = rtol,
atol = atol,
warn_on_no_convergence = warn_on_no_convergence,
opts = opts,
prec = prec,
check_analytic,
take_prec,
rtol,
atol,
warn_on_no_convergence,
opts,
prec,
)
end

Expand All @@ -362,14 +362,14 @@ function integrate(
)
return integrate(
f,
Acb(a, prec = prec),
Acb(b, prec = prec),
check_analytic = check_analytic,
take_prec = take_prec,
prec = prec,
rtol = rtol,
atol = atol,
warn_on_no_convergence = warn_on_no_convergence,
opts = opts,
Acb(a; prec),
Acb(b; prec);
check_analytic,
take_prec,
prec,
rtol,
atol,
warn_on_no_convergence,
opts,
)
end
28 changes: 14 additions & 14 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ Mag(x::Union{MagRef,ArfRef}) = Mag(mag_struct(cstruct(x)))
Mag(x, y) = set!(Mag(), x, y)

# Arf
Arf(x; prec::Integer = _precision(x)) = set!(Arf(prec = prec), x)
Arf(x; prec::Integer = _precision(x)) = set!(Arf(; prec), x)
# disambiguation
Arf(x::Arf; prec::Integer = precision(x)) = set!(Arf(prec = prec), x)
Arf(x::Rational; prec::Integer = _precision(x)) = set!(Arf(prec = prec), x)
Arf(x::Arf; prec::Integer = precision(x)) = set!(Arf(; prec), x)
Arf(x::Rational; prec::Integer = _precision(x)) = set!(Arf(; prec), x)

#Arb
Arb(x; prec::Integer = _precision(x)) = set!(Arb(prec = prec), x)
Arb(x; prec::Integer = _precision(x)) = set!(Arb(; prec), x)
# disambiguation
Arb(x::Arb; prec::Integer = precision(x)) = set!(Arb(prec = prec), x)
Arb(x::Rational; prec::Integer = _precision(x)) = set!(Arb(prec = prec), x)
Arb(x::Arb; prec::Integer = precision(x)) = set!(Arb(; prec), x)
Arb(x::Rational; prec::Integer = _precision(x)) = set!(Arb(; prec), x)

function Arb(str::AbstractString; prec::Integer = DEFAULT_PRECISION[])
res = Arb(prec = prec)
res = Arb(; prec)
flag = set!(res, str)
iszero(flag) || throw(ArgumentError("could not parse $str as an Arb"))
return res
Expand All @@ -26,26 +26,26 @@ end
Acb(
x::Union{Real,arb_struct,arf_struct,Tuple{<:Real,<:Real}};
prec::Integer = _precision(x),
) = set!(Acb(prec = prec), x)
) = set!(Acb(; prec), x)
Acb(
re::Union{Real,arb_struct,arf_struct,Tuple{<:Real,<:Real}},
im::Union{Real,arb_struct,arf_struct,Tuple{<:Real,<:Real}};
prec::Integer = max(_precision(re), _precision(im)),
) = set!(Acb(prec = prec), re, im)
) = set!(Acb(; prec), re, im)

Acb(z::Union{AcbLike,Complex}; prec::Integer = _precision(z)) = set!(Acb(prec = prec), z)
Acb(z::Union{AcbLike,Complex}; prec::Integer = _precision(z)) = set!(Acb(; prec), z)
# disambiguation
Acb(x::Acb; prec::Integer = precision(x)) = set!(Acb(prec = prec), x)
Acb(x::Acb; prec::Integer = precision(x)) = set!(Acb(; prec), x)

function Acb(str::AbstractString; prec::Integer = DEFAULT_PRECISION[])
res = Acb(prec = prec)
res = Acb(; prec)
flag = set!(realref(res), str)
iszero(flag) || throw(ArgumentError("could not parse $str as an Arb"))
return res
end

function Acb(re::AbstractString, im::AbstractString; prec::Integer = DEFAULT_PRECISION[])
res = Acb(prec = prec)
res = Acb(; prec)
flag = set!(realref(res), re)
iszero(flag) || throw(ArgumentError("could not parse $str as an Arb"))
flag = set!(imagref(res), im)
Expand All @@ -65,7 +65,7 @@ Base.ComplexF64(z::AcbLike) = Complex(Float64(realref(z)), Float64(imagref(z)))
function Base.BigFloat(x::Union{Arf,ArfRef})
y = BigFloat(; precision = precision(x))
get!(y, x)
y
return y
end
Base.BigFloat(x::Union{Arb,ArbRef}) = BigFloat(midref(x))

Expand Down
Loading

2 comments on commit 89e8f0d

@Joel-Dahne
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/61879

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.1 -m "<description of version>" 89e8f0df3709305b92c713986f2179ed57797b0d
git push origin v0.7.1

Please sign in to comment.