From 4fd7b1a70dc05eec23732e70e9438c1ac87d0909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 18 Oct 2024 18:34:42 +0200 Subject: [PATCH 1/7] Clean up `fq_mat_entry_set` calls --- src/flint/FlintTypes.jl | 57 ++++++++++++++--------------------------- src/flint/fq_mat.jl | 8 +++--- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index 9baa31fd1..0d491dfd2 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -5739,72 +5739,54 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{FqPolyRepFieldElem}, ctx::FqPolyRepField) z = FqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_mat_entry_set, libflint), Nothing, - (Ref{FqPolyRepMatrix}, Int, Int, Ref{FqPolyRepFieldElem}, Ref{FqPolyRepField}), - z, i - 1, j - 1, arr[i, j], ctx) - end + for i = 1:r, j = 1:c + el = arr[i, j] + @inbounds z[i, j] = el end return z end function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{FqPolyRepFieldElem}, ctx::FqPolyRepField) z = FqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_mat_entry_set, libflint), Nothing, - (Ref{FqPolyRepMatrix}, Int, Int, Ref{FqPolyRepFieldElem}, Ref{FqPolyRepField}), - z, i - 1, j - 1, arr[(i - 1) * c + j], ctx) - end + for i = 1:r, j = 1:c + el = arr[(i - 1) * c + j] + @inbounds z[i, j] = el end return z end function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::FqPolyRepField) z = FqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - el = mat_entry_ptr(z, i, j) - ccall((:fq_set_fmpz, libflint), Nothing, - (Ptr{FqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{FqPolyRepField}), el, arr[i, j], ctx) - end + for i = 1:r, j = 1:c + el = arr[i, j] + @inbounds z[i, j] = el end return z end function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::FqPolyRepField) z = FqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - el = mat_entry_ptr(z, i, j) - ccall((:fq_set_fmpz, libflint), Nothing, - (Ptr{FqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{FqPolyRepField}), el, arr[(i - 1) * c + j], ctx) - end + for i = 1:r, j = 1:c + el = arr[(i - 1) * c + j] + @inbounds z[i, j] = el end return z end function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::FqPolyRepField) where {T <: Integer} z = FqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_mat_entry_set, libflint), Nothing, - (Ref{FqPolyRepMatrix}, Int, Int, Ref{FqPolyRepFieldElem}, Ref{FqPolyRepField}), - z, i - 1, j - 1, ctx(arr[i, j]), ctx) - end + for i = 1:r, j = 1:c + el = ctx(arr[i, j]) + @inbounds z[i, j] = el end return z end function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::FqPolyRepField) where {T <: Integer} z = FqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_mat_entry_set, libflint), Nothing, - (Ref{FqPolyRepMatrix}, Int, Int, Ref{FqPolyRepFieldElem}, Ref{FqPolyRepField}), - z, i - 1, j - 1, ctx(arr[(i - 1) * c + j]), ctx) - end + for i = 1:r, j = 1:c + el = ctx(arr[(i - 1) * c + j]) + @inbounds z[i, j] = el end return z end @@ -5813,8 +5795,7 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} ctx = parent(d) z = FqPolyRepMatrix(r, c, ctx) for i = 1:min(r, c) - ccall((:fq_mat_entry_set, libflint), Nothing, - (Ref{FqPolyRepMatrix}, Int, Int, Ref{FqPolyRepFieldElem}, Ref{FqPolyRepField}), z, i - 1, i- 1, d, ctx) + @inbounds z[i, i] = d end return z end diff --git a/src/flint/fq_mat.jl b/src/flint/fq_mat.jl index a9d721862..7fbd366f6 100644 --- a/src/flint/fq_mat.jl +++ b/src/flint/fq_mat.jl @@ -47,11 +47,11 @@ end return z end -@inline function setindex!(a::FqPolyRepMatrix, u::FqPolyRepFieldElem, i::Int, j::Int) +@inline function setindex!(a::FqPolyRepMatrix, u::FqPolyRepFieldElemOrPtr, i::Int, j::Int) @boundscheck _checkbounds(a, i, j) - ccall((:fq_mat_entry_set, libflint), Nothing, - (Ref{FqPolyRepMatrix}, Int, Int, Ref{FqPolyRepFieldElem}, Ref{FqPolyRepField}), - a, i - 1, j - 1, u, base_ring(a)) + @ccall libflint.fq_mat_entry_set( + a::Ref{FqPolyRepMatrix}, (i-1)::Int, (j-1)::Int, u::Ref{FqPolyRepFieldElem}, base_ring(a)::Ref{FqPolyRepField} + )::Nothing end @inline function setindex!(a::FqPolyRepMatrix, u::ZZRingElem, i::Int, j::Int) From bafe7b9ac19374b26278818a465a492ab455ed27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 18 Oct 2024 18:39:56 +0200 Subject: [PATCH 2/7] Clean up `fq_default_mat_entry_set` uses --- src/flint/FlintTypes.jl | 64 +++++++++++-------------------------- src/flint/fq_default_mat.jl | 11 +++---- 2 files changed, 23 insertions(+), 52 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index 0d491dfd2..d689098f2 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -5574,78 +5574,54 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{FqFieldElem}, ctx::FqField) z = FqMatrix(r, c, ctx) - for i = 1:r - for j = 1:c - ccall((:fq_default_mat_entry_set, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, - Ref{FqField}), - z, i - 1, j - 1, arr[i, j], ctx) - end + for i = 1:r, j = 1:c + el = arr[i, j] + @inbounds z[i, j] = el end return z end function FqMatrix(r::Int, c::Int, arr::AbstractVector{FqFieldElem}, ctx::FqField) z = FqMatrix(r, c, ctx) - for i = 1:r - for j = 1:c - ccall((:fq_default_mat_entry_set, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, - Ref{FqField}), - z, i - 1, j - 1, arr[(i - 1) * c + j], ctx) - end + for i = 1:r, j = 1:c + el = arr[(i - 1) * c + j] + @inbounds z[i, j] = el end return z end function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::FqField) z = FqMatrix(r, c, ctx) - for i = 1:r - for j = 1:c - ccall((:fq_default_mat_entry_set_fmpz, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{ZZRingElem}, - Ref{FqField}), - z, i - 1, j - 1, arr[i, j], ctx) - end + for i = 1:r, j = 1:c + el = arr[i, j] + @inbounds z[i, j] = el end return z end function FqMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::FqField) z = FqMatrix(r, c, ctx) - for i = 1:r - for j = 1:c - ccall((:fq_default_mat_entry_set_fmpz, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{ZZRingElem}, - Ref{FqField}), - z, i - 1, j - 1, arr[(i - 1) * c + j], ctx) - end + for i = 1:r, j = 1:c + el = arr[(i - 1) * c + j] + @inbounds z[i, j] = el end return z end function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::FqField) where {T <: Integer} z = FqMatrix(r, c, ctx) - for i = 1:r - for j = 1:c - ccall((:fq_default_mat_entry_set, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, - Ref{FqField}), - z, i - 1, j - 1, ctx(arr[i, j]), ctx) - end + for i = 1:r, j = 1:c + el = ctx(arr[i, j]) + @inbounds z[i, j] = el end return z end function FqMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::FqField) where {T <: Integer} z = FqMatrix(r, c, ctx) - for i = 1:r - for j = 1:c - ccall((:fq_default_mat_entry_set, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, - Ref{FqField}), - z, i - 1, j - 1, ctx(arr[(i - 1) * c + j]), ctx) - end + for i = 1:r, j = 1:c + el = ctx(arr[(i - 1) * c + j]) + @inbounds z[i, j] = el end return z end @@ -5654,9 +5630,7 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} ctx = parent(d) z = FqMatrix(r, c, ctx) for i = 1:min(r, c) - ccall((:fq_default_mat_entry_set, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, - Ref{FqField}), z, i - 1, i - 1, d, ctx) + @inbounds z[i, i] = d end return z end diff --git a/src/flint/fq_default_mat.jl b/src/flint/fq_default_mat.jl index 3c114c6ae..ee921af11 100644 --- a/src/flint/fq_default_mat.jl +++ b/src/flint/fq_default_mat.jl @@ -45,14 +45,11 @@ end return z end -@inline function setindex!(a::FqMatrix, u::FqFieldElem, i::Int, j::Int) +@inline function setindex!(a::FqMatrix, u::FqFieldElemOrPtr, i::Int, j::Int) @boundscheck _checkbounds(a, i, j) - K = base_ring(a) - uu = K(u) - ccall((:fq_default_mat_entry_set, libflint), Nothing, - (Ref{FqMatrix}, Int, Int, Ref{FqFieldElem}, Ref{FqField}), - a, i - 1, j - 1, uu, base_ring(a)) - nothing + @ccall libflint.fq_default_mat_entry_set( + a::Ref{FqMatrix}, (i-1)::Int, (j-1)::Int, u::Ref{FqFieldElem}, base_ring(a)::Ref{FqField} + )::Nothing end @inline function setindex!(a::FqMatrix, u::ZZRingElem, i::Int, j::Int) From 0909192d80ec29c397dd027edda88ff2394a2828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 18 Oct 2024 18:46:21 +0200 Subject: [PATCH 3/7] Clean up `fq_nmod_mat_entry_set` calls --- src/flint/FlintTypes.jl | 57 ++++++++++++++-------------------------- src/flint/fq_nmod_mat.jl | 8 +++--- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index d689098f2..e36b11d1e 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -5827,72 +5827,54 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{fqPolyRepFieldElem}, ctx::fqPolyRepField) z = fqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_nmod_mat_entry_set, libflint), Nothing, - (Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), - z, i - 1, j - 1, arr[i, j], ctx) - end + for i = 1:r, j = 1:c + el = arr[i, j] + @inbounds z[i, j] = el end return z end function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{fqPolyRepFieldElem}, ctx::fqPolyRepField) z = fqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_nmod_mat_entry_set, libflint), Nothing, - (Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), - z, i - 1, j - 1, arr[(i - 1) * c + j], ctx) - end + for i = 1:r, j = 1:c + el = arr[(i - 1) * c + j] + @inbounds z[i, j] = el end return z end function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::fqPolyRepField) z = fqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - el = mat_entry_ptr(z, i, j) - ccall((:fq_nmod_set_fmpz, libflint), Nothing, - (Ptr{fqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{fqPolyRepField}), el, arr[i, j], ctx) - end + for i = 1:r, j = 1:c + el = arr[i, j] + @inbounds z[i, j] = el end return z end function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::fqPolyRepField) z = fqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - el = mat_entry_ptr(z, i, j) - ccall((:fq_nmod_set_fmpz, libflint), Nothing, - (Ptr{fqPolyRepFieldElem}, Ref{ZZRingElem}, Ref{fqPolyRepField}), el, arr[(i - 1) * c + j], ctx) - end + for i = 1:r, j = 1:c + el = arr[(i - 1) * c + j] + @inbounds z[i, j] = el end return z end function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::fqPolyRepField) where {T <: Integer} z = fqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_nmod_mat_entry_set, libflint), Nothing, - (Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), - z, i - 1, j - 1, ctx(arr[i, j]), ctx) - end + for i = 1:r, j = 1:c + el = ctx(arr[i, j]) + @inbounds z[i, j] = el end return z end function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::fqPolyRepField) where {T <: Integer} z = fqPolyRepMatrix(r, c, ctx) - GC.@preserve z for i = 1:r - for j = 1:c - ccall((:fq_nmod_mat_entry_set, libflint), Nothing, - (Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), - z, i - 1, j - 1, ctx(arr[(i - 1) * c + j]), ctx) - end + for i = 1:r, j = 1:c + el = ctx(arr[(i - 1) * c + j]) + @inbounds z[i, j] = el end return z end @@ -5901,8 +5883,7 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} ctx = parent(d) z = fqPolyRepMatrix(r, c, ctx) for i = 1:min(r, c) - ccall((:fq_nmod_mat_entry_set, libflint), Nothing, - (Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), z, i - 1, i- 1, d, ctx) + @inbounds z[i, i] = d end return z end diff --git a/src/flint/fq_nmod_mat.jl b/src/flint/fq_nmod_mat.jl index 20dd55a16..c44bb26aa 100644 --- a/src/flint/fq_nmod_mat.jl +++ b/src/flint/fq_nmod_mat.jl @@ -47,11 +47,11 @@ end return z end -@inline function setindex!(a::fqPolyRepMatrix, u::fqPolyRepFieldElem, i::Int, j::Int) +@inline function setindex!(a::fqPolyRepMatrix, u::fqPolyRepFieldElemOrPtr, i::Int, j::Int) @boundscheck _checkbounds(a, i, j) - ccall((:fq_nmod_mat_entry_set, libflint), Nothing, - (Ref{fqPolyRepMatrix}, Int, Int, Ref{fqPolyRepFieldElem}, Ref{fqPolyRepField}), - a, i - 1, j - 1, u, base_ring(a)) + @ccall libflint.fq_nmod_mat_entry_set( + a::Ref{fqPolyRepMatrix}, (i-1)::Int, (j-1)::Int, u::Ref{fqPolyRepFieldElem}, base_ring(a)::Ref{fqPolyRepField} + )::Nothing end @inline function setindex!(a::fqPolyRepMatrix, u::ZZRingElem, i::Int, j::Int) From aad9e2274b4e9476f0df87fe653dfb31004993da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 18 Oct 2024 19:00:11 +0200 Subject: [PATCH 4/7] Fix coercion in `FqMatrix` --- src/flint/fq_default_mat.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flint/fq_default_mat.jl b/src/flint/fq_default_mat.jl index ee921af11..8f7278159 100644 --- a/src/flint/fq_default_mat.jl +++ b/src/flint/fq_default_mat.jl @@ -47,8 +47,9 @@ end @inline function setindex!(a::FqMatrix, u::FqFieldElemOrPtr, i::Int, j::Int) @boundscheck _checkbounds(a, i, j) + uu = base_ring(a)(u) @ccall libflint.fq_default_mat_entry_set( - a::Ref{FqMatrix}, (i-1)::Int, (j-1)::Int, u::Ref{FqFieldElem}, base_ring(a)::Ref{FqField} + a::Ref{FqMatrix}, (i-1)::Int, (j-1)::Int, uu::Ref{FqFieldElem}, base_ring(a)::Ref{FqField} )::Nothing end From f83e47e797583f55b9e74c22b6cafa49b76e57d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 25 Oct 2024 11:03:26 +0200 Subject: [PATCH 5/7] Merge similar constructors --- src/flint/FlintTypes.jl | 120 ++---------------------------------- src/flint/fq_default_mat.jl | 3 +- src/flint/fq_mat.jl | 3 +- src/flint/fq_nmod_mat.jl | 3 +- 4 files changed, 9 insertions(+), 120 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index e36b11d1e..b68b464da 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -5572,7 +5572,7 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} return z end - function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{FqFieldElem}, ctx::FqField) + function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{<:Union{FqFieldElem,ZZRingElem,Integer}}, ctx::FqField) z = FqMatrix(r, c, ctx) for i = 1:r, j = 1:c el = arr[i, j] @@ -5581,7 +5581,7 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} return z end - function FqMatrix(r::Int, c::Int, arr::AbstractVector{FqFieldElem}, ctx::FqField) + function FqMatrix(r::Int, c::Int, arr::AbstractVector{<:Union{FqFieldElem,ZZRingElem,Integer}}, ctx::FqField) z = FqMatrix(r, c, ctx) for i = 1:r, j = 1:c el = arr[(i - 1) * c + j] @@ -5590,42 +5590,6 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} return z end - function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::FqField) - z = FqMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = arr[i, j] - @inbounds z[i, j] = el - end - return z - end - - function FqMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::FqField) - z = FqMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = arr[(i - 1) * c + j] - @inbounds z[i, j] = el - end - return z - end - - function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::FqField) where {T <: Integer} - z = FqMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = ctx(arr[i, j]) - @inbounds z[i, j] = el - end - return z - end - - function FqMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::FqField) where {T <: Integer} - z = FqMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = ctx(arr[(i - 1) * c + j]) - @inbounds z[i, j] = el - end - return z - end - function FqMatrix(r::Int, c::Int, d::FqFieldElem) ctx = parent(d) z = FqMatrix(r, c, ctx) @@ -5711,25 +5675,7 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} return z end - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{FqPolyRepFieldElem}, ctx::FqPolyRepField) - z = FqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = arr[i, j] - @inbounds z[i, j] = el - end - return z - end - - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{FqPolyRepFieldElem}, ctx::FqPolyRepField) - z = FqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = arr[(i - 1) * c + j] - @inbounds z[i, j] = el - end - return z - end - - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::FqPolyRepField) + function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{<:Union{FqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::FqPolyRepField) z = FqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c el = arr[i, j] @@ -5738,7 +5684,7 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} return z end - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::FqPolyRepField) + function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{<:Union{FqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::FqPolyRepField) z = FqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c el = arr[(i - 1) * c + j] @@ -5747,24 +5693,6 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} return z end - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::FqPolyRepField) where {T <: Integer} - z = FqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = ctx(arr[i, j]) - @inbounds z[i, j] = el - end - return z - end - - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::FqPolyRepField) where {T <: Integer} - z = FqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = ctx(arr[(i - 1) * c + j]) - @inbounds z[i, j] = el - end - return z - end - function FqPolyRepMatrix(r::Int, c::Int, d::FqPolyRepFieldElem) ctx = parent(d) z = FqPolyRepMatrix(r, c, ctx) @@ -5825,7 +5753,7 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} return z end - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{fqPolyRepFieldElem}, ctx::fqPolyRepField) + function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{<:Union{fqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::fqPolyRepField) z = fqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c el = arr[i, j] @@ -5834,7 +5762,7 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} return z end - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{fqPolyRepFieldElem}, ctx::fqPolyRepField) + function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{<:Union{fqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::fqPolyRepField) z = fqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c el = arr[(i - 1) * c + j] @@ -5843,42 +5771,6 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} return z end - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem}, ctx::fqPolyRepField) - z = fqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = arr[i, j] - @inbounds z[i, j] = el - end - return z - end - - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem}, ctx::fqPolyRepField) - z = fqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = arr[(i - 1) * c + j] - @inbounds z[i, j] = el - end - return z - end - - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{T}, ctx::fqPolyRepField) where {T <: Integer} - z = fqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = ctx(arr[i, j]) - @inbounds z[i, j] = el - end - return z - end - - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractVector{T}, ctx::fqPolyRepField) where {T <: Integer} - z = fqPolyRepMatrix(r, c, ctx) - for i = 1:r, j = 1:c - el = ctx(arr[(i - 1) * c + j]) - @inbounds z[i, j] = el - end - return z - end - function fqPolyRepMatrix(r::Int, c::Int, d::fqPolyRepFieldElem) ctx = parent(d) z = fqPolyRepMatrix(r, c, ctx) diff --git a/src/flint/fq_default_mat.jl b/src/flint/fq_default_mat.jl index 8f7278159..b07d379c1 100644 --- a/src/flint/fq_default_mat.jl +++ b/src/flint/fq_default_mat.jl @@ -62,8 +62,7 @@ end nothing end -setindex!(a::FqMatrix, u::Integer, i::Int, j::Int) = -setindex!(a, base_ring(a)(u), i, j) +setindex!(a::FqMatrix, u::Integer, i::Int, j::Int) = setindex!(a, base_ring(a)(u), i, j) function setindex!(a::FqMatrix, b::FqMatrix, r::UnitRange{Int64}, c::UnitRange{Int64}) _checkbounds(a, r, c) diff --git a/src/flint/fq_mat.jl b/src/flint/fq_mat.jl index 7fbd366f6..264a7bc03 100644 --- a/src/flint/fq_mat.jl +++ b/src/flint/fq_mat.jl @@ -63,8 +63,7 @@ end end end -setindex!(a::FqPolyRepMatrix, u::Integer, i::Int, j::Int) = -setindex!(a, base_ring(a)(u), i, j) +setindex!(a::FqPolyRepMatrix, u::Integer, i::Int, j::Int) = setindex!(a, base_ring(a)(u), i, j) function setindex!(a::FqPolyRepMatrix, b::FqPolyRepMatrix, r::UnitRange{Int64}, c::UnitRange{Int64}) _checkbounds(a, r, c) diff --git a/src/flint/fq_nmod_mat.jl b/src/flint/fq_nmod_mat.jl index c44bb26aa..e78bd2d8d 100644 --- a/src/flint/fq_nmod_mat.jl +++ b/src/flint/fq_nmod_mat.jl @@ -63,8 +63,7 @@ end end end -setindex!(a::fqPolyRepMatrix, u::Integer, i::Int, j::Int) = -setindex!(a, base_ring(a)(u), i, j) +setindex!(a::fqPolyRepMatrix, u::Integer, i::Int, j::Int) = setindex!(a, base_ring(a)(u), i, j) function setindex!(a::fqPolyRepMatrix, b::fqPolyRepMatrix, r::UnitRange{Int64}, c::UnitRange{Int64}) _checkbounds(a, r, c) From d9943c14ecbe584a0138a865cea211ae4e31f444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 25 Oct 2024 11:20:08 +0200 Subject: [PATCH 6/7] Drop `r` and `c` from some matrix constructors --- src/flint/FlintTypes.jl | 21 ++++++++++++--------- src/flint/fq_default_mat.jl | 21 ++++++--------------- src/flint/fq_mat.jl | 21 ++++++--------------- src/flint/fq_nmod_mat.jl | 21 ++++++--------------- 4 files changed, 30 insertions(+), 54 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index b68b464da..5f9887c59 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -5572,11 +5572,12 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} return z end - function FqMatrix(r::Int, c::Int, arr::AbstractMatrix{<:Union{FqFieldElem,ZZRingElem,Integer}}, ctx::FqField) + function FqMatrix(arr::AbstractMatrix{<:Union{FqFieldElem,ZZRingElem,Integer}}, ctx::FqField) + r = nrows(arr) + c = ncols(arr) z = FqMatrix(r, c, ctx) for i = 1:r, j = 1:c - el = arr[i, j] - @inbounds z[i, j] = el + @inbounds z[i, j] = arr[i, j] end return z end @@ -5675,11 +5676,12 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} return z end - function FqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{<:Union{FqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::FqPolyRepField) + function FqPolyRepMatrix(arr::AbstractMatrix{<:Union{FqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::FqPolyRepField) + r = nrows(arr) + c = ncols(arr) z = FqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c - el = arr[i, j] - @inbounds z[i, j] = el + @inbounds z[i, j] = arr[i, j] end return z end @@ -5753,11 +5755,12 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} return z end - function fqPolyRepMatrix(r::Int, c::Int, arr::AbstractMatrix{<:Union{fqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::fqPolyRepField) + function fqPolyRepMatrix(arr::AbstractMatrix{<:Union{fqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::fqPolyRepField) + r = nrows(arr) + c = ncols(arr) z = fqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c - el = arr[i, j] - @inbounds z[i, j] = el + @inbounds z[i, j] = arr[i, j] end return z end diff --git a/src/flint/fq_default_mat.jl b/src/flint/fq_default_mat.jl index b07d379c1..befc02a98 100644 --- a/src/flint/fq_default_mat.jl +++ b/src/flint/fq_default_mat.jl @@ -674,22 +674,12 @@ function (a::FqMatrixSpace)(b::FqFieldElem) return FqMatrix(nrows(a), ncols(a), b) end -function (a::FqMatrixSpace)(arr::AbstractMatrix{T}) where {T <: Integer} +function (a::FqMatrixSpace)(arr::AbstractMatrix{<:IntegerUnion}) _check_dim(nrows(a), ncols(a), arr) - return FqMatrix(nrows(a), ncols(a), arr, base_ring(a)) -end - -function (a::FqMatrixSpace)(arr::AbstractVector{T}) where {T <: Integer} - _check_dim(nrows(a), ncols(a), arr) - return FqMatrix(nrows(a), ncols(a), arr, base_ring(a)) + return FqMatrix(arr, base_ring(a)) end -function (a::FqMatrixSpace)(arr::AbstractMatrix{ZZRingElem}) - _check_dim(nrows(a), ncols(a), arr) - return FqMatrix(nrows(a), ncols(a), arr, base_ring(a)) -end - -function (a::FqMatrixSpace)(arr::AbstractVector{ZZRingElem}) +function (a::FqMatrixSpace)(arr::AbstractVector{<:IntegerUnion}) _check_dim(nrows(a), ncols(a), arr) return FqMatrix(nrows(a), ncols(a), arr, base_ring(a)) end @@ -697,7 +687,7 @@ end function (a::FqMatrixSpace)(arr::AbstractMatrix{FqFieldElem}) _check_dim(nrows(a), ncols(a), arr) (length(arr) > 0 && (base_ring(a) != parent(arr[1]))) && error("Elements must have same base ring") - return FqMatrix(nrows(a), ncols(a), arr, base_ring(a)) + return FqMatrix(arr, base_ring(a)) end function (a::FqMatrixSpace)(arr::AbstractVector{FqFieldElem}) @@ -732,7 +722,8 @@ end ############################################################################### function matrix(R::FqField, arr::AbstractMatrix{<: Union{FqFieldElem, ZZRingElem, Integer}}) - z = FqMatrix(size(arr, 1), size(arr, 2), arr, R) + Base.require_one_based_indexing(arr) + z = FqMatrix(arr, R) return z end diff --git a/src/flint/fq_mat.jl b/src/flint/fq_mat.jl index 264a7bc03..1ff8e7e85 100644 --- a/src/flint/fq_mat.jl +++ b/src/flint/fq_mat.jl @@ -667,22 +667,12 @@ function (a::FqPolyRepMatrixSpace)(b::FqPolyRepFieldElem) return FqPolyRepMatrix(nrows(a), ncols(a), b) end -function (a::FqPolyRepMatrixSpace)(arr::AbstractMatrix{T}) where {T <: Integer} +function (a::FqPolyRepMatrixSpace)(arr::AbstractMatrix{<:IntegerUnion}) _check_dim(nrows(a), ncols(a), arr) - return FqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) -end - -function (a::FqPolyRepMatrixSpace)(arr::AbstractVector{T}) where {T <: Integer} - _check_dim(nrows(a), ncols(a), arr) - return FqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) + return FqPolyRepMatrix(arr, base_ring(a)) end -function (a::FqPolyRepMatrixSpace)(arr::AbstractMatrix{ZZRingElem}) - _check_dim(nrows(a), ncols(a), arr) - return FqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) -end - -function (a::FqPolyRepMatrixSpace)(arr::AbstractVector{ZZRingElem}) +function (a::FqPolyRepMatrixSpace)(arr::AbstractVector{<:IntegerUnion}) _check_dim(nrows(a), ncols(a), arr) return FqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) end @@ -690,7 +680,7 @@ end function (a::FqPolyRepMatrixSpace)(arr::AbstractMatrix{FqPolyRepFieldElem}) _check_dim(nrows(a), ncols(a), arr) (length(arr) > 0 && (base_ring(a) != parent(arr[1]))) && error("Elements must have same base ring") - return FqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) + return FqPolyRepMatrix(arr, base_ring(a)) end function (a::FqPolyRepMatrixSpace)(arr::AbstractVector{FqPolyRepFieldElem}) @@ -711,7 +701,8 @@ end ############################################################################### function matrix(R::FqPolyRepField, arr::AbstractMatrix{<: Union{FqPolyRepFieldElem, ZZRingElem, Integer}}) - z = FqPolyRepMatrix(size(arr, 1), size(arr, 2), arr, R) + Base.require_one_based_indexing(arr) + z = FqPolyRepMatrix(arr, R) return z end diff --git a/src/flint/fq_nmod_mat.jl b/src/flint/fq_nmod_mat.jl index e78bd2d8d..8f838b64a 100644 --- a/src/flint/fq_nmod_mat.jl +++ b/src/flint/fq_nmod_mat.jl @@ -656,22 +656,12 @@ function (a::fqPolyRepMatrixSpace)(b::fqPolyRepFieldElem) return fqPolyRepMatrix(nrows(a), ncols(a), b) end -function (a::fqPolyRepMatrixSpace)(arr::AbstractMatrix{T}) where {T <: Integer} +function (a::fqPolyRepMatrixSpace)(arr::AbstractMatrix{<:IntegerUnion}) _check_dim(nrows(a), ncols(a), arr) - return fqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) -end - -function (a::fqPolyRepMatrixSpace)(arr::AbstractVector{T}) where {T <: Integer} - _check_dim(nrows(a), ncols(a), arr) - return fqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) + return fqPolyRepMatrix(arr, base_ring(a)) end -function (a::fqPolyRepMatrixSpace)(arr::AbstractMatrix{ZZRingElem}) - _check_dim(nrows(a), ncols(a), arr) - return fqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) -end - -function (a::fqPolyRepMatrixSpace)(arr::AbstractVector{ZZRingElem}) +function (a::fqPolyRepMatrixSpace)(arr::AbstractVector{<:IntegerUnion}) _check_dim(nrows(a), ncols(a), arr) return fqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) end @@ -679,7 +669,7 @@ end function (a::fqPolyRepMatrixSpace)(arr::AbstractMatrix{fqPolyRepFieldElem}) _check_dim(nrows(a), ncols(a), arr) (length(arr) > 0 && (base_ring(a) != parent(arr[1]))) && error("Elements must have same base ring") - return fqPolyRepMatrix(nrows(a), ncols(a), arr, base_ring(a)) + return fqPolyRepMatrix(arr, base_ring(a)) end function (a::fqPolyRepMatrixSpace)(arr::AbstractVector{fqPolyRepFieldElem}) @@ -700,7 +690,8 @@ end ############################################################################### function matrix(R::fqPolyRepField, arr::AbstractMatrix{<: Union{fqPolyRepFieldElem, ZZRingElem, Integer}}) - z = fqPolyRepMatrix(size(arr, 1), size(arr, 2), arr, R) + Base.require_one_based_indexing(arr) + z = fqPolyRepMatrix(arr, R) return z end From 46babf0fb297faa8446f93840bc8645b07a6a31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 25 Oct 2024 11:45:53 +0200 Subject: [PATCH 7/7] fix --- src/flint/FlintTypes.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index 5f9887c59..9ca8d5d2e 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -5573,8 +5573,7 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} end function FqMatrix(arr::AbstractMatrix{<:Union{FqFieldElem,ZZRingElem,Integer}}, ctx::FqField) - r = nrows(arr) - c = ncols(arr) + (r, c) = size(arr) z = FqMatrix(r, c, ctx) for i = 1:r, j = 1:c @inbounds z[i, j] = arr[i, j] @@ -5677,8 +5676,7 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} end function FqPolyRepMatrix(arr::AbstractMatrix{<:Union{FqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::FqPolyRepField) - r = nrows(arr) - c = ncols(arr) + (r, c) = size(arr) z = FqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c @inbounds z[i, j] = arr[i, j] @@ -5756,8 +5754,7 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} end function fqPolyRepMatrix(arr::AbstractMatrix{<:Union{fqPolyRepFieldElem,ZZRingElem,Integer}}, ctx::fqPolyRepField) - r = nrows(arr) - c = ncols(arr) + (r, c) = size(arr) z = fqPolyRepMatrix(r, c, ctx) for i = 1:r, j = 1:c @inbounds z[i, j] = arr[i, j]