From bb1a9fa209b2c02e0345cb396d7ff9e6c40da91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 16 Jul 2024 22:21:39 +0200 Subject: [PATCH] Add `mat_entry_ptr` for arb matrix types (#1829) * Add `mat_entry_ptr` for `AcbMatrix` * Add `mat_entry_ptr` for `ComplexMat` * Add `mat_entry_ptr` for `ArbMatrix` * Add `mat_entry_ptr` for `RealMat` --- src/arb/ArbTypes.jl | 96 +++++++++++++++---------------------------- src/arb/ComplexMat.jl | 24 +++++++---- src/arb/RealMat.jl | 19 ++++++--- src/arb/acb_mat.jl | 22 ++++++---- src/arb/arb_mat.jl | 19 ++++++--- 5 files changed, 88 insertions(+), 92 deletions(-) diff --git a/src/arb/ArbTypes.jl b/src/arb/ArbTypes.jl index 59338cefb..cbe3b2969 100644 --- a/src/arb/ArbTypes.jl +++ b/src/arb/ArbTypes.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/arb/ComplexMat.jl b/src/arb/ComplexMat.jl index 14e11cc16..2070e5b7f 100644 --- a/src/arb/ComplexMat.jl +++ b/src/arb/ComplexMat.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/arb/RealMat.jl b/src/arb/RealMat.jl index eb0f09b0c..3424c3cc5 100644 --- a/src/arb/RealMat.jl +++ b/src/arb/RealMat.jl @@ -29,8 +29,7 @@ dense_matrix_type(::Type{RealFieldElem}) = RealMat function getindex!(z::ArbFieldElem, x::RealMat, r::Int, c::Int) GC.@preserve x begin - v = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem}, - (Ref{RealMat}, Int, Int), x, r - 1, c - 1) + v = mat_entry_ptr(x, r, c) ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ptr{RealFieldElem}), z, v) end return z @@ -41,8 +40,7 @@ end z = base_ring(x)() GC.@preserve x begin - v = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem}, - (Ref{RealMat}, Int, Int), x, r - 1, c - 1) + v = mat_entry_ptr(x, r, c) ccall((:arb_set, libflint), Nothing, (Ref{RealFieldElem}, Ptr{RealFieldElem}), z, v) end return z @@ -54,8 +52,7 @@ for T in [Int, UInt, ZZRingElem, QQFieldElem, Float64, BigFloat, RealFieldElem, @boundscheck _checkbounds(x, r, c) GC.@preserve x begin - z = ccall((:arb_mat_entry_ptr, libflint), Ptr{RealFieldElem}, - (Ref{RealMat}, Int, Int), x, r - 1, c - 1) + z = mat_entry_ptr(x, r, c) _arb_set(z, y, precision(Balls)) end end @@ -790,6 +787,16 @@ function identity_matrix(R::RealField, n::Int) return z end +################################################################################ +# +# Entry pointers +# +################################################################################ + +@inline mat_entry_ptr(A::RealMat, i::Int, j::Int) = +ccall((:arb_mat_entry_ptr, libflint), + Ptr{RealFieldElem}, (Ref{RealMat}, Int, Int), A, i-1, j-1) + ############################################################################### # # Promotions diff --git a/src/arb/acb_mat.jl b/src/arb/acb_mat.jl index 2654a3c89..53b95bdb1 100644 --- a/src/arb/acb_mat.jl +++ b/src/arb/acb_mat.jl @@ -32,8 +32,7 @@ precision(x::AcbMatSpace) = precision(base_ring(x)) function getindex!(z::AcbFieldElem, x::AcbMatrix, r::Int, c::Int) GC.@preserve x begin - v = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem}, - (Ref{AcbMatrix}, Int, Int), x, r - 1, c - 1) + v = mat_entry_ptr(x, r, c) ccall((:acb_set, libflint), Nothing, (Ref{AcbFieldElem}, Ptr{AcbFieldElem}), z, v) end return z @@ -44,8 +43,7 @@ end z = base_ring(x)() GC.@preserve x begin - v = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem}, - (Ref{AcbMatrix}, Int, Int), x, r - 1, c - 1) + v = mat_entry_ptr(x, r, c) ccall((:acb_set, libflint), Nothing, (Ref{AcbFieldElem}, Ptr{AcbFieldElem}), z, v) end return z @@ -57,8 +55,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, ArbFieldElem, BigFloat, Acb @boundscheck _checkbounds(x, r, c) GC.@preserve x begin - z = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem}, - (Ref{AcbMatrix}, Int, Int), x, r - 1, c - 1) + z = mat_entry_ptr(x, r, c) _acb_set(z, y, precision(base_ring(x))) end end @@ -75,8 +72,7 @@ for T in [Integer, Float64, ZZRingElem, QQFieldElem, ArbFieldElem, BigFloat, Abs @boundscheck _checkbounds(x, r, c) GC.@preserve x begin - z = ccall((:acb_mat_entry_ptr, libflint), Ptr{AcbFieldElem}, - (Ref{AcbMatrix}, Int, Int), x, r - 1, c - 1) + z = mat_entry_ptr(x, r, c) _acb_set(z, y[1], y[2], precision(base_ring(x))) end end @@ -914,6 +910,16 @@ function identity_matrix(R::AcbField, n::Int) return z end +################################################################################ +# +# Entry pointers +# +################################################################################ + +@inline mat_entry_ptr(A::AcbMatrix, i::Int, j::Int) = +ccall((:acb_mat_entry_ptr, libflint), + Ptr{AcbFieldElem}, (Ref{AcbMatrix}, Int, Int), A, i-1, j-1) + ############################################################################### # # Promotions diff --git a/src/arb/arb_mat.jl b/src/arb/arb_mat.jl index b84e1fd58..b0357da4f 100644 --- a/src/arb/arb_mat.jl +++ b/src/arb/arb_mat.jl @@ -32,8 +32,7 @@ precision(x::ArbMatSpace) = precision(x.base_ring) function getindex!(z::ArbFieldElem, x::ArbMatrix, r::Int, c::Int) GC.@preserve x begin - v = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem}, - (Ref{ArbMatrix}, Int, Int), x, r - 1, c - 1) + v = mat_entry_ptr(x, r, c) ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ptr{ArbFieldElem}), z, v) end return z @@ -44,8 +43,7 @@ end z = base_ring(x)() GC.@preserve x begin - v = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem}, - (Ref{ArbMatrix}, Int, Int), x, r - 1, c - 1) + v = mat_entry_ptr(x, r, c) ccall((:arb_set, libflint), Nothing, (Ref{ArbFieldElem}, Ptr{ArbFieldElem}), z, v) end return z @@ -57,8 +55,7 @@ for T in [Int, UInt, ZZRingElem, QQFieldElem, Float64, BigFloat, ArbFieldElem, A @boundscheck _checkbounds(x, r, c) GC.@preserve x begin - z = ccall((:arb_mat_entry_ptr, libflint), Ptr{ArbFieldElem}, - (Ref{ArbMatrix}, Int, Int), x, r - 1, c - 1) + z = mat_entry_ptr(x, r, c) _arb_set(z, y, precision(base_ring(x))) end end @@ -810,6 +807,16 @@ function identity_matrix(R::ArbField, n::Int) return z end +################################################################################ +# +# Entry pointers +# +################################################################################ + +@inline mat_entry_ptr(A::ArbMatrix, i::Int, j::Int) = +ccall((:arb_mat_entry_ptr, libflint), + Ptr{ArbFieldElem}, (Ref{ArbMatrix}, Int, Int), A, i-1, j-1) + ############################################################################### # # Promotions