Skip to content
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

Use _arb_set/_acb_set instead of ccall #1912

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arb/ArbTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mutable struct RealFieldElem <: FieldElem

function RealFieldElem(mid::RealFieldElem, rad::RealFieldElem)
z = RealFieldElem()
ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}), z, mid)
_arb_set(z, mid)
ccall((:arb_add_error, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}), z, rad)
return z
end
Expand Down Expand Up @@ -170,7 +170,7 @@ mutable struct ArbFieldElem <: FieldElem

function ArbFieldElem(mid::ArbFieldElem, rad::ArbFieldElem)
z = ArbFieldElem()
ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ref{ArbFieldElem}), z, mid)
_arb_set(z, mid)
ccall((:arb_add_error, libflint), Nothing, (Ref{ArbFieldElem}, Ref{ArbFieldElem}), z, rad)
return z
end
Expand Down
14 changes: 11 additions & 3 deletions src/arb/Complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end

function deepcopy_internal(a::ComplexFieldElem, dict::IdDict)
b = ComplexFieldElem()
ccall((:acb_set, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}), b, a)
_acb_set(b, a)
return b
end

Expand Down Expand Up @@ -1657,11 +1657,19 @@ for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{Compl
(($passtoc), ($passtoc), Int), x, x, p)
end

function _acb_set(x::($typeofx), y::ComplexFieldElem)
function _acb_set(x::($typeofx), y::ComplexFieldElemOrPtr)
ccall((:acb_set, libflint), Nothing, (($passtoc), Ref{ComplexFieldElem}), x, y)
end

function _acb_set(x::($typeofx), y::ComplexFieldElem, p::Int)
function _acb_set(x::($typeofx), y::Ptr{acb_struct})
ccall((:acb_set, libflint), Nothing, (($passtoc), Ptr{acb_struct}), x, y)
end

function _acb_set(x::Ptr{acb_struct}, y::($typeofx))
ccall((:acb_set, libflint), Nothing, (Ptr{acb_struct}, ($passtoc)) , x, y)
end

function _acb_set(x::($typeofx), y::ComplexFieldElemOrPtr, p::Int)
ccall((:acb_set_round, libflint), Nothing,
(($passtoc), Ref{ComplexFieldElem}, Int), x, y, p)
end
Expand Down
4 changes: 2 additions & 2 deletions src/arb/ComplexMat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
function getindex!(z::ComplexFieldElem, x::ComplexMatrix, r::Int, c::Int)
GC.@preserve x begin
v = mat_entry_ptr(x, r, c)
ccall((:acb_set, libflint), Nothing, (Ref{ComplexFieldElem}, Ptr{ComplexFieldElem}), z, v)
_acb_set(z, v)

Check warning on line 33 in src/arb/ComplexMat.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/ComplexMat.jl#L33

Added line #L33 was not covered by tests
end
return z
end
Expand All @@ -41,7 +41,7 @@
z = base_ring(x)()
GC.@preserve x begin
v = mat_entry_ptr(x, r, c)
ccall((:acb_set, libflint), Nothing, (Ref{ComplexFieldElem}, Ptr{ComplexFieldElem}), z, v)
_acb_set(z, v)
end
return z
end
Expand Down
10 changes: 4 additions & 6 deletions src/arb/ComplexPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,17 @@ end

function acb_vec(b::Vector{ComplexFieldElem})
v = ccall((:_acb_vec_init, libflint), Ptr{acb_struct}, (Int,), length(b))
for i=1:length(b)
ccall((:acb_set, libflint), Nothing, (Ptr{acb_struct}, Ref{ComplexFieldElem}),
v + (i-1)*sizeof(acb_struct), b[i])
for i in 1:length(b)
_acb_set(v + (i-1)*sizeof(acb_struct), b[i])
end
return v
end

function array(R::ComplexField, v::Ptr{acb_struct}, n::Int)
r = Vector{ComplexFieldElem}(undef, n)
for i=1:n
for i in 1:n
r[i] = R()
ccall((:acb_set, libflint), Nothing, (Ref{ComplexFieldElem}, Ptr{acb_struct}),
r[i], v + (i-1)*sizeof(acb_struct))
_acb_set(r[i], v + (i-1)*sizeof(acb_struct))
end
return r
end
Expand Down
14 changes: 11 additions & 3 deletions src/arb/Real.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

function deepcopy_internal(a::RealFieldElem, dict::IdDict)
b = parent(a)()
ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}), b, a)
_arb_set(b, a)
return b
end

