Skip to content

Commit

Permalink
feat: add cache argument for GF
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Apr 5, 2024
1 parent 992ea59 commit 76157e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AbstractAlgebra"
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
version = "0.40.6"
version = "0.40.7"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
4 changes: 2 additions & 2 deletions src/julia/GF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ By default, the integer $p$ is checked with a probabilistic algorithm for primal
When `check == false`, no check is made, but the behaviour of the resulting object
is undefined if $p$ is composite.
"""
function GF(p::T; check::Bool=true) where T <: Integer
function GF(p::T; cached::Bool = true, check::Bool=true) where T <: Integer
check && !is_probable_prime(p) && throw(DomainError(p, "Characteristic is not prime in GF(p)"))
return GFField{T}(p)
return GFField{T}(p; cached = cached)
end
8 changes: 5 additions & 3 deletions src/julia/JuliaTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ end
mutable struct GFField{T <: Integer} <: FinField
p::T

function GFField{T}(p::T) where T <: Integer
if haskey(GFFieldID, (T, p))
function GFField{T}(p::T; cached::Bool = true) where T <: Integer
if cached && haskey(GFFieldID, (T, p))
z = GFFieldID[T, p]::GFField{T}
else
z = new{T}(p)
GFFieldID[T, p] = z
if cached
GFFieldID[T, p] = z
end
end
return z
end
Expand Down
2 changes: 2 additions & 0 deletions test/julia/GFElem-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ end
end

@testset "Julia.GFElem.constructors" begin
@test GF(2, cached = false) !== GF(2, cached = false)
@test GF(2) === GF(2)
@test_throws DomainError GF(4)
@test_throws DomainError GF(4, check=true)
F = GF(4, check=false)
Expand Down

0 comments on commit 76157e9

Please sign in to comment.