Is there an efficient way to associate a value with a parameterized type.For exa

Is there an efficient way to associate a value with a parameterized type.
For example:
struct GaloisField{p,r}; val::Int end

+(a::G, b::G} where G<:GaloisField = addop(a.val, b.val, logtable(G))

Memoization of logtable or using a global dictionary is not fast enough.

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

1 Like

The following post of @benoitrichard gave the solution:
I think what you need is a generated function then

@generated function logtable(::Type{G}) where {p, r, G <: GaloisField{p, r}}
lg = _logtable(p, r) # The actual computation
return :($lg)
end

That way the actual logtable will be comptued only once per type

2 Likes