From e223763b75db2e8a24a19b198537d4ef0797bab5 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 10 Sep 2017 21:41:36 +0200 Subject: [PATCH 1/5] add check_pm function to test against zeros; Since we can not throw from a thread, after introduction of Threading into create_pm doesn't warn user on the possible not supported product. Indeed threading quits immediately after first error is thrown, leaving the pm matrix under-populated; we check on zeros and warn the user on the situation; --- src/GroupRings.jl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 5524863..2349831 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -518,7 +518,7 @@ function reverse_dict(iter) end function create_pm{T<:GroupElem}(basis::Vector{T}, basis_dict::Dict{T, Int}, - limit::Int=length(basis); twisted::Bool=false) + limit::Int=length(basis); twisted::Bool=false, check=true) product_matrix = zeros(Int, (limit,limit)) Threads.@threads for i in 1:limit x = basis[i] @@ -526,12 +526,29 @@ function create_pm{T<:GroupElem}(basis::Vector{T}, basis_dict::Dict{T, Int}, x = inv(x) end for j in 1:limit - product_matrix[i,j] = basis_dict[x*(basis[j])] + product_matrix[i,j] = basis_dict[x*basis[j]] end end + + check && check_pm(product_matrix, basis, twisted) + return product_matrix end +function check_pm(product_matrix, basis, twisted) + idx = findfirst(product_matrix' .== 0) + if idx != 0 + warn("Product is not supported on basis") + i,j = ind2sub(product_matrix, idx) + x = basis[i] + if twisted + x = inv(x) + end + throw(KeyError(x*basis[j])) + end + return true +end + create_pm{T<:GroupElem}(b::Vector{T}) = create_pm(b, reverse_dict(b)) function complete!(RG::GroupRing) From 61bed0f3d04035066f27913d69e5433fd33b3046 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 10 Sep 2017 21:42:45 +0200 Subject: [PATCH 2/5] allow to have 0s in completed pm --- src/GroupRings.jl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 2349831..8a2e96e 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -556,12 +556,21 @@ function complete!(RG::GroupRing) RG.basis = [elements(RG.group)...] end - fastm!(RG, fill=true) + fastm!(RG, fill=false) + warning = false for linidx in find(RG.pm .== 0) i,j = ind2sub(size(RG.pm), linidx) - RG.pm[i,j] = RG.basis_dict[RG.basis[i]*RG.basis[j]] + g = RG.basis[i]*RG.basis[j] + if haskey(RG.basis_dict, g) + RG.pm[i,j] = RG.basis_dict[g] + else + if !warning + warning = true + end + end end + warning && warn("Some products were not supported on basis") return RG end From d14c4ca0e7ae28b7be126a092a95405c4e1b4515 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 10 Sep 2017 21:43:09 +0200 Subject: [PATCH 3/5] add tests checking that comlpetions with 0s work --- test/runtests.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 36869e8..284abf8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -44,7 +44,6 @@ using Nemo F = FreeGroup(3) S = gens(F) append!(S, [inv(s) for s in S]) - S = unique(S) basis, sizes = Groups.generate_balls(S, F(), radius=4) d = GroupRings.reverse_dict(basis) @@ -58,6 +57,15 @@ using Nemo B = GroupRing(F, basis, d, pm) @test A == B + RF = GroupRing(F, basis, d, create_pm(basis, d, check=false)) + nz1 = contnz(RF.pm) + @test nz1 > 1000 + + GroupRings.complete!(RF) + nz2 = contnz(RF.pm) + @test nz2 > nz1 + @test nz2 = 45469 + g = B() s = S[2] g[s] = 1 From df2e51128d4f108c159bb77d92b45718f1fce1a3 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 10 Sep 2017 21:44:15 +0200 Subject: [PATCH 4/5] add baseless_warn global constant to suppress warnings for baseless Group Rings --- src/GroupRings.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 8a2e96e..45cbc16 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -11,6 +11,8 @@ import Base: convert, show, hash, ==, +, -, *, //, /, length, norm, rationalize, # ############################################################################### +baseless_warn = false + type GroupRing{Gr<:Group, T<:GroupElem} <: Ring group::Gr basis::Vector{T} @@ -232,7 +234,7 @@ function show(io::IO, X::GroupRingElem) end print(io, str) else - warn("Basis of the parent Group is not defined, showing coeffs") + baseless_warn && warn("Basis of the parent Group is not defined, showing coeffs") show(io, MIME("text/plain"), X.coeffs) end end @@ -257,7 +259,7 @@ function (==)(A::GroupRing, B::GroupRing) if isdefined(A, :basis) && isdefined(B, :basis) A.basis == B.basis || return false else - warn("Bases of GroupRings are not defined, comparing products mats.") + baseless_warn && warn("Bases of GroupRings are not defined, comparing products mats.") A.pm == B.pm || return false end return true From 81b7aae9d9f79d7b611fe2fcc672449f50d27ebb Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 10 Sep 2017 21:46:36 +0200 Subject: [PATCH 5/5] trivial fixes in tests --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 284abf8..795d4f6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -58,13 +58,13 @@ using Nemo @test A == B RF = GroupRing(F, basis, d, create_pm(basis, d, check=false)) - nz1 = contnz(RF.pm) + nz1 = countnz(RF.pm) @test nz1 > 1000 GroupRings.complete!(RF) - nz2 = contnz(RF.pm) + nz2 = countnz(RF.pm) @test nz2 > nz1 - @test nz2 = 45469 + @test nz2 == 45469 g = B() s = S[2]