From 7d4737f3f74490a64b26af5e0e8ef0d951338af7 Mon Sep 17 00:00:00 2001 From: Erik Paemurru Date: Fri, 27 Sep 2024 15:01:36 +0200 Subject: [PATCH 1/4] Add `components` method --- docs/src/manual/abelian/elements.md | 1 + src/GrpAb/Elem.jl | 9 +++++++++ src/exports.jl | 1 + 3 files changed, 11 insertions(+) diff --git a/docs/src/manual/abelian/elements.md b/docs/src/manual/abelian/elements.md index 1434705bbe..8ebee2ca9c 100644 --- a/docs/src/manual/abelian/elements.md +++ b/docs/src/manual/abelian/elements.md @@ -19,6 +19,7 @@ parent(x::FinGenAbGroupElem) ### Access ```@docs +components(x::FinGenAbGroupElem) getindex(x::FinGenAbGroupElem, i::Int) ``` diff --git a/src/GrpAb/Elem.jl b/src/GrpAb/Elem.jl index 402921cc2e..77da2f92cc 100644 --- a/src/GrpAb/Elem.jl +++ b/src/GrpAb/Elem.jl @@ -137,6 +137,15 @@ end # ################################################################################ +@doc raw""" + components(x::FinGenAbGroupElem) -> Vector{ZZRingElem} + +Returns the components of the element $x$. +""" +function components(x::FinGenAbGroupElem) + return x.coeff +end + @doc raw""" getindex(x::FinGenAbGroupElem, i::Int) -> ZZRingElem diff --git a/src/exports.jl b/src/exports.jl index da71484562..379cfbd9d1 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -206,6 +206,7 @@ export codifferent export codomain export coefficient_ideals export coefficients +export components export coinvariant_lattice export cokernel export collapse_top_layer From d3d063e265e5762b5c074fae88bd7ae7252ba7f6 Mon Sep 17 00:00:00 2001 From: Erik Paemurru Date: Fri, 11 Oct 2024 16:53:38 +0200 Subject: [PATCH 2/4] Add another getindex method To be able to call `x[begin:end]`. --- docs/src/manual/abelian/elements.md | 2 +- src/GrpAb/Elem.jl | 37 ++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/docs/src/manual/abelian/elements.md b/docs/src/manual/abelian/elements.md index 8ebee2ca9c..e0b52b56a4 100644 --- a/docs/src/manual/abelian/elements.md +++ b/docs/src/manual/abelian/elements.md @@ -19,7 +19,7 @@ parent(x::FinGenAbGroupElem) ### Access ```@docs -components(x::FinGenAbGroupElem) +getindex(x::FinGenAbGroupElem, v::AbstractVector{Int}) getindex(x::FinGenAbGroupElem, i::Int) ``` diff --git a/src/GrpAb/Elem.jl b/src/GrpAb/Elem.jl index 77da2f92cc..50aca85248 100644 --- a/src/GrpAb/Elem.jl +++ b/src/GrpAb/Elem.jl @@ -138,21 +138,42 @@ end ################################################################################ @doc raw""" - components(x::FinGenAbGroupElem) -> Vector{ZZRingElem} + getindex(x::FinGenAbGroupElem, i::Int) -> ZZRingElem -Returns the components of the element $x$. +Returns the $i$-th component of the element $x$. """ -function components(x::FinGenAbGroupElem) - return x.coeff +function getindex(x::FinGenAbGroupElem, i::Int) + return x.coeff[1, i] end @doc raw""" - getindex(x::FinGenAbGroupElem, i::Int) -> ZZRingElem + getindex(x::FinGenAbGroupElem, v::AbstractVector{Int}) -> Vector{ZZRingElem} -Returns the $i$-th component of the element $x$. +Returns the $i$-th components of the element $x$ where $i \in v$. + +!!! note + This function is inefficient since the elements are internally stored using ZZMatrix but this function outputs a vector. """ -function getindex(x::FinGenAbGroupElem, i::Int) - return x.coeff[1, i] +function getindex(x::FinGenAbGroupElem, v::AbstractVector{Int}) + return [x.coeff[1, i] for i in v] +end + +@doc raw""" + firstindex(x::FinGenAbGroupElem) -> Int64 + +Returns the first component of the element $x$. +""" +function Base.firstindex(x::FinGenAbGroupElem) + return Int64(1) +end + +@doc raw""" + lastindex(x::FinGenAbGroupElem) -> Int64 + +Returns the last component of the element $x$. +""" +function Base.lastindex(x::FinGenAbGroupElem) + return ngens(parent(x)) end ################################################################################ From 72882c1a6fc62d56bb71b996b59f073741544aa0 Mon Sep 17 00:00:00 2001 From: Erik Paemurru <143521159+paemurru@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:48:19 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Tommy Hofmann --- src/GrpAb/Elem.jl | 12 +----------- src/exports.jl | 1 - 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/GrpAb/Elem.jl b/src/GrpAb/Elem.jl index 50aca85248..29ec93ea13 100644 --- a/src/GrpAb/Elem.jl +++ b/src/GrpAb/Elem.jl @@ -158,20 +158,10 @@ function getindex(x::FinGenAbGroupElem, v::AbstractVector{Int}) return [x.coeff[1, i] for i in v] end -@doc raw""" - firstindex(x::FinGenAbGroupElem) -> Int64 - -Returns the first component of the element $x$. -""" function Base.firstindex(x::FinGenAbGroupElem) - return Int64(1) + return Int(1) end -@doc raw""" - lastindex(x::FinGenAbGroupElem) -> Int64 - -Returns the last component of the element $x$. -""" function Base.lastindex(x::FinGenAbGroupElem) return ngens(parent(x)) end diff --git a/src/exports.jl b/src/exports.jl index 379cfbd9d1..da71484562 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -206,7 +206,6 @@ export codifferent export codomain export coefficient_ideals export coefficients -export components export coinvariant_lattice export cokernel export collapse_top_layer From af3e7cd1e1ef17b1cab99b8636887cd37cf614a7 Mon Sep 17 00:00:00 2001 From: Erik Paemurru Date: Fri, 18 Oct 2024 16:17:03 +0200 Subject: [PATCH 4/4] Add tests --- test/GrpAb/Elem.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/GrpAb/Elem.jl b/test/GrpAb/Elem.jl index 2e33680942..f767a82dec 100644 --- a/test/GrpAb/Elem.jl +++ b/test/GrpAb/Elem.jl @@ -6,12 +6,14 @@ a = @inferred FinGenAbGroupElem(G, N) @test parent(a) == G @test a.coeff == N + @test a[begin:end] == [0, 0, 0] G = @inferred abelian_group([3, 0]) N = FlintZZ[1 1] a = @inferred FinGenAbGroupElem(G, N) @test @inferred parent(a) == G @test a.coeff == N + @test a[begin:end] == [1, 1] N = matrix(FlintZZ, 1, 2, [ 1, 1 ]) a = @inferred G(N) @@ -21,6 +23,7 @@ a = @inferred G(N) @test @inferred parent(a) == G @test a.coeff == transpose(N) + @test a[begin:end] == [1, 1] end @testset "Generators" begin