Skip to content

Commit

Permalink
Optimize mat_entry_ptr for ZZMatrix (#1807)
Browse files Browse the repository at this point in the history
... by replacing a ccall with a direct address computation.
This allows the Julia compiler to understand what's going on
and thus enables further optimizations.
  • Loading branch information
fingolfin authored Jul 1, 2024
1 parent 79c9770 commit 82519f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4856,10 +4856,10 @@ const ZZMatrixSpace = AbstractAlgebra.Generic.MatSpace{ZZRingElem}
ZZMatrixSpace(r::Int, c::Int) = ZZMatrixSpace(ZZ, r, c)

mutable struct ZZMatrix <: MatElem{ZZRingElem}
entries::Ptr{Nothing}
entries::Ptr{ZZRingElem}
r::Int
c::Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{ZZRingElem}}
view_parent

# Used by view, not finalised!!
Expand Down
4 changes: 1 addition & 3 deletions src/flint/fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,4 @@ end
#
################################################################################

@inline mat_entry_ptr(A::ZZMatrix, i::Int, j::Int) =
ccall((:fmpz_mat_entry, libflint),
Ptr{ZZRingElem}, (Ref{ZZMatrix}, Int, Int), A, i-1, j-1)
@inline mat_entry_ptr(A::ZZMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(UInt)

0 comments on commit 82519f3

Please sign in to comment.