From eea3f9406483134dee9bf81ff1f0f423d59b963d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 25 Oct 2024 14:29:02 +0200 Subject: [PATCH] Wrap Arb pointer functions into julia functions (#1921) --- src/arb/ArbTypes.jl | 11 +++++++++++ src/arb/Complex.jl | 43 ++++++++++++++++++++++-------------------- src/arb/ComplexMat.jl | 4 ++-- src/arb/ComplexPoly.jl | 21 +++++++++------------ src/arb/Real.jl | 17 ++++++++--------- src/arb/RealMat.jl | 4 ++-- src/arb/RealPoly.jl | 4 ++-- src/arb/acb.jl | 43 ++++++++++++++++++++++-------------------- src/arb/acb_mat.jl | 4 ++-- src/arb/acb_poly.jl | 21 +++++++++------------ src/arb/arb.jl | 17 ++++++++--------- src/arb/arb_mat.jl | 4 ++-- src/arb/arb_poly.jl | 4 ++-- 13 files changed, 103 insertions(+), 94 deletions(-) diff --git a/src/arb/ArbTypes.jl b/src/arb/ArbTypes.jl index 95926c9bf..d5a66b99f 100644 --- a/src/arb/ArbTypes.jl +++ b/src/arb/ArbTypes.jl @@ -74,6 +74,17 @@ mutable struct acb_struct imag_rad_man::UInt end +const arf_structOrPtr = Union{arf_struct, Ref{arf_struct}, Ptr{arf_struct}} +const mag_structOrPtr = Union{mag_struct, Ref{mag_struct}, Ptr{mag_struct}} +const arb_structOrPtr = Union{arb_struct, Ref{arb_struct}, Ptr{arb_struct}} +const acb_structOrPtr = Union{acb_struct, Ref{acb_struct}, Ptr{acb_struct}} + +_mid_ptr(x::arb_structOrPtr) = @ccall libflint.arb_mid_ptr(x::Ref{arb_struct})::Ptr{arf_struct} +_rad_ptr(x::arb_structOrPtr) = @ccall libflint.arb_rad_ptr(x::Ref{arb_struct})::Ptr{mag_struct} + +_real_ptr(x::acb_structOrPtr) = @ccall libflint.acb_real_ptr(x::Ref{acb_struct})::Ptr{arb_struct} +_imag_ptr(x::acb_structOrPtr) = @ccall libflint.acb_imag_ptr(x::Ref{acb_struct})::Ptr{arb_struct} + ################################################################################ # # Types and memory management for ArbField diff --git a/src/arb/Complex.jl b/src/arb/Complex.jl index e7d13c87e..6d5e43773 100644 --- a/src/arb/Complex.jl +++ b/src/arb/Complex.jl @@ -75,10 +75,10 @@ characteristic(::ComplexField) = 0 function convert(::Type{ComplexF64}, x::ComplexFieldElem) GC.@preserve x begin - re = ccall((:acb_real_ptr, libflint), Ptr{arb_struct}, (Ref{ComplexFieldElem}, ), x) - im = ccall((:acb_imag_ptr, libflint), Ptr{arb_struct}, (Ref{ComplexFieldElem}, ), x) - t = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ptr{RealFieldElem}, ), re) - u = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ptr{RealFieldElem}, ), im) + re = _real_ptr(x) + im = _imag_ptr(x) + t = _mid_ptr(re) + u = _mid_ptr(im) # 4 == round to nearest v = ccall((:arf_get_d, libflint), Float64, (Ptr{arf_struct}, Int), t, 4) w = ccall((:arf_get_d, libflint), Float64, (Ptr{arf_struct}, Int), u, 4) @@ -1616,6 +1616,9 @@ end # ################################################################################ +_real_ptr(x::ComplexFieldElemOrPtr) = @ccall libflint.acb_real_ptr(x::Ref{ComplexFieldElem})::Ptr{RealFieldElem} +_imag_ptr(x::ComplexFieldElemOrPtr) = @ccall libflint.acb_imag_ptr(x::Ref{ComplexFieldElem})::Ptr{RealFieldElem} + for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{ComplexFieldElem}, Ptr{ComplexFieldElem})) for (f,t) in (("acb_set_si", Int), ("acb_set_ui", UInt), ("acb_set_d", Float64)) @@ -1675,23 +1678,23 @@ for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{Compl end function _acb_set(x::($typeofx), y::AbstractString, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end function _acb_set(x::($typeofx), y::BigFloat) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end function _acb_set(x::($typeofx), y::BigFloat, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end @@ -1714,30 +1717,30 @@ for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{Compl end function _acb_set(x::($typeofx), y::QQFieldElem, z::QQFieldElem, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, z, p) end function _acb_set(x::($typeofx), y::T, z::T, p::Int) where {T <: AbstractString} - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, z, p) end function _acb_set(x::($typeofx), y::Real, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end function _acb_set(x::($typeofx), y::Complex, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, real(y), p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, imag(y), p) end @@ -1746,9 +1749,9 @@ for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{Compl for T in (Real, ZZRingElem) @eval begin function _acb_set(x::($typeofx), y::($T), z::($T), p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, z, p) end end diff --git a/src/arb/ComplexMat.jl b/src/arb/ComplexMat.jl index 055ee94b4..fff7ab1e7 100644 --- a/src/arb/ComplexMat.jl +++ b/src/arb/ComplexMat.jl @@ -686,10 +686,10 @@ bound for the infinity norm for every matrix in $x$ function bound_inf_norm(x::ComplexMatrix) z = RealFieldElem() GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{RealFieldElem}, ), z) + t = _rad_ptr(z) ccall((:acb_mat_bound_inf_norm, libflint), Nothing, (Ptr{mag_struct}, Ref{ComplexMatrix}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{RealFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:mag_zero, libflint), Nothing, diff --git a/src/arb/ComplexPoly.jl b/src/arb/ComplexPoly.jl index 6c1a47dea..76071a8d9 100644 --- a/src/arb/ComplexPoly.jl +++ b/src/arb/ComplexPoly.jl @@ -597,12 +597,10 @@ function roots(x::ComplexPolyRingElem; target=0, isolate_real=false, initial_pre ok = true if target > 0 for i = 0 : deg-1 - re = ccall((:acb_real_ptr, libflint), Ptr{arb_struct}, - (Ptr{acb_struct}, ), roots + i * sizeof(acb_struct)) - im = ccall((:acb_imag_ptr, libflint), Ptr{arb_struct}, - (Ptr{acb_struct}, ), roots + i * sizeof(acb_struct)) - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ptr{ArbFieldElem}, ), re) - u = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ptr{ArbFieldElem}, ), im) + re = _real_ptr(roots + i * sizeof(acb_struct)) + im = _imag_ptr(roots + i * sizeof(acb_struct)) + t = _rad_ptr(re) + u = _rad_ptr(im) ok = ok && (ccall((:mag_cmp_2exp_si, libflint), Cint, (Ptr{mag_struct}, Int), t, -target) <= 0) ok = ok && (ccall((:mag_cmp_2exp_si, libflint), Cint, @@ -620,10 +618,9 @@ function roots(x::ComplexPolyRingElem; target=0, isolate_real=false, initial_pre if real_ok for i = 0 : deg - 1 - im = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, - (Ptr{ComplexFieldElem}, ), roots + i * sizeof(acb_struct)) - if ccall((:arb_contains_zero, libflint), Bool, (Ptr{RealFieldElem}, ), im) - zero!(im) + im = _imag_ptr(roots + i * sizeof(acb_struct)) + if ccall((:arb_contains_zero, libflint), Bool, (Ptr{arb_struct}, ), im) + ccall((:arb_zero, libflint), Nothing, (Ptr{arb_struct}, ), im) end end end @@ -669,10 +666,10 @@ function roots_upper_bound(x::ComplexPolyRingElem) z = RealFieldElem() p = precision(Balls) GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{RealFieldElem}, ), z) + t = _rad_ptr(z) ccall((:acb_poly_root_bound_fujiwara, libflint), Nothing, (Ptr{mag_struct}, Ref{ComplexPolyRingElem}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{RealFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:arf_set_round, libflint), Nothing, (Ptr{arf_struct}, Ptr{arf_struct}, Int, Cint), s, s, p, ARB_RND_CEIL) diff --git a/src/arb/Real.jl b/src/arb/Real.jl index f6765e544..daf3cdf07 100644 --- a/src/arb/Real.jl +++ b/src/arb/Real.jl @@ -55,6 +55,9 @@ end characteristic(::RealField) = 0 +_mid_ptr(x::RealFieldElemOrPtr) = @ccall libflint.arb_mid_ptr(x::Ref{RealFieldElem})::Ptr{arf_struct} +_rad_ptr(x::RealFieldElemOrPtr) = @ccall libflint.arb_rad_ptr(x::Ref{RealFieldElem})::Ptr{mag_struct} + ################################################################################ # # Conversions @@ -90,9 +93,7 @@ end function _arb_get_arf(x::RealFieldElem, ::RoundingMode{:Nearest}) t = arf_struct() GC.@preserve x begin - t1 = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, - (Ref{RealFieldElem}, ), - x) + t1 = _mid_ptr(x) ccall((:arf_set, libflint), Nothing, (Ref{arf_struct}, Ptr{arf_struct}), t, t1) @@ -2013,18 +2014,16 @@ for (typeofx, passtoc) in ((RealFieldElem, Ref{RealFieldElem}), (Ptr{RealFieldEl end function _arb_set(x::($typeofx), y::BigFloat) - m = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, - (($passtoc), ), x) - r = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, - (($passtoc), ), x) + m = _mid_ptr(x) + r = _rad_ptr(x) ccall((:arf_set_mpfr, libflint), Nothing, (Ptr{arf_struct}, Ref{BigFloat}), m, y) ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) end function _arb_set(x::($typeofx), y::BigFloat, p::Int) - m = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (($passtoc), ), x) - r = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (($passtoc), ), x) + m = _mid_ptr(x) + r = _rad_ptr(x) ccall((:arf_set_mpfr, libflint), Nothing, (Ptr{arf_struct}, Ref{BigFloat}), m, y) ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) diff --git a/src/arb/RealMat.jl b/src/arb/RealMat.jl index fccbc26ce..f48e3f6db 100644 --- a/src/arb/RealMat.jl +++ b/src/arb/RealMat.jl @@ -628,10 +628,10 @@ bound for the infinity norm for every matrix in $x$ function bound_inf_norm(x::RealMatrix) z = RealFieldElem() GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{RealFieldElem}, ), z) + t = _rad_ptr(z) ccall((:arb_mat_bound_inf_norm, libflint), Nothing, (Ptr{mag_struct}, Ref{RealMatrix}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{RealFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:mag_zero, libflint), Nothing, diff --git a/src/arb/RealPoly.jl b/src/arb/RealPoly.jl index 6d5dd5b81..ff4cd9008 100644 --- a/src/arb/RealPoly.jl +++ b/src/arb/RealPoly.jl @@ -569,10 +569,10 @@ function roots_upper_bound(x::RealPolyRingElem) z = base_ring(x)() p = precision(Balls) GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{RealFieldElem}, ), z) + t = _rad_ptr(z) ccall((:arb_poly_root_bound_fujiwara, libflint), Nothing, (Ptr{mag_struct}, Ref{RealPolyRingElem}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{RealFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:arf_set_round, libflint), Nothing, (Ptr{arf_struct}, Ptr{arf_struct}, Int, Cint), s, s, p, ARB_RND_CEIL) diff --git a/src/arb/acb.jl b/src/arb/acb.jl index 51d8faa35..7e9edcab6 100644 --- a/src/arb/acb.jl +++ b/src/arb/acb.jl @@ -85,10 +85,10 @@ characteristic(::AcbField) = 0 function convert(::Type{ComplexF64}, x::AcbFieldElem) GC.@preserve x begin - re = ccall((:acb_real_ptr, libflint), Ptr{arb_struct}, (Ref{AcbFieldElem}, ), x) - im = ccall((:acb_imag_ptr, libflint), Ptr{arb_struct}, (Ref{AcbFieldElem}, ), x) - t = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ptr{ArbFieldElem}, ), re) - u = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ptr{ArbFieldElem}, ), im) + re = _real_ptr(x) + im = _imag_ptr(x) + t = _mid_ptr(re) + u = _mid_ptr(im) # 4 == round to nearest v = ccall((:arf_get_d, libflint), Float64, (Ptr{arf_struct}, Int), t, 4) w = ccall((:arf_get_d, libflint), Float64, (Ptr{arf_struct}, Int), u, 4) @@ -1611,6 +1611,9 @@ end # ################################################################################ +_real_ptr(x::AcbFieldElemOrPtr) = @ccall libflint.acb_real_ptr(x::Ref{AcbFieldElem})::Ptr{ArbFieldElem} +_imag_ptr(x::AcbFieldElemOrPtr) = @ccall libflint.acb_imag_ptr(x::Ref{AcbFieldElem})::Ptr{ArbFieldElem} + for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem}, Ptr{AcbFieldElem})) for (f,t) in (("acb_set_si", Int), ("acb_set_ui", UInt), ("acb_set_d", Float64)) @@ -1670,23 +1673,23 @@ for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem} end function _acb_set(x::($typeofx), y::AbstractString, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end function _acb_set(x::($typeofx), y::BigFloat) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end function _acb_set(x::($typeofx), y::BigFloat, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end @@ -1709,30 +1712,30 @@ for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem} end function _acb_set(x::($typeofx), y::QQFieldElem, z::QQFieldElem, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, z, p) end function _acb_set(x::($typeofx), y::T, z::T, p::Int) where {T <: AbstractString} - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, z, p) end function _acb_set(x::($typeofx), y::Real, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) zero!(i) end function _acb_set(x::($typeofx), y::Complex, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, real(y), p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, imag(y), p) end @@ -1741,9 +1744,9 @@ for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem} for T in (Real, ZZRingElem) @eval begin function _acb_set(x::($typeofx), y::($T), z::($T), p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + r = _real_ptr(x) _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) + i = _imag_ptr(x) _arb_set(i, z, p) end end diff --git a/src/arb/acb_mat.jl b/src/arb/acb_mat.jl index 722548b74..1bf5111cb 100644 --- a/src/arb/acb_mat.jl +++ b/src/arb/acb_mat.jl @@ -688,10 +688,10 @@ bound for the infinity norm for every matrix in $x$ function bound_inf_norm(x::AcbMatrix) z = ArbFieldElem() GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{ArbFieldElem}, ), z) + t = _rad_ptr(z) ccall((:acb_mat_bound_inf_norm, libflint), Nothing, (Ptr{mag_struct}, Ref{AcbMatrix}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{ArbFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:mag_zero, libflint), Nothing, diff --git a/src/arb/acb_poly.jl b/src/arb/acb_poly.jl index 57c8fc7be..e6c26f287 100644 --- a/src/arb/acb_poly.jl +++ b/src/arb/acb_poly.jl @@ -593,12 +593,10 @@ function roots(x::AcbPolyRingElem; target=0, isolate_real=false, initial_prec=0, ok = true if target > 0 for i = 0 : deg-1 - re = ccall((:acb_real_ptr, libflint), Ptr{arb_struct}, - (Ptr{AcbFieldElem}, ), roots + i * sizeof(acb_struct)) - im = ccall((:acb_imag_ptr, libflint), Ptr{arb_struct}, - (Ptr{AcbFieldElem}, ), roots + i * sizeof(acb_struct)) - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ptr{ArbFieldElem}, ), re) - u = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ptr{ArbFieldElem}, ), im) + re = _real_ptr(roots + i * sizeof(acb_struct)) + im = _imag_ptr(roots + i * sizeof(acb_struct)) + t = _rad_ptr(re) + u = _rad_ptr(im) ok = ok && (ccall((:mag_cmp_2exp_si, libflint), Cint, (Ptr{mag_struct}, Int), t, -target) <= 0) ok = ok && (ccall((:mag_cmp_2exp_si, libflint), Cint, @@ -616,10 +614,9 @@ function roots(x::AcbPolyRingElem; target=0, isolate_real=false, initial_prec=0, if real_ok for i = 0 : deg - 1 - im = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, - (Ptr{AcbFieldElem}, ), roots + i * sizeof(acb_struct)) - if ccall((:arb_contains_zero, libflint), Bool, (Ptr{ArbFieldElem}, ), im) - zero!(im) + im = _imag_ptr(roots + i * sizeof(acb_struct)) + if ccall((:arb_contains_zero, libflint), Bool, (Ptr{arb_struct}, ), im) + ccall((:arb_zero, libflint), Nothing, (Ptr{arb_struct}, ), im) end end end @@ -665,10 +662,10 @@ function roots_upper_bound(x::AcbPolyRingElem) z = ArbField(precision(base_ring(x)))() p = precision(base_ring(x)) GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{ArbFieldElem}, ), z) + t = _rad_ptr(z) ccall((:acb_poly_root_bound_fujiwara, libflint), Nothing, (Ptr{mag_struct}, Ref{AcbPolyRingElem}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{ArbFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:arf_set_round, libflint), Nothing, (Ptr{arf_struct}, Ptr{arf_struct}, Int, Cint), s, s, p, ARB_RND_CEIL) diff --git a/src/arb/arb.jl b/src/arb/arb.jl index c86b05da1..32df2456b 100644 --- a/src/arb/arb.jl +++ b/src/arb/arb.jl @@ -56,6 +56,9 @@ end characteristic(::ArbField) = 0 +_mid_ptr(x::ArbFieldElemOrPtr) = @ccall libflint.arb_mid_ptr(x::Ref{ArbFieldElem})::Ptr{arf_struct} +_rad_ptr(x::ArbFieldElemOrPtr) = @ccall libflint.arb_rad_ptr(x::Ref{ArbFieldElem})::Ptr{mag_struct} + ################################################################################ # # Conversions @@ -91,9 +94,7 @@ end function _arb_get_arf(x::ArbFieldElem, ::RoundingMode{:Nearest}) t = arf_struct() GC.@preserve x begin - t1 = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, - (Ref{ArbFieldElem}, ), - x) + t1 = _mid_ptr(x) ccall((:arf_set, libflint), Nothing, (Ref{arf_struct}, Ptr{arf_struct}), t, t1) @@ -2021,18 +2022,16 @@ for (typeofx, passtoc) in ((ArbFieldElem, Ref{ArbFieldElem}), (Ptr{ArbFieldElem} end function _arb_set(x::($typeofx), y::BigFloat) - m = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, - (($passtoc), ), x) - r = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, - (($passtoc), ), x) + m = _mid_ptr(x) + r = _rad_ptr(x) ccall((:arf_set_mpfr, libflint), Nothing, (Ptr{arf_struct}, Ref{BigFloat}), m, y) ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) end function _arb_set(x::($typeofx), y::BigFloat, p::Int) - m = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (($passtoc), ), x) - r = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (($passtoc), ), x) + m = _mid_ptr(x) + r = _rad_ptr(x) ccall((:arf_set_mpfr, libflint), Nothing, (Ptr{arf_struct}, Ref{BigFloat}), m, y) ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) diff --git a/src/arb/arb_mat.jl b/src/arb/arb_mat.jl index 2e61a140f..b0daa8ff4 100644 --- a/src/arb/arb_mat.jl +++ b/src/arb/arb_mat.jl @@ -655,10 +655,10 @@ bound for the infinity norm for every matrix in $x$ function bound_inf_norm(x::ArbMatrix) z = ArbFieldElem() GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{ArbFieldElem}, ), z) + t = _rad_ptr(z) ccall((:arb_mat_bound_inf_norm, libflint), Nothing, (Ptr{mag_struct}, Ref{ArbMatrix}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{ArbFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:mag_zero, libflint), Nothing, diff --git a/src/arb/arb_poly.jl b/src/arb/arb_poly.jl index 90d2b8944..32744e189 100644 --- a/src/arb/arb_poly.jl +++ b/src/arb/arb_poly.jl @@ -569,10 +569,10 @@ function roots_upper_bound(x::ArbPolyRingElem) z = base_ring(x)() p = precision(base_ring(x)) GC.@preserve x z begin - t = ccall((:arb_rad_ptr, libflint), Ptr{mag_struct}, (Ref{ArbFieldElem}, ), z) + t = _rad_ptr(z) ccall((:arb_poly_root_bound_fujiwara, libflint), Nothing, (Ptr{mag_struct}, Ref{ArbPolyRingElem}), t, x) - s = ccall((:arb_mid_ptr, libflint), Ptr{arf_struct}, (Ref{ArbFieldElem}, ), z) + s = _mid_ptr(z) ccall((:arf_set_mag, libflint), Nothing, (Ptr{arf_struct}, Ptr{mag_struct}), s, t) ccall((:arf_set_round, libflint), Nothing, (Ptr{arf_struct}, Ptr{arf_struct}, Int, Cint), s, s, p, ARB_RND_CEIL)