Skip to content

Commit

Permalink
Add mat_entry_ptr for arb matrix types (#1829)
Browse files Browse the repository at this point in the history
* Add `mat_entry_ptr` for `AcbMatrix`

* Add `mat_entry_ptr` for `ComplexMat`

* Add `mat_entry_ptr` for `ArbMatrix`

* Add `mat_entry_ptr` for `RealMat`
  • Loading branch information
lgoettgens authored Jul 16, 2024
1 parent 088d70c commit bb1a9fa
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 92 deletions.
96 changes: 32 additions & 64 deletions src/arb/ArbTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,7 @@ mutable struct RealMat <: MatElem{RealFieldElem}
z = RealMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem},
(Ref{RealMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[i, j])
end
end
Expand All @@ -833,8 +832,7 @@ mutable struct RealMat <: MatElem{RealFieldElem}
z = RealMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem},
(Ref{RealMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[(i-1)*c+j])
end
end
Expand All @@ -845,8 +843,7 @@ mutable struct RealMat <: MatElem{RealFieldElem}
z = RealMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem},
(Ref{RealMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[i, j], prec)
end
end
Expand All @@ -857,8 +854,7 @@ mutable struct RealMat <: MatElem{RealFieldElem}
z = RealMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem},
(Ref{RealMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[(i-1)*c+j], prec)
end
end
Expand Down Expand Up @@ -913,8 +909,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem}
z = ArbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem},
(Ref{ArbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[i, j])
end
end
Expand All @@ -925,8 +920,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem}
z = ArbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem},
(Ref{ArbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[(i-1)*c+j])
end
end
Expand All @@ -937,8 +931,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem}
z = ArbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem},
(Ref{ArbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[i, j], prec)
end
end
Expand All @@ -949,8 +942,7 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem}
z = ArbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem},
(Ref{ArbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_arb_set(el, arr[(i-1)*c+j], prec)
end
end
Expand Down Expand Up @@ -1023,8 +1015,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j])
end
end
Expand All @@ -1035,8 +1026,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j])
end
end
Expand All @@ -1047,8 +1037,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j])
end
end
Expand All @@ -1059,8 +1048,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j])
end
end
Expand All @@ -1071,8 +1059,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j], prec)
end
end
Expand All @@ -1083,8 +1070,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j], prec)
end
end
Expand All @@ -1095,8 +1081,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j], prec)
end
end
Expand All @@ -1107,8 +1092,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j], prec)
end
end
Expand All @@ -1119,8 +1103,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j][1], arr[i,j][2], prec)
end
end
Expand All @@ -1131,8 +1114,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j][1], arr[i,j][2], prec)
end
end
Expand All @@ -1143,8 +1125,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec)
end
end
Expand All @@ -1155,8 +1136,7 @@ mutable struct ComplexMat <: MatElem{ComplexFieldElem}
z = ComplexMat(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec)
end
end
Expand Down Expand Up @@ -1225,8 +1205,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j])
end
end
Expand All @@ -1237,8 +1216,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j])
end
end
Expand All @@ -1249,8 +1227,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j])
end
end
Expand All @@ -1261,8 +1238,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j])
end
end
Expand All @@ -1273,8 +1249,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j], prec)
end
end
Expand All @@ -1285,8 +1260,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j], prec)
end
end
Expand All @@ -1297,8 +1271,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j], prec)
end
end
Expand All @@ -1309,8 +1282,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j], prec)
end
end
Expand All @@ -1321,8 +1293,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j][1], arr[i,j][2], prec)
end
end
Expand All @@ -1333,8 +1304,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[i, j][1], arr[i,j][2], prec)
end
end
Expand All @@ -1345,8 +1315,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec)
end
end
Expand All @@ -1357,8 +1326,7 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem}
z = AcbMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem},
(Ref{AcbMatrix}, Int, Int), z, i - 1, j - 1)
el = mat_entry_ptr(z, i, j)
_acb_set(el, arr[(i-1)*c+j][1], arr[(i-1)*c+j][2], prec)
end
end
Expand Down
24 changes: 16 additions & 8 deletions src/arb/ComplexMat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ dense_matrix_type(::Type{ComplexFieldElem}) = ComplexMat

function getindex!(z::ComplexFieldElem, x::ComplexMat, r::Int, c::Int)
GC.@preserve x begin
v = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), x, r - 1, c - 1)
v = mat_entry_ptr(x, r, c)
ccall((:acb_set, libflint), Nothing, (Ref{ComplexFieldElem}, Ptr{ComplexFieldElem}), z, v)
end
return z
Expand All @@ -41,8 +40,7 @@ end

z = base_ring(x)()
GC.@preserve x begin
v = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), x, r - 1, c - 1)
v = mat_entry_ptr(x, r, c)
ccall((:acb_set, libflint), Nothing, (Ref{ComplexFieldElem}, Ptr{ComplexFieldElem}), z, v)
end
return z
Expand All @@ -54,8 +52,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, RealFieldElem, BigFloat, Co
@boundscheck _checkbounds(x, r, c)

GC.@preserve x begin
z = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), x, r - 1, c - 1)
z = mat_entry_ptr(x, r, c)
_acb_set(z, y, precision(Balls))
end
end
Expand All @@ -72,8 +69,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, RealFieldElem, BigFloat, Ab
@boundscheck _checkbounds(x, r, c)

GC.@preserve x begin
z = ccall((:acb_mat_entry_ptr, libflint), Ptr{ComplexFieldElem},
(Ref{ComplexMat}, Int, Int), x, r - 1, c - 1)
z = mat_entry_ptr(x, r, c)
_acb_set(z, y[1], y[2], precision(Balls))
end
end
Expand Down Expand Up @@ -900,6 +896,18 @@ function identity_matrix(R::ComplexField, n::Int)
return z
end

################################################################################
#
# Entry pointers
#
################################################################################

@inline mat_entry_ptr(A::ComplexMat, i::Int, j::Int) =
ccall((:acb_mat_entry_ptr, libflint),
Ptr{ComplexFieldElem}, (Ref{ComplexMat}, Int, Int), A, i-1, j-1)



###############################################################################
#
# Promotions
Expand Down
Loading

0 comments on commit bb1a9fa

Please sign in to comment.