Expand Down Expand Up @@ -1988,11 +1988,19 @@ for (typeofx, passtoc) in ((RealFieldElem, Ref{RealFieldElem}), (Ptr{RealFieldEl
(($passtoc), Ref{QQFieldElem}, Int), x, y, p)
end

function _arb_set(x::($typeofx), y::RealFieldElem)
function _arb_set(x::($typeofx), y::RealFieldElemOrPtr)
ccall((:arb_set, libflint), Nothing, (($passtoc), Ref{RealFieldElem}), x, y)
end

function _arb_set(x::($typeofx), y::RealFieldElem, p::Int)
function _arb_set(x::($typeofx), y::Ptr{arb_struct})
ccall((:arb_set, libflint), Nothing, (($passtoc), Ptr{arb_struct}), x, y)
end

function _arb_set(x::Ptr{arb_struct}, y::($typeofx))
ccall((:arb_set, libflint), Nothing, (Ptr{arb_struct}, ($passtoc)) , x, y)
end

function _arb_set(x::($typeofx), y::RealFieldElemOrPtr, p::Int)
ccall((:arb_set_round, libflint), Nothing,
(($passtoc), Ref{RealFieldElem}, Int), x, y, p)
end
Expand Down
4 changes: 2 additions & 2 deletions src/arb/RealMat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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)
_arb_set(z, v)

Check warning on line 33 in src/arb/RealMat.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/RealMat.jl#L33

Added line #L33 was not covered by tests
end
return z
end
Expand All @@ -41,7 +41,7 @@
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)
_arb_set(z, v)
end
return z
end
Expand Down
10 changes: 4 additions & 6 deletions src/arb/RealPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,17 @@ end

function arb_vec(b::Vector{RealFieldElem})
v = ccall((:_arb_vec_init, libflint), Ptr{arb_struct}, (Int,), length(b))
for i=1:length(b)
ccall((:arb_set, libflint), Nothing, (Ptr{arb_struct}, Ref{RealFieldElem}),
v + (i-1)*sizeof(arb_struct), b[i])
for i in 1:length(b)
_arb_set(v + (i-1)*sizeof(arb_struct), b[i])
end
return v
end

function array(R::RealField, v::Ptr{arb_struct}, n::Int)
r = Vector{RealFieldElem}(undef, n)
for i=1:n
for i in 1:n
r[i] = R()
ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ptr{arb_struct}),
r[i], v + (i-1)*sizeof(arb_struct))
_arb_set(r[i], v + (i-1)*sizeof(arb_struct))
end
return r
end
Expand Down
14 changes: 11 additions & 3 deletions src/arb/acb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end

function deepcopy_internal(a::AcbFieldElem, dict::IdDict)
b = parent(a)()
ccall((:acb_set, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}), b, a)
_acb_set(b, a)
return b
end

Expand Down Expand Up @@ -1652,11 +1652,19 @@ for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem}
(($passtoc), ($passtoc), Int), x, x, p)
end

function _acb_set(x::($typeofx), y::AcbFieldElem)
function _acb_set(x::($typeofx), y::AcbFieldElemOrPtr)
ccall((:acb_set, libflint), Nothing, (($passtoc), Ref{AcbFieldElem}), x, y)
end

function _acb_set(x::($typeofx), y::AcbFieldElem, p::Int)
function _acb_set(x::($typeofx), y::Ptr{acb_struct})
ccall((:acb_set, libflint), Nothing, (($passtoc), Ptr{acb_struct}), x, y)
end

function _acb_set(x::Ptr{acb_struct}, y::($typeofx))
ccall((:acb_set, libflint), Nothing, (Ptr{acb_struct}, ($passtoc)) , x, y)
end

function _acb_set(x::($typeofx), y::AcbFieldElemOrPtr, p::Int)
ccall((:acb_set_round, libflint), Nothing,
(($passtoc), Ref{AcbFieldElem}, Int), x, y, p)
end
Expand Down
2 changes: 1 addition & 1 deletion src/arb/acb_calc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function acb_calc_func_wrap(res::Ptr{ComplexFieldElem}, x::Ptr{ComplexFieldElem}
xx = unsafe_load(x)
F = unsafe_pointer_to_objref(param)
w = F(xx)
ccall((:acb_set, libflint), Ptr{Nothing}, (Ptr{ComplexFieldElem}, Ref{ComplexFieldElem}), res, w)
_acb_set(res, w)
return zero(Cint)
end

Expand Down
4 changes: 2 additions & 2 deletions src/arb/acb_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
function getindex!(z::AcbFieldElem, x::AcbMatrix, r::Int, c::Int)
GC.@preserve x begin
v = mat_entry_ptr(x, r, c)
ccall((:acb_set, libflint), Nothing, (Ref{AcbFieldElem}, Ptr{AcbFieldElem}), z, v)
_acb_set(z, v)

Check warning on line 36 in src/arb/acb_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/acb_mat.jl#L36

Added line #L36 was not covered by tests
end
return z
end
Expand All @@ -44,7 +44,7 @@
z = base_ring(x)()
GC.@preserve x begin
v = mat_entry_ptr(x, r, c)
ccall((:acb_set, libflint), Nothing, (Ref{AcbFieldElem}, Ptr{AcbFieldElem}), z, v)
_acb_set(z, v)
end
return z
end
Expand Down
10 changes: 4 additions & 6 deletions src/arb/acb_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,17 @@ end

function acb_vec(b::Vector{AcbFieldElem})
v = ccall((:_acb_vec_init, libflint), Ptr{acb_struct}, (Int,), length(b))
for i=1:length(b)
ccall((:acb_set, libflint), Nothing, (Ptr{acb_struct}, Ref{AcbFieldElem}),
v + (i-1)*sizeof(acb_struct), b[i])
for i in 1:length(b)
_acb_set(v + (i-1)*sizeof(acb_struct), b[i])
end
return v
end

function array(R::AcbField, v::Ptr{acb_struct}, n::Int)
r = Vector{AcbFieldElem}(undef, n)
for i=1:n
for i in 1:n
r[i] = R()
ccall((:acb_set, libflint), Nothing, (Ref{AcbFieldElem}, Ptr{acb_struct}),
r[i], v + (i-1)*sizeof(acb_struct))
_acb_set(r[i], v + (i-1)*sizeof(acb_struct))
end
return r
end
Expand Down
14 changes: 11 additions & 3 deletions src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

function deepcopy_internal(a::ArbFieldElem, dict::IdDict)
b = parent(a)()
ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ref{ArbFieldElem}), b, a)
_arb_set(b, a)
return b
end

Expand Down Expand Up @@ -1996,11 +1996,19 @@ for (typeofx, passtoc) in ((ArbFieldElem, Ref{ArbFieldElem}), (Ptr{ArbFieldElem}
(($passtoc), Ref{QQFieldElem}, Int), x, y, p)
end

function _arb_set(x::($typeofx), y::ArbFieldElem)
function _arb_set(x::($typeofx), y::ArbFieldElemOrPtr)
ccall((:arb_set, libflint), Nothing, (($passtoc), Ref{ArbFieldElem}), x, y)
end

function _arb_set(x::($typeofx), y::ArbFieldElem, p::Int)
function _arb_set(x::($typeofx), y::Ptr{arb_struct})
ccall((:arb_set, libflint), Nothing, (($passtoc), Ptr{arb_struct}), x, y)
end

function _arb_set(x::Ptr{arb_struct}, y::($typeofx))
ccall((:arb_set, libflint), Nothing, (Ptr{arb_struct}, ($passtoc)) , x, y)
end

function _arb_set(x::($typeofx), y::ArbFieldElemOrPtr, p::Int)
ccall((:arb_set_round, libflint), Nothing,
(($passtoc), Ref{ArbFieldElem}, Int), x, y, p)
end
Expand Down
4 changes: 2 additions & 2 deletions src/arb/arb_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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)
_arb_set(z, v)

Check warning on line 36 in src/arb/arb_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/arb_mat.jl#L36

Added line #L36 was not covered by tests
end
return z
end
Expand All @@ -44,7 +44,7 @@
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)
_arb_set(z, v)
end
return z
end
Expand Down
10 changes: 4 additions & 6 deletions src/arb/arb_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,17 @@ end

function arb_vec(b::Vector{ArbFieldElem})
v = ccall((:_arb_vec_init, libflint), Ptr{arb_struct}, (Int,), length(b))
for i=1:length(b)
ccall((:arb_set, libflint), Nothing, (Ptr{arb_struct}, Ref{ArbFieldElem}),
v + (i-1)*sizeof(arb_struct), b[i])
for i in 1:length(b)
_arb_set(v + (i-1)*sizeof(arb_struct), b[i])
end
return v
end

function array(R::ArbField, v::Ptr{arb_struct}, n::Int)
r = Vector{ArbFieldElem}(undef, n)
for i=1:n
for i in 1:n
r[i] = R()
ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ptr{arb_struct}),
r[i], v + (i-1)*sizeof(arb_struct))
_arb_set(r[i], v + (i-1)*sizeof(arb_struct))
end
return r
end
Expand Down
Loading