Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes for type stability #1189

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Misc/FactoredElem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@

Base.length(a::FacElem) = Base.length(a.fac)

Base.eltype(a::Type{FacElem{S, T}}) where {S, T} = Pair{S, ZZRingElem}

Check warning on line 215 in src/Misc/FactoredElem.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/FactoredElem.jl#L215

Added line #L215 was not covered by tests

check_parent(x::FacElem{S, T}, y::FacElem{S, T}) where { S, T } = base_ring(x) == base_ring(y)

################################################################################
Expand Down
9 changes: 5 additions & 4 deletions src/Misc/Integer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,20 @@ mutable struct Divisors{T}
return Divisors(FacElem(a), units=units, power=power)
end
end

Base.IteratorSize(::Divisors) = Base.HasLength()
Base.length(D::Divisors) = length(D.s)
Base.eltype(::Divisors{T}) where {T} = T
Base.eltype(::Type{Divisors{T}}) where {T} = T

function Base.iterate(D::Divisors)
function Base.iterate(D::Divisors{T}) where {T}
x = iterate(D.s)
if x === nothing
return x
end
return D.f(x[1]), x[2]
return D.f(x[1])::T, x[2]
end

function Base.iterate(D::Divisors, i)
function Base.iterate(D::Divisors{T}, i) where {T}
x = iterate(D.s, i)
if x === nothing
return x
Expand Down
2 changes: 1 addition & 1 deletion src/NumFieldOrd/NfOrd/ResidueRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ end

function one(Q::AbsOrdQuoRing)
if isdefined(Q, :one)
return deepcopy(Q.one)#elem_type(Q)(Q, one(base_ring(Q)))
return deepcopy(Q.one::elem_type(Q))#elem_type(Q)(Q, one(base_ring(Q)))
else
return elem_type(Q)(Q, one(base_ring(Q)))
end
Expand Down
32 changes: 15 additions & 17 deletions src/QuadForm/MassQuad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,28 @@ function _local_factor_cho(L, p)
_, G, S = jordan_decomposition(L, p)
k, h = residue_field(R, p)
hext = extend(h, K)
V = []
V = Tuple{eltype(S), dense_matrix_type(k)}[]

for s in S
AG = diagonal_matrix([2^(S[j] < s ? 2*(s - S[j]) : 0) * G[j] for j in 1:length(G)])
AG = diagonal_matrix(eltype(G)[2^(S[j] < s ? 2*(s - S[j]) : 0) * G[j] for j in 1:length(G)])
_,B = left_kernel(matrix(k, nrows(AG), 1, [hext(d//K(2)^s) for d in diagonal(AG)]))
@assert all(is_square(x)[1] for x in B)
B = map_entries(x -> sqrt(x), B)
BK = map_entries(x -> hext\x, B)
Q = 1//K(2)^(s + 1) * BK * AG * transpose(BK)
for i in 1:ncols(Q)
for j in 1:ncols(Q)
_Q = 1//K(2)^(s + 1) * BK * AG * transpose(BK)
for i in 1:ncols(_Q)
for j in 1:ncols(_Q)
if i > j
Q[i, j] = 0
_Q[i, j] = 0
elseif i < j
Q[i, j] *= 2
_Q[i, j] *= 2
end
end
end

Q = map_entries(hext, Q)
Q = map_entries(hext, _Q)

BB = []
BB = dense_matrix_type(k)[]
for i in 1:nrows(B)
b = zero_matrix(k, 1, nrows(B))
b[1, i] = 1
Expand All @@ -196,23 +196,22 @@ function _local_factor_cho(L, p)

VV = vector_space(k, nrows(B))

SS, mSS = sub(VV, [ VV([rad[i, j] for j in 1:ncols(rad) ]) for i in 1:nrows(rad)])
W, g = quo(VV, SS)

SS, mSS = sub(VV, elem_type(VV)[ VV(elem_type(k)[rad[i, j] for j in 1:ncols(rad)]) for i in 1:nrows(rad)])
W, g = quo(VV, SS)::Tuple{Generic.QuotientModule{elem_type(k)}, Generic.ModuleHomomorphism{elem_type(k)}}
@assert length(rels(W)) == 0

if ngens(W) == 0
push!(V, (s, zero_matrix(k, 0, 0)))
else
BBelts = elem_type(k)[]
for w in gens(W)
_w = preimage(g, w)
_w = preimage(g, w)::elem_type(VV)
for j in 1:rank(VV)
push!(BBelts, _w[j])
end
end
BB = matrix(k, ngens(W), ncols(Q), BBelts)
push!(V, (s, BB * Q * transpose(BB)))
BBB = matrix(k, ngens(W), ncols(Q), BBelts)
push!(V, (s, BBB * Q * transpose(BBB)))
end
end

Expand All @@ -224,8 +223,7 @@ function _local_factor_cho(L, p)
alpha = Int[]

for i in 1:length(G)
j = findfirst(v -> v[1] == S[i], V)
@assert j !== nothing
j = something(findfirst(v -> v[1] == S[i], V))
v = V[j]
if ncols(v[2]) != 0 && (!((S[i] - 1) in S) || !(PT[i-1])) && (!((S[i] + 1) in S) || !PT[i + 1])
push!(alpha, i)
Expand Down
Loading
Loading