diff --git a/src/arb/ArbTypes.jl b/src/arb/ArbTypes.jl index 225292497..7c3740182 100644 --- a/src/arb/ArbTypes.jl +++ b/src/arb/ArbTypes.jl @@ -100,19 +100,19 @@ mutable struct RealFieldElem <: FieldElem function RealFieldElem(x::Union{Real, ZZRingElem, QQFieldElem, AbstractString, RealFieldElem}, p::Int) z = RealFieldElem() - _arb_set(z, x, p) + set!(z, x, p) return z end function RealFieldElem(x::Union{Real, ZZRingElem}) z = RealFieldElem() - _arb_set(z, x) + set!(z, x) return z end function RealFieldElem(mid::RealFieldElem, rad::RealFieldElem) z = RealFieldElem() - ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}), z, mid) + set!(z, mid) ccall((:arb_add_error, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}), z, rad) return z end @@ -158,19 +158,19 @@ mutable struct ArbFieldElem <: FieldElem function ArbFieldElem(x::Union{Real, ZZRingElem, QQFieldElem, AbstractString, ArbFieldElem}, p::Int) z = ArbFieldElem() - _arb_set(z, x, p) + set!(z, x, p) return z end function ArbFieldElem(x::Union{Real, ZZRingElem, ArbFieldElem}) z = ArbFieldElem() - _arb_set(z, x) + set!(z, x) return z end function ArbFieldElem(mid::ArbFieldElem, rad::ArbFieldElem) z = ArbFieldElem() - ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ref{ArbFieldElem}), z, mid) + set!(z, mid) ccall((:arb_add_error, libflint), Nothing, (Ref{ArbFieldElem}, Ref{ArbFieldElem}), z, rad) return z end @@ -219,19 +219,19 @@ mutable struct ComplexFieldElem <: FieldElem function ComplexFieldElem(x::Union{Number, ZZRingElem, RealFieldElem, ComplexFieldElem}) z = ComplexFieldElem() - _acb_set(z, x) + set!(z, x) return z end function ComplexFieldElem(x::Union{Number, ZZRingElem, QQFieldElem, RealFieldElem, ComplexFieldElem, AbstractString}, p::Int) z = ComplexFieldElem() - _acb_set(z, x, p) + set!(z, x, p) return z end function ComplexFieldElem(x::T, y::T, p::Int) where {T <: Union{Real, ZZRingElem, QQFieldElem, AbstractString, RealFieldElem}} z = ComplexFieldElem() - _acb_set(z, x, y, p) + set!(z, (x, y), p) return z end end @@ -370,25 +370,25 @@ mutable struct AcbFieldElem <: FieldElem function AcbFieldElem(x::Union{Number, ZZRingElem, ArbFieldElem, AcbFieldElem}) z = AcbFieldElem() - _acb_set(z, x) + set!(z, x) return z end function AcbFieldElem(x::Union{Number, ZZRingElem, QQFieldElem, ArbFieldElem, AcbFieldElem, AbstractString}, p::Int) z = AcbFieldElem() - _acb_set(z, x, p) + set!(z, x, p) return z end #function AcbFieldElem{T <: Union{Int, UInt, Float64, ZZRingElem, BigFloat, ArbFieldElem}}(x::T, y::T) # z = AcbFieldElem() - # _acb_set(z, x, y) + # set!(z, x, y) # return z #end function AcbFieldElem(x::T, y::T, p::Int) where {T <: Union{Real, ZZRingElem, QQFieldElem, AbstractString, ArbFieldElem}} z = AcbFieldElem() - _acb_set(z, x, y, p) + set!(z, (x, y), p) return z end end @@ -822,7 +822,7 @@ mutable struct RealMatrix <: MatElem{RealFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[i, j]) + set!(el, arr[i, j]) end end return z @@ -833,7 +833,7 @@ mutable struct RealMatrix <: MatElem{RealFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[(i-1)*c+j]) + set!(el, arr[(i-1)*c+j]) end end return z @@ -844,7 +844,7 @@ mutable struct RealMatrix <: MatElem{RealFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[i, j], prec) + set!(el, arr[i, j], prec) end end return z @@ -855,7 +855,7 @@ mutable struct RealMatrix <: MatElem{RealFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[(i-1)*c+j], prec) + set!(el, arr[(i-1)*c+j], prec) end end return z @@ -910,7 +910,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[i, j]) + set!(el, arr[i, j]) end end return z @@ -921,7 +921,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[(i-1)*c+j]) + set!(el, arr[(i-1)*c+j]) end end return z @@ -932,7 +932,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[i, j], prec) + set!(el, arr[i, j], prec) end end return z @@ -943,7 +943,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _arb_set(el, arr[(i-1)*c+j], prec) + set!(el, arr[(i-1)*c+j], prec) end end return z @@ -1016,7 +1016,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j]) + set!(el, arr[i, j]) end end return z @@ -1027,7 +1027,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j]) + set!(el, arr[i, j]) end end return z @@ -1038,7 +1038,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j]) + set!(el, arr[(i-1)*c+j]) end end return z @@ -1049,7 +1049,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j]) + set!(el, arr[(i-1)*c+j]) end end return z @@ -1060,7 +1060,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j], prec) + set!(el, arr[i, j], prec) end end return z @@ -1071,7 +1071,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j], prec) + set!(el, arr[i, j], prec) end end return z @@ -1082,7 +1082,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j], prec) + set!(el, arr[(i-1)*c+j], prec) end end return z @@ -1093,7 +1093,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j], prec) + set!(el, arr[(i-1)*c+j], prec) end end return z @@ -1104,7 +1104,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j][1], arr[i,j][2], prec) + set!(el, arr[i, j][1], arr[i,j][2], prec) end end return z @@ -1115,7 +1115,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j][1], arr[i,j][2], prec) + set!(el, arr[i, j][1], arr[i,j][2], prec) end end return z @@ -1126,7 +1126,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) + set!(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) end end return z @@ -1137,7 +1137,7 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) + set!(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) end end return z @@ -1206,7 +1206,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j]) + set!(el, arr[i, j]) end end return z @@ -1217,7 +1217,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j]) + set!(el, arr[i, j]) end end return z @@ -1228,7 +1228,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j]) + set!(el, arr[(i-1)*c+j]) end end return z @@ -1239,7 +1239,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j]) + set!(el, arr[(i-1)*c+j]) end end return z @@ -1250,7 +1250,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j], prec) + set!(el, arr[i, j], prec) end end return z @@ -1261,7 +1261,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j], prec) + set!(el, arr[i, j], prec) end end return z @@ -1272,7 +1272,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j], prec) + set!(el, arr[(i-1)*c+j], prec) end end return z @@ -1283,7 +1283,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j], prec) + set!(el, arr[(i-1)*c+j], prec) end end return z @@ -1294,7 +1294,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j][1], arr[i,j][2], prec) + set!(el, arr[i, j][1], arr[i,j][2], prec) end end return z @@ -1305,7 +1305,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[i, j][1], arr[i,j][2], prec) + set!(el, arr[i, j][1], arr[i,j][2], prec) end end return z @@ -1316,7 +1316,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) + set!(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) end end return z @@ -1327,7 +1327,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} GC.@preserve z for i = 1:r for j = 1:c el = mat_entry_ptr(z, i, j) - _acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) + set!(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec) end end return z diff --git a/src/arb/Complex.jl b/src/arb/Complex.jl index 4f26a1680..db41ea5ee 100644 --- a/src/arb/Complex.jl +++ b/src/arb/Complex.jl @@ -75,8 +75,8 @@ 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) + re = _real_ptr(x) + im = _imag_ptr(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) # 4 == round to nearest @@ -1616,135 +1616,127 @@ end # ################################################################################ -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)) - @eval begin - function _acb_set(x::($typeofx), y::($t)) - ccall(($f, libflint), Nothing, (($passtoc), ($t)), x, y) - end - - function _acb_set(x::($typeofx), y::($t), p::Int) - _acb_set(x, y) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end - end - 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 (f,t) in (("acb_set_si", Int), ("acb_set_ui", UInt), ("acb_set_d", Float64)) @eval begin - function _acb_set(x::($typeofx), y::ZZRingElem) - ccall((:acb_set_fmpz, libflint), Nothing, (($passtoc), Ref{ZZRingElem}), x, y) + function set!(x::ComplexFieldElemOrPtr, y::$t) + @ccall libflint.$f(x::Ref{ComplexFieldElem}, y::$t)::Nothing end - function _acb_set(x::($typeofx), y::ZZRingElem, p::Int) - ccall((:acb_set_round_fmpz, libflint), Nothing, - (($passtoc), Ref{ZZRingElem}, Int), x, y, p) + function set!(x::ComplexFieldElemOrPtr, y::$t, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{ComplexFieldElem}, x::Ref{ComplexFieldElem}, p::Int)::Nothing end + end +end - function _acb_set(x::($typeofx), y::QQFieldElem, p::Int) - ccall((:acb_set_fmpq, libflint), Nothing, - (($passtoc), Ref{QQFieldElem}, Int), x, y, p) - end +function set!(x::ComplexFieldElemOrPtr, y::ZZRingElemOrPtr) + @ccall libflint.acb_set_fmpz(x::Ref{ComplexFieldElem}, y::Ref{ZZRingElem})::Nothing +end - function _acb_set(x::($typeofx), y::RealFieldElem) - ccall((:acb_set_arb, libflint), Nothing, (($passtoc), Ref{RealFieldElem}), x, y) - end +function set!(x::ComplexFieldElemOrPtr, y::ZZRingElemOrPtr, p::Int) + @ccall libflint.acb_set_round_fmpz(x::Ref{ComplexFieldElem}, y::Ref{ZZRingElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::RealFieldElem, p::Int) - _acb_set(x, y) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::ComplexFieldElemOrPtr, y::QQFieldElemOrPtr, p::Int) + @ccall libflint.acb_set_fmpq(x::Ref{ComplexFieldElem}, y::Ref{QQFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::ComplexFieldElem) - ccall((:acb_set, libflint), Nothing, (($passtoc), Ref{ComplexFieldElem}), x, y) - end +function set!(x::ComplexFieldElemOrPtr, y::RealFieldElemOrPtr) + @ccall libflint.acb_set_arb(x::Ref{ComplexFieldElem}, y::Ref{RealFieldElem})::Nothing +end - function _acb_set(x::($typeofx), y::ComplexFieldElem, p::Int) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), Ref{ComplexFieldElem}, Int), x, y, p) - end +function set!(x::ComplexFieldElemOrPtr, y::RealFieldElemOrPtr, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{ComplexFieldElem}, x::Ref{ComplexFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::AbstractString, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::ComplexFieldElemOrPtr, y::ComplexFieldElemOrPtr) + @ccall libflint.acb_set(x::Ref{ComplexFieldElem}, y::Ref{ComplexFieldElem})::Nothing +end - function _acb_set(x::($typeofx), y::BigFloat) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(r, y) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::ComplexFieldElemOrPtr, y::ComplexFieldElemOrPtr, p::Int) + @ccall libflint.acb_set_round(x::Ref{ComplexFieldElem}, y::Ref{ComplexFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::BigFloat, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::ComplexFieldElemOrPtr, y::AbstractString, p::Int) + r = _real_ptr(x) + set!(r, y, p) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::Int, z::Int, p::Int) - ccall((:acb_set_si_si, libflint), Nothing, - (($passtoc), Int, Int), x, y, z) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::ComplexFieldElemOrPtr, y::BigFloat) + r = _real_ptr(x) + set!(r, y) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::RealFieldElem, z::RealFieldElem) - ccall((:acb_set_arb_arb, libflint), Nothing, - (($passtoc), Ref{RealFieldElem}, Ref{RealFieldElem}), x, y, z) - end +function set!(x::ComplexFieldElemOrPtr, y::BigFloat, p::Int) + r = _real_ptr(x) + set!(r, y, p) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::RealFieldElem, z::RealFieldElem, p::Int) - _acb_set(x, y, z) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::ComplexFieldElemOrPtr, y::Real, p::Int) + r = _real_ptr(x) + set!(r, y, p) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::QQFieldElem, z::QQFieldElem, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(i, z, p) - end +function set!(x::ComplexFieldElemOrPtr, y::Tuple{Int, Int}, p::Int) + @ccall libflint.acb_set_si_si(x::Ref{ComplexFieldElem}, y[1]::Int, y[2]::Int)::Nothing +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) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(i, z, p) - end +function set!(x::ComplexFieldElemOrPtr, y::Tuple{Int, Int}, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{ComplexFieldElem}, x::Ref{ComplexFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::Real, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::ComplexFieldElemOrPtr, y::Tuple{RealFieldElemOrPtr, RealFieldElemOrPtr}) + @ccall libflint.acb_set_arb_arb(x::Ref{ComplexFieldElem}, y[1]::Ref{RealFieldElem}, y[2]::Ref{RealFieldElem})::Nothing +end - function _acb_set(x::($typeofx), y::Complex, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(r, real(y), p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(i, imag(y), p) - end +function set!(x::ComplexFieldElemOrPtr, y::Tuple{RealFieldElemOrPtr, RealFieldElemOrPtr}, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{ComplexFieldElem}, x::Ref{ComplexFieldElem}, p::Int)::Nothing +end - end +function set!(x::ComplexFieldElemOrPtr, y::Tuple{QQFieldElemOrPtr, QQFieldElemOrPtr}, p::Int) + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) +end - 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) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - _arb_set(i, z, p) - end - end - end +function set!(x::ComplexFieldElemOrPtr, y::Tuple{T, T}, p::Int) where {T <: AbstractString} + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) +end + +function set!(x::ComplexFieldElemOrPtr, y::Complex, p::Int) + set!(x, (real(y), imag(y)), p) +end + +function set!(x::ComplexFieldElemOrPtr, y::Tuple{Real, Real}, p::Int) + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) +end + +function set!(x::ComplexFieldElemOrPtr, y::Tuple{ZZRingElemOrPtr, ZZRingElemOrPtr}, p::Int) + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) end ############################################################################### diff --git a/src/arb/ComplexMat.jl b/src/arb/ComplexMat.jl index 2fe4be9a3..45522f963 100644 --- a/src/arb/ComplexMat.jl +++ b/src/arb/ComplexMat.jl @@ -53,7 +53,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, RealFieldElem, BigFloat, Co GC.@preserve x begin z = mat_entry_ptr(x, r, c) - _acb_set(z, y, precision(Balls)) + set!(z, y, precision(Balls)) end end end @@ -70,7 +70,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, RealFieldElem, BigFloat, Ab GC.@preserve x begin z = mat_entry_ptr(x, r, c) - _acb_set(z, y[1], y[2], precision(Balls)) + set!(z, y[1], y[2], precision(Balls)) end end end diff --git a/src/arb/Real.jl b/src/arb/Real.jl index 6f1012a2a..d1fe2fc99 100644 --- a/src/arb/Real.jl +++ b/src/arb/Real.jl @@ -1957,89 +1957,74 @@ end # ################################################################################ -for (typeofx, passtoc) in ((RealFieldElem, Ref{RealFieldElem}), (Ptr{RealFieldElem}, Ptr{RealFieldElem})) - for (f,t) in (("arb_set_si", Int), ("arb_set_ui", UInt), - ("arb_set_d", Float64)) - @eval begin - function _arb_set(x::($typeofx), y::($t)) - ccall(($f, libflint), Nothing, (($passtoc), ($t)), x, y) - end - - function _arb_set(x::($typeofx), y::($t), p::Int) - _arb_set(x, y) - ccall((:arb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end - end - end - +for (f,t) in (("arb_set_si", Int), ("arb_set_ui", UInt), ("arb_set_d", Float64)) @eval begin - function _arb_set(x::($typeofx), y::ZZRingElem) - ccall((:arb_set_fmpz, libflint), Nothing, (($passtoc), Ref{ZZRingElem}), x, y) + function set!(x::RealFieldElemOrPtr, y::$t) + @ccall libflint.$f(x::Ref{RealFieldElem}, y::$t)::Nothing end - function _arb_set(x::($typeofx), y::ZZRingElem, p::Int) - ccall((:arb_set_round_fmpz, libflint), Nothing, - (($passtoc), Ref{ZZRingElem}, Int), x, y, p) + function set!(x::RealFieldElemOrPtr, y::$t, p::Int) + set!(x, y) + @ccall libflint.arb_set_round(x::Ref{RealFieldElem}, x::Ref{RealFieldElem}, p::Int)::Nothing end + end +end - function _arb_set(x::($typeofx), y::QQFieldElem, p::Int) - ccall((:arb_set_fmpq, libflint), Nothing, - (($passtoc), Ref{QQFieldElem}, Int), x, y, p) - end +function set!(x::RealFieldElemOrPtr, y::ZZRingElemOrPtr) + @ccall libflint.arb_set_fmpz(x::Ref{RealFieldElem}, y::Ref{ZZRingElem})::Nothing +end - function _arb_set(x::($typeofx), y::RealFieldElem) - ccall((:arb_set, libflint), Nothing, (($passtoc), Ref{RealFieldElem}), x, y) - end +function set!(x::RealFieldElemOrPtr, y::ZZRingElemOrPtr, p::Int) + @ccall libflint.arb_set_round_fmpz(x::Ref{RealFieldElem}, y::Ref{ZZRingElem}, p::Int)::Nothing +end - function _arb_set(x::($typeofx), y::RealFieldElem, p::Int) - ccall((:arb_set_round, libflint), Nothing, - (($passtoc), Ref{RealFieldElem}, Int), x, y, p) - end +function set!(x::RealFieldElemOrPtr, y::QQFieldElemOrPtr, p::Int) + @ccall libflint.arb_set_fmpq(x::Ref{RealFieldElem}, y::Ref{QQFieldElem}, p::Int)::Nothing +end - function _arb_set(x::($typeofx), y::AbstractString, p::Int) - s = string(y) - err = ccall((:arb_set_str, libflint), Int32, - (($passtoc), Ptr{UInt8}, Int), x, s, p) - err == 0 || error("Invalid real string: $(repr(s))") - end +function set!(x::RealFieldElemOrPtr, y::RealFieldElemOrPtr) + @ccall libflint.arb_set(x::Ref{RealFieldElem}, y::Ref{RealFieldElem})::Nothing +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) - ccall((:arf_set_mpfr, libflint), Nothing, - (Ptr{arf_struct}, Ref{BigFloat}), m, y) - ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) - end +function set!(x::RealFieldElemOrPtr, y::RealFieldElemOrPtr, p::Int) + @ccall libflint.arb_set_round(x::Ref{RealFieldElem}, y::Ref{RealFieldElem}, p::Int)::Nothing +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) - ccall((:arf_set_mpfr, libflint), Nothing, - (Ptr{arf_struct}, Ref{BigFloat}), m, y) - ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) - ccall((:arb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::RealFieldElemOrPtr, y::AbstractString, p::Int) + s = string(y) + err = @ccall libflint.arb_set_str(x::Ref{RealFieldElem}, s::Ptr{UInt8}, p::Int)::Int32 + err == 0 || error("Invalid real string: $(repr(s))") +end - function _arb_set(x::($typeofx), y::Integer) - _arb_set(x, ZZRingElem(y)) - end +function set!(x::RealFieldElemOrPtr, y::BigFloat) + m = @ccall libflint.arb_mid_ptr(x::Ref{RealFieldElem})::Ptr{arf_struct} + r = @ccall libflint.arb_rad_ptr(x::Ref{RealFieldElem})::Ptr{mag_struct} + @ccall libflint.arf_set_mpfr(m::Ptr{arf_struct}, y::Ref{BigFloat})::Nothing + @ccall libflint.mag_zero(r::Ptr{mag_struct})::Nothing +end - function _arb_set(x::($typeofx), y::Integer, p::Int) - _arb_set(x, ZZRingElem(y), p) - end +function set!(x::RealFieldElemOrPtr, y::BigFloat, p::Int) + m = @ccall libflint.arb_mid_ptr(x::Ref{RealFieldElem})::Ptr{arf_struct} + r = @ccall libflint.arb_rad_ptr(x::Ref{RealFieldElem})::Ptr{mag_struct} + @ccall libflint.arf_set_mpfr(m::Ptr{arf_struct}, y::Ref{BigFloat})::Nothing + @ccall libflint.mag_zero(r::Ptr{mag_struct})::Nothing + @ccall libflint.arb_set_round(x::Ref{RealFieldElem}, x::Ref{RealFieldElem}, p::Int)::Nothing +end - function _arb_set(x::($typeofx), y::Real) - _arb_set(x, BigFloat(y)) - end +function set!(x::RealFieldElemOrPtr, y::Integer) + set!(x, flintify(y)) +end - function _arb_set(x::($typeofx), y::Real, p::Int) - _arb_set(x, BigFloat(y), p) - end - end +function set!(x::RealFieldElemOrPtr, y::Integer, p::Int) + set!(x, flintify(y), p) +end + +function set!(x::RealFieldElemOrPtr, y::Real) + set!(x, BigFloat(y)) +end + +function set!(x::RealFieldElemOrPtr, y::Real, p::Int) + set!(x, BigFloat(y), p) end ################################################################################ diff --git a/src/arb/RealMat.jl b/src/arb/RealMat.jl index 5796bdd5f..08f7edc1f 100644 --- a/src/arb/RealMat.jl +++ b/src/arb/RealMat.jl @@ -30,7 +30,7 @@ dense_matrix_type(::Type{RealFieldElem}) = RealMatrix function getindex!(z::ArbFieldElem, x::RealMatrix, r::Int, c::Int) GC.@preserve x begin v = mat_entry_ptr(x, r, c) - ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ptr{RealFieldElem}), z, v) + set!(z, v) end return z end @@ -41,7 +41,7 @@ end z = base_ring(x)() GC.@preserve x begin v = mat_entry_ptr(x, r, c) - ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ptr{RealFieldElem}), z, v) + set!(z, v) end return z end @@ -53,7 +53,7 @@ for T in [Int, UInt, ZZRingElem, QQFieldElem, Float64, BigFloat, RealFieldElem, GC.@preserve x begin z = mat_entry_ptr(x, r, c) - _arb_set(z, y, precision(Balls)) + set!(z, y, precision(Balls)) end end end diff --git a/src/arb/acb.jl b/src/arb/acb.jl index a0e33edec..7c63851a9 100644 --- a/src/arb/acb.jl +++ b/src/arb/acb.jl @@ -85,8 +85,8 @@ 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) + re = _real_ptr(x) + im = _imag_ptr(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) # 4 == round to nearest @@ -1611,135 +1611,127 @@ end # ################################################################################ -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)) - @eval begin - function _acb_set(x::($typeofx), y::($t)) - ccall(($f, libflint), Nothing, (($passtoc), ($t)), x, y) - end - - function _acb_set(x::($typeofx), y::($t), p::Int) - _acb_set(x, y) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end - end - 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 (f,t) in (("acb_set_si", Int), ("acb_set_ui", UInt), ("acb_set_d", Float64)) @eval begin - function _acb_set(x::($typeofx), y::ZZRingElem) - ccall((:acb_set_fmpz, libflint), Nothing, (($passtoc), Ref{ZZRingElem}), x, y) + function set!(x::AcbFieldElemOrPtr, y::$t) + @ccall libflint.$f(x::Ref{AcbFieldElem}, y::$t)::Nothing end - function _acb_set(x::($typeofx), y::ZZRingElem, p::Int) - ccall((:acb_set_round_fmpz, libflint), Nothing, - (($passtoc), Ref{ZZRingElem}, Int), x, y, p) + function set!(x::AcbFieldElemOrPtr, y::$t, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{AcbFieldElem}, x::Ref{AcbFieldElem}, p::Int)::Nothing end + end +end - function _acb_set(x::($typeofx), y::QQFieldElem, p::Int) - ccall((:acb_set_fmpq, libflint), Nothing, - (($passtoc), Ref{QQFieldElem}, Int), x, y, p) - end +function set!(x::AcbFieldElemOrPtr, y::ZZRingElemOrPtr) + @ccall libflint.acb_set_fmpz(x::Ref{AcbFieldElem}, y::Ref{ZZRingElem})::Nothing +end - function _acb_set(x::($typeofx), y::ArbFieldElem) - ccall((:acb_set_arb, libflint), Nothing, (($passtoc), Ref{ArbFieldElem}), x, y) - end +function set!(x::AcbFieldElemOrPtr, y::ZZRingElemOrPtr, p::Int) + @ccall libflint.acb_set_round_fmpz(x::Ref{AcbFieldElem}, y::Ref{ZZRingElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::ArbFieldElem, p::Int) - _acb_set(x, y) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::AcbFieldElemOrPtr, y::QQFieldElemOrPtr, p::Int) + @ccall libflint.acb_set_fmpq(x::Ref{AcbFieldElem}, y::Ref{QQFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::AcbFieldElem) - ccall((:acb_set, libflint), Nothing, (($passtoc), Ref{AcbFieldElem}), x, y) - end +function set!(x::AcbFieldElemOrPtr, y::ArbFieldElemOrPtr) + @ccall libflint.acb_set_arb(x::Ref{AcbFieldElem}, y::Ref{ArbFieldElem})::Nothing +end - function _acb_set(x::($typeofx), y::AcbFieldElem, p::Int) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), Ref{AcbFieldElem}, Int), x, y, p) - end +function set!(x::AcbFieldElemOrPtr, y::ArbFieldElemOrPtr, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{AcbFieldElem}, x::Ref{AcbFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::AbstractString, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::AcbFieldElemOrPtr, y::AcbFieldElemOrPtr) + @ccall libflint.acb_set(x::Ref{AcbFieldElem}, y::Ref{AcbFieldElem})::Nothing +end - function _acb_set(x::($typeofx), y::BigFloat) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(r, y) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::AcbFieldElemOrPtr, y::AcbFieldElemOrPtr, p::Int) + @ccall libflint.acb_set_round(x::Ref{AcbFieldElem}, y::Ref{AcbFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::BigFloat, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::AcbFieldElemOrPtr, y::AbstractString, p::Int) + r = _real_ptr(x) + set!(r, y, p) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::Int, z::Int, p::Int) - ccall((:acb_set_si_si, libflint), Nothing, - (($passtoc), Int, Int), x, y, z) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::AcbFieldElemOrPtr, y::BigFloat) + r = _real_ptr(x) + set!(r, y) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::ArbFieldElem, z::ArbFieldElem) - ccall((:acb_set_arb_arb, libflint), Nothing, - (($passtoc), Ref{ArbFieldElem}, Ref{ArbFieldElem}), x, y, z) - end +function set!(x::AcbFieldElemOrPtr, y::BigFloat, p::Int) + r = _real_ptr(x) + set!(r, y, p) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::ArbFieldElem, z::ArbFieldElem, p::Int) - _acb_set(x, y, z) - ccall((:acb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::AcbFieldElemOrPtr, y::Real, p::Int) + r = _real_ptr(x) + set!(r, y, p) + i = _imag_ptr(x) + zero!(i) +end - function _acb_set(x::($typeofx), y::QQFieldElem, z::QQFieldElem, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(i, z, p) - end +function set!(x::AcbFieldElemOrPtr, y::Tuple{Int, Int}) + @ccall libflint.acb_set_si_si(x::Ref{AcbFieldElem}, y[1]::Int, y[2]::Int)::Nothing +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) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(i, z, p) - end +function set!(x::AcbFieldElemOrPtr, y::Tuple{Int, Int}, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{AcbFieldElem}, x::Ref{AcbFieldElem}, p::Int)::Nothing +end - function _acb_set(x::($typeofx), y::Real, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - zero!(i) - end +function set!(x::AcbFieldElemOrPtr, y::Tuple{ArbFieldElemOrPtr, ArbFieldElemOrPtr}) + @ccall libflint.acb_set_arb_arb(x::Ref{AcbFieldElem}, y[1]::Ref{ArbFieldElem}, y[2]::Ref{ArbFieldElem})::Nothing +end - function _acb_set(x::($typeofx), y::Complex, p::Int) - r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(r, real(y), p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(i, imag(y), p) - end +function set!(x::AcbFieldElemOrPtr, y::Tuple{ArbFieldElemOrPtr, ArbFieldElemOrPtr}, p::Int) + set!(x, y) + @ccall libflint.acb_set_round(x::Ref{AcbFieldElem}, x::Ref{AcbFieldElem}, p::Int)::Nothing +end - end +function set!(x::AcbFieldElemOrPtr, y::Tuple{QQFieldElemOrPtr, QQFieldElemOrPtr}, p::Int) + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) +end - 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) - _arb_set(r, y, p) - i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - _arb_set(i, z, p) - end - end - end +function set!(x::AcbFieldElemOrPtr, y::Tuple{T, T}, p::Int) where {T <: AbstractString} + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) +end + +function set!(x::AcbFieldElemOrPtr, y::Complex, p::Int) + set!(x, (real(y), imag(y)), p) +end + +function set!(x::AcbFieldElemOrPtr, y::Tuple{Real, Real}, p::Int) + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) +end + +function set!(x::AcbFieldElemOrPtr, y::Tuple{ZZRingElemOrPtr, ZZRingElemOrPtr}, p::Int) + r = _real_ptr(x) + set!(r, y[1], p) + i = _imag_ptr(x) + set!(i, y[2], p) end ############################################################################### diff --git a/src/arb/acb_mat.jl b/src/arb/acb_mat.jl index 925442d07..488e72ed7 100644 --- a/src/arb/acb_mat.jl +++ b/src/arb/acb_mat.jl @@ -56,7 +56,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, ArbFieldElem, BigFloat, Acb GC.@preserve x begin z = mat_entry_ptr(x, r, c) - _acb_set(z, y, precision(base_ring(x))) + set!(z, y, precision(base_ring(x))) end end end @@ -73,7 +73,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, ArbFieldElem, BigFloat, Abs GC.@preserve x begin z = mat_entry_ptr(x, r, c) - _acb_set(z, y[1], y[2], precision(base_ring(x))) + set!(z, y[1], y[2], precision(base_ring(x))) end end end diff --git a/src/arb/arb.jl b/src/arb/arb.jl index 5f64190db..ce6b865ba 100644 --- a/src/arb/arb.jl +++ b/src/arb/arb.jl @@ -1965,89 +1965,74 @@ end # ################################################################################ -for (typeofx, passtoc) in ((ArbFieldElem, Ref{ArbFieldElem}), (Ptr{ArbFieldElem}, Ptr{ArbFieldElem})) - for (f,t) in (("arb_set_si", Int), ("arb_set_ui", UInt), - ("arb_set_d", Float64)) - @eval begin - function _arb_set(x::($typeofx), y::($t)) - ccall(($f, libflint), Nothing, (($passtoc), ($t)), x, y) - end - - function _arb_set(x::($typeofx), y::($t), p::Int) - _arb_set(x, y) - ccall((:arb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end - end - end - +for (f,t) in (("arb_set_si", Int), ("arb_set_ui", UInt), ("arb_set_d", Float64)) @eval begin - function _arb_set(x::($typeofx), y::ZZRingElem) - ccall((:arb_set_fmpz, libflint), Nothing, (($passtoc), Ref{ZZRingElem}), x, y) + function set!(x::ArbFieldElemOrPtr, y::$t) + @ccall libflint.$f(x::Ref{ArbFieldElem}, y::$t)::Nothing end - function _arb_set(x::($typeofx), y::ZZRingElem, p::Int) - ccall((:arb_set_round_fmpz, libflint), Nothing, - (($passtoc), Ref{ZZRingElem}, Int), x, y, p) + function set!(x::ArbFieldElemOrPtr, y::$t, p::Int) + set!(x, y) + @ccall libflint.arb_set_round(x::Ref{ArbFieldElem}, x::Ref{ArbFieldElem}, p::Int)::Nothing end + end +end - function _arb_set(x::($typeofx), y::QQFieldElem, p::Int) - ccall((:arb_set_fmpq, libflint), Nothing, - (($passtoc), Ref{QQFieldElem}, Int), x, y, p) - end +function set!(x::ArbFieldElemOrPtr, y::ZZRingElemOrPtr) + @ccall libflint.arb_set_fmpz(x::Ref{ArbFieldElem}, y::Ref{ZZRingElem})::Nothing +end - function _arb_set(x::($typeofx), y::ArbFieldElem) - ccall((:arb_set, libflint), Nothing, (($passtoc), Ref{ArbFieldElem}), x, y) - end +function set!(x::ArbFieldElemOrPtr, y::ZZRingElemOrPtr, p::Int) + @ccall libflint.arb_set_round_fmpz(x::Ref{ArbFieldElem}, y::Ref{ZZRingElem}, p::Int)::Nothing +end - function _arb_set(x::($typeofx), y::ArbFieldElem, p::Int) - ccall((:arb_set_round, libflint), Nothing, - (($passtoc), Ref{ArbFieldElem}, Int), x, y, p) - end +function set!(x::ArbFieldElemOrPtr, y::QQFieldElemOrPtr, p::Int) + @ccall libflint.arb_set_fmpq(x::Ref{ArbFieldElem}, y::Ref{QQFieldElem}, p::Int)::Nothing +end - function _arb_set(x::($typeofx), y::AbstractString, p::Int) - s = string(y) - err = ccall((:arb_set_str, libflint), Int32, - (($passtoc), Ptr{UInt8}, Int), x, s, p) - err == 0 || error("Invalid real string: $(repr(s))") - end +function set!(x::ArbFieldElemOrPtr, y::ArbFieldElemOrPtr) + @ccall libflint.arb_set(x::Ref{ArbFieldElem}, y::Ref{ArbFieldElem})::Nothing +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) - ccall((:arf_set_mpfr, libflint), Nothing, - (Ptr{arf_struct}, Ref{BigFloat}), m, y) - ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) - end +function set!(x::ArbFieldElemOrPtr, y::ArbFieldElemOrPtr, p::Int) + @ccall libflint.arb_set_round(x::Ref{ArbFieldElem}, y::Ref{ArbFieldElem}, p::Int)::Nothing +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) - ccall((:arf_set_mpfr, libflint), Nothing, - (Ptr{arf_struct}, Ref{BigFloat}), m, y) - ccall((:mag_zero, libflint), Nothing, (Ptr{mag_struct}, ), r) - ccall((:arb_set_round, libflint), Nothing, - (($passtoc), ($passtoc), Int), x, x, p) - end +function set!(x::ArbFieldElemOrPtr, y::AbstractString, p::Int) + s = string(y) + err = @ccall libflint.arb_set_str(x::Ref{ArbFieldElem}, s::Ptr{UInt8}, p::Int)::Int32 + err == 0 || error("Invalid real string: $(repr(s))") +end - function _arb_set(x::($typeofx), y::Integer) - _arb_set(x, ZZRingElem(y)) - end +function set!(x::ArbFieldElemOrPtr, y::BigFloat) + m = @ccall libflint.arb_mid_ptr(x::Ref{ArbFieldElem})::Ptr{arf_struct} + r = @ccall libflint.arb_rad_ptr(x::Ref{ArbFieldElem})::Ptr{mag_struct} + @ccall libflint.arf_set_mpfr(m::Ptr{arf_struct}, y::Ref{BigFloat})::Nothing + @ccall libflint.mag_zero(r::Ptr{mag_struct})::Nothing +end - function _arb_set(x::($typeofx), y::Integer, p::Int) - _arb_set(x, ZZRingElem(y), p) - end +function set!(x::ArbFieldElemOrPtr, y::BigFloat, p::Int) + m = @ccall libflint.arb_mid_ptr(x::Ref{ArbFieldElem})::Ptr{arf_struct} + r = @ccall libflint.arb_rad_ptr(x::Ref{ArbFieldElem})::Ptr{mag_struct} + @ccall libflint.arf_set_mpfr(m::Ptr{arf_struct}, y::Ref{BigFloat})::Nothing + @ccall libflint.mag_zero(r::Ptr{mag_struct})::Nothing + @ccall libflint.arb_set_round(x::Ref{ArbFieldElem}, x::Ref{ArbFieldElem}, p::Int)::Nothing +end - function _arb_set(x::($typeofx), y::Real) - _arb_set(x, BigFloat(y)) - end +function set!(x::ArbFieldElemOrPtr, y::Integer) + set!(x, flintify(y)) +end - function _arb_set(x::($typeofx), y::Real, p::Int) - _arb_set(x, BigFloat(y), p) - end - end +function set!(x::ArbFieldElemOrPtr, y::Integer, p::Int) + set!(x, flintify(y), p) +end + +function set!(x::ArbFieldElemOrPtr, y::Real) + set!(x, BigFloat(y)) +end + +function set!(x::ArbFieldElemOrPtr, y::Real, p::Int) + set!(x, BigFloat(y), p) end ################################################################################ diff --git a/src/arb/arb_mat.jl b/src/arb/arb_mat.jl index bc934c458..ea48754fa 100644 --- a/src/arb/arb_mat.jl +++ b/src/arb/arb_mat.jl @@ -33,7 +33,7 @@ precision(x::ArbMatrixSpace) = precision(x.base_ring) function getindex!(z::ArbFieldElem, x::ArbMatrix, r::Int, c::Int) GC.@preserve x begin v = mat_entry_ptr(x, r, c) - ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ptr{ArbFieldElem}), z, v) + set!(z, v) end return z end @@ -44,7 +44,7 @@ end z = base_ring(x)() GC.@preserve x begin v = mat_entry_ptr(x, r, c) - ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ptr{ArbFieldElem}), z, v) + set!(z, v) end return z end @@ -56,7 +56,7 @@ for T in [Int, UInt, ZZRingElem, QQFieldElem, Float64, BigFloat, ArbFieldElem, A GC.@preserve x begin z = mat_entry_ptr(x, r, c) - _arb_set(z, y, precision(base_ring(x))) + set!(z, y, precision(base_ring(x))) end end end