From 82ca5abed3f7747bf6eebe150132ece524f32dcc Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 30 Oct 2019 17:16:49 +0100 Subject: [PATCH] use get in create_pm --- src/GroupRings.jl | 15 +++++---------- test/runtests.jl | 9 +++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 0809128..b7c9820 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -537,7 +537,7 @@ function create_pm(basis::AbstractVector{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] = get(basis_dict, x*basis[j], 0) end end @@ -553,16 +553,13 @@ function check_pm(product_matrix, basis, twisted=false) if idx != nothing @warn("Product is not supported on basis") i,j = Tuple(idx) - x = basis[i] - if twisted - x = inv(x) - end + x = (twisted ? inv(basis[i]) : basis[i]) throw(KeyError(x*basis[j])) end return true end -function complete!(RG::GroupRing) +function complete!(RG::GroupRing, twisted::Bool=false) isdefined(RG, :basis) || throw(ArgumentError("Provide basis for completion first!")) if !isdefined(RG, :pm) initializepm!(RG, fill=false) @@ -572,13 +569,11 @@ function complete!(RG::GroupRing) warning = false for idx in findall(RG.pm .== 0) i,j = Tuple(idx) - g = RG.basis[i]*RG.basis[j] + g = (twisted ? inv(RG.basis[i]) : 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 + warning = true end end warning && @warn("Some products were not supported on basis") diff --git a/test/runtests.jl b/test/runtests.jl index 3ad1f23..7da8e90 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -61,14 +61,11 @@ using SparseArrays B = GroupRing(F, basis, d, pm) @test A == B - RF = GroupRing(F, basis, d, create_pm(basis, d, check=false)) - nz1 = count(!iszero, RF.pm) - @test nz1 > 1000 + RF = GroupRing(F, basis, cachedmul=true) + @test count(!iszero, RF.pm) == 0 GroupRings.complete!(RF) - nz2 = count(!iszero, RF.pm) - @test nz2 > nz1 - @test nz2 == 45469 + @test count(!iszero, RF.pm) == 45469 g = B() s = S[2]