From e223763b75db2e8a24a19b198537d4ef0797bab5 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 10 Sep 2017 21:41:36 +0200 Subject: [PATCH] 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)