Skip to content

Commit

Permalink
Optimize mat_entry_ptr methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Sep 30, 2024
1 parent 8b486cc commit 2af5415
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
28 changes: 14 additions & 14 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4696,10 +4696,10 @@ const QQMatrixSpace = AbstractAlgebra.Generic.MatSpace{QQFieldElem}
QQMatrixSpace(r::Int, c::Int) = QQMatrixSpace(QQ, r, c)

mutable struct QQMatrix <: MatElem{QQFieldElem}
entries::Ptr{Nothing}
entries::Ptr{QQFieldElem}
r::Int
c::Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{QQFieldElem}}
view_parent

# used by windows, not finalised!!
Expand Down Expand Up @@ -4912,10 +4912,10 @@ end
const zzModMatrixSpace = AbstractAlgebra.Generic.MatSpace{zzModRingElem}

mutable struct zzModMatrix <: MatElem{zzModRingElem}
entries::Ptr{Nothing}
entries::Ptr{UInt}
r::Int # Int
c::Int # Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{UInt}}
n::UInt # mp_limb_t / Culong
ninv::UInt # mp_limb_t / Culong
norm::UInt # mp_limb_t / Culong
Expand Down Expand Up @@ -5057,10 +5057,10 @@ end
const ZZModMatrixSpace = AbstractAlgebra.Generic.MatSpace{ZZModRingElem}

mutable struct ZZModMatrix <: MatElem{ZZModRingElem}
entries::Ptr{Nothing}
entries::Ptr{ZZRingElem}
r::Int
c::Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{ZZRingElem}}
# end flint struct

base_ring::ZZModRing
Expand Down Expand Up @@ -5215,10 +5215,10 @@ end
const FpMatrixSpace = AbstractAlgebra.Generic.MatSpace{FpFieldElem}

mutable struct FpMatrix <: MatElem{FpFieldElem}
entries::Ptr{Nothing}
entries::Ptr{ZZRingElem}
r::Int
c::Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{ZZRingElem}}
# end flint struct

base_ring::FpField
Expand Down Expand Up @@ -5324,10 +5324,10 @@ end
const fpMatrixSpace = AbstractAlgebra.Generic.MatSpace{fpFieldElem}

mutable struct fpMatrix <: MatElem{fpFieldElem}
entries::Ptr{Nothing}
entries::Ptr{UInt}
r::Int # Int
c::Int # Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{UInt}}
n::UInt # mp_limb_t / Culong
ninv::UInt # mp_limb_t / Culong
norm::UInt # mp_limb_t / Culong
Expand Down Expand Up @@ -6071,10 +6071,10 @@ end
const FqPolyRepMatrixSpace = AbstractAlgebra.Generic.MatSpace{FqPolyRepFieldElem}

mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem}
entries::Ptr{Nothing}
entries::Ptr{FqPolyRepFieldElem}
r::Int
c::Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{FqPolyRepFieldElem}}
base_ring::FqPolyRepField
view_parent

Expand Down Expand Up @@ -6204,10 +6204,10 @@ end
const fqPolyRepMatrixSpace = AbstractAlgebra.Generic.MatSpace{fqPolyRepFieldElem}

mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem}
entries::Ptr{Nothing}
entries::Ptr{fqPolyRepFieldElem}
r::Int
c::Int
rows::Ptr{Nothing}
rows::Ptr{Ptr{fqPolyRepFieldElem}}
base_ring::fqPolyRepField
view_parent

Expand Down
4 changes: 1 addition & 3 deletions src/flint/fmpq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,7 @@ end
#
################################################################################

@inline mat_entry_ptr(A::QQMatrix, i::Int, j::Int) =
ccall((:fmpq_mat_entry, libflint),
Ptr{QQFieldElem}, (Ref{QQMatrix}, Int, Int), A, i-1, j-1)
mat_entry_ptr(A::QQMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*2*sizeof(Ptr)

################################################################################
#
Expand Down
2 changes: 1 addition & 1 deletion src/flint/fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2107,4 +2107,4 @@ end
#
################################################################################

@inline mat_entry_ptr(A::ZZMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(UInt)
mat_entry_ptr(A::ZZMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(Ptr)
4 changes: 1 addition & 3 deletions src/flint/fmpz_mod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,4 @@ end
#
################################################################################

@inline mat_entry_ptr(A::ZZModMatrix, i::Int, j::Int) =
ccall((:fmpz_mod_mat_entry, libflint), Ptr{ZZRingElem},
(Ref{ZZModMatrix}, Int, Int), A, i - 1, j - 1)
mat_entry_ptr(A::ZZModMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(Ptr)
4 changes: 1 addition & 3 deletions src/flint/fq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,4 @@ end
#
################################################################################

@inline mat_entry_ptr(A::FqPolyRepMatrix, i::Int, j::Int) =
ccall((:fq_mat_entry, libflint), Ptr{FqPolyRepFieldElem},
(Ref{FqPolyRepMatrix}, Int, Int), A, i - 1, j - 1)
mat_entry_ptr(A::FqPolyRepMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*(sizeof(Ptr)+2*sizeof(Int))
4 changes: 1 addition & 3 deletions src/flint/fq_nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,4 @@ end
#
################################################################################

@inline mat_entry_ptr(A::fqPolyRepMatrix, i::Int, j::Int) =
ccall((:fq_nmod_mat_entry, libflint), Ptr{fqPolyRepFieldElem},
(Ref{fqPolyRepMatrix}, Int, Int), A, i - 1, j - 1)
mat_entry_ptr(A::fqPolyRepMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*(sizeof(Ptr)+5*sizeof(Int))
4 changes: 1 addition & 3 deletions src/flint/gfp_fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,4 @@ end
#
################################################################################

@inline mat_entry_ptr(A::FpMatrix, i::Int, j::Int) =
ccall((:fmpz_mod_mat_entry, libflint), Ptr{ZZRingElem},
(Ref{FpMatrix}, Int, Int), A, i - 1, j - 1)
mat_entry_ptr(A::FpMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(Ptr)
8 changes: 8 additions & 0 deletions src/flint/nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,11 @@ function kernel(::Solve.RREFTrait, M::Union{zzModMatrix, ZZModMatrix}; side::Sym
end

# For kernel(::HowellFormTrait, ...) we use generic AbstractAlgebra code

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

mat_entry_ptr(A::Zmodn_mat, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(UInt)

Check warning on line 908 in src/flint/nmod_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/nmod_mat.jl#L908

Added line #L908 was not covered by tests

0 comments on commit 2af5415

Please sign in to comment.