From 2ccf4cb305df448bfdba9473b6c1cad51ba27cd0 Mon Sep 17 00:00:00 2001 From: Martin Wagner Date: Tue, 17 Sep 2024 14:30:30 +0200 Subject: [PATCH] improve type stability --- src/CharTable.jl | 8 ++++++-- src/Ortho.jl | 10 +++++----- src/Show.jl | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/CharTable.jl b/src/CharTable.jl index aef693d0..1ed92de2 100644 --- a/src/CharTable.jl +++ b/src/CharTable.jl @@ -54,7 +54,9 @@ function CharTable(order::UPoly, table::Matrix{GenericCyclo}, classinfo::Vector{ end Base.getindex(ct::CharTable, i::Integer) = ct.chars[i]::GenericCharacter -Base.getindex(ct::CharTable, i::Integer, j::Integer) = ct.chars[i].values[j]::GenericCyclo +Base.getindex(ct::CharTable, i::Integer, j::Integer) = ct[i].values[j]::GenericCyclo + +classsum(t::CharTable, class::Integer, x::Union{GenericCyclo, GenericCycloFrac}) = t.classsums[class](x)::Union{GenericCyclo, GenericCycloFrac} @doc raw""" GenericCharacter <: AbstractGenericCharacter @@ -86,6 +88,8 @@ struct GenericCharacter <: AbstractGenericCharacter params::Parameters # Info about the parameters in this character type end +charsum(c::GenericCharacter, x::Union{GenericCyclo, GenericCycloFrac}) = c.sum(x)::Union{GenericCyclo, GenericCycloFrac} + @doc raw""" (t::CharTable)(c::GenericCharacter) @@ -143,7 +147,7 @@ struct SimpleCharTable{T} <: Table end Base.getindex(ct::SimpleCharTable{T}, i::Integer) where T<:NfPoly = ct.chars[i]::SimpleGenericCharacter{T} -Base.getindex(ct::SimpleCharTable{T}, i::Integer, j::Integer) where T<:NfPoly = ct.chars[i].values[j]::T +Base.getindex(ct::SimpleCharTable{T}, i::Integer, j::Integer) where T<:NfPoly = ct[i].values[j]::T Base.setindex!(ct::SimpleCharTable{T}, v::T, i::Integer, j::Integer) where T<:NfPoly = setindex!(ct.chars[i].values, v, j) @doc raw""" diff --git a/src/Ortho.jl b/src/Ortho.jl index a965fb96..9a569194 100644 --- a/src/Ortho.jl +++ b/src/Ortho.jl @@ -24,7 +24,7 @@ function classmult(t::CharTable, class1::Int64, class2::Int64, class3::Int64) val1=shift_class_parameters(t, t[char, class1], 1) val2=shift_class_parameters(t, t[char, class2], 2) val3=shift_class_parameters(t, t[char, class3], 3) - sum+=t.order*t[char].sum(val1*val2*conj(val3))//t[char].degree # TODO move t.order* to the end of the function + sum+=t.order*charsum(t[char], val1*val2*conj(val3))//t[char].degree # TODO move t.order* to the end of the function end return shrink((t.classlength[class1]*t.classlength[class2])*sum//(t.order^2)) end @@ -72,7 +72,7 @@ function Oscar.norm(char::GenericCharacter) sum=0 for class in 1:classtypes(t) val=char[class] - sum+=t.classlength[class]*t.classsums[class](val*conj(val)) + sum+=t.classlength[class]*classsum(t, class, val*conj(val)) end return shrink(sum//t.order) end @@ -125,7 +125,7 @@ function Oscar.scalar_product(char1::GenericCharacter, char2::GenericCharacter) for class in 1:classtypes(t) val1=shift_char_parameters(t, char1[class], 1) val2=shift_char_parameters(t, char2[class], 2) - sum+=t.classlength[class]*t.classsums[class](val1*conj(val2)) + sum+=t.classlength[class]*classsum(t, class, val1*conj(val2)) end return shrink(sum//t.order) end @@ -175,7 +175,7 @@ function ortho2norm(t::CharTable, class::Int64) sum=0 for char in 1:irrchartypes(t) val=t[char, class] - sum+=t[char].sum(val*conj(val)) + sum+=charsum(t[char], val*conj(val)) end return shrink(t.classlength[class]*sum//t.order) end @@ -229,7 +229,7 @@ function ortho2scalar(t::CharTable, class1::Int64, class2::Int64) for char in 1:irrchartypes(t) val1=shift_class_parameters(t, t[char, class1], 1) val2=shift_class_parameters(t, t[char, class2], 2) - sum+=t[char].sum(val1*conj(val2)) + sum+=charsum(t[char], val1*conj(val2)) end return shrink(t.classlength[class1]*sum//t.order) end diff --git a/src/Show.jl b/src/Show.jl index 879dbab7..cbea898c 100644 --- a/src/Show.jl +++ b/src/Show.jl @@ -196,7 +196,7 @@ julia> classtypes(g) ``` """ function classtypes(t::Table) # TODO ? - length(t.chars[1].values) + length(t[1].values) end @doc raw"""