Skip to content

Commit

Permalink
Rename vec for AbstractAlgebra matrices to _vec (#3387)
Browse files Browse the repository at this point in the history
* Rename `vec` for AbstractAlgebra matrices to `_vec`

* Move `_vec` to src

* Adapt callsites

(cherry picked from commit 0b282fb)
  • Loading branch information
lgoettgens authored and benlorenz committed Feb 21, 2024
1 parent 1a2a050 commit bac429a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 34 deletions.
20 changes: 2 additions & 18 deletions experimental/GModule/GModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Hecke: data
# first does a "restriction of scalars" or blow up with the rep mat
# second tries to conjugate down to k

import Oscar: gmodule, GAPWrap
import Oscar: _vec, gmodule, GAPWrap
import Oscar.GrpCoh: MultGrp, MultGrpElem

import AbstractAlgebra: Group, Module
Expand Down Expand Up @@ -1351,7 +1351,7 @@ end
function invariant_forms(C::GModule{<:Any, <:AbstractAlgebra.FPModule})
D = Oscar.dual(C)
h = hom_base(C, D)
r, k = kernel(transpose(reduce(vcat, [matrix(base_ring(C), 1, dim(C)^2, vec(x-transpose(x))) for x = h])))
r, k = kernel(transpose(reduce(vcat, [matrix(base_ring(C), 1, dim(C)^2, _vec(x-transpose(x))) for x = h])))
return [sum(h[i]*k[i, j] for i=1:length(h)) for j=1:r]
end

Expand Down Expand Up @@ -1443,22 +1443,6 @@ end
#TODO: cover all finite fields
# make the Modules work

#to bypass the vec(collect(M)) which copies twice
function Base.vec(M::Generic.Mat)
return vec(M.entries)
end

function Base.vec(M::MatElem)
r = elem_type(base_ring(M))[]
sizehint!(r, nrows(M) * ncols(M))
for j=1:ncols(M)
for i=1:nrows(M)
push!(r, M[i, j])
end
end
return r
end

function Oscar.simplify(C::GModule{<:Any, <:AbstractAlgebra.FPModule{QQFieldElem}})
return gmodule(QQ, Oscar.simplify(gmodule(ZZ, C))[1])
end
Expand Down
2 changes: 1 addition & 1 deletion experimental/Schemes/elliptic_surface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ function horizontal_decomposition(X::EllipticSurface, F::Vector{QQFieldElem})
else
found = false
for (i,(T, tor)) in enumerate(tors)
d = F2-vec(tor)
d = F2 - _vec(tor)
if all(isone(denominator(i)) for i in d)
found = true
T0 = mordell_weil_torsion(X)[i]
Expand Down
20 changes: 10 additions & 10 deletions src/AlgebraicGeometry/Surfaces/K3Auto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function BorcherdsCtx(L::ZZLat, S::ZZLat, weyl::ZZMatrix; compute_OR::Bool=true)
phi = phiSS_S*inv(i)*phi*j
img,_ = sub(ODSS,[ODSS(phi*hom(g)*inv(phi)) for g in imOR])
ds = degree(SS)
membership_test = (g->ODSS(hom(DSS,DSS,[DSS(vec(matrix(QQ, 1, ds, lift(x))*g)) for x in gens(DSS)])) in img)
membership_test = (g->ODSS(hom(DSS,DSS,[DSS(_vec(matrix(QQ, 1, ds, lift(x))*g)) for x in gens(DSS)])) in img)
end
else
membership_test(g) = is_pm1_on_discr(SS,g)
Expand Down Expand Up @@ -311,8 +311,8 @@ function rays(D::K3Chamber)
# clear denominators
Lz = ZZMatrix[change_base_ring(ZZ,i*denominator(i)) for i in Lq]
# primitive in S
Lz = ZZMatrix[divexact(i,gcd(vec(i))) for i in Lz]
@hassert :K3Auto 2 all(all(x>=0 for x in vec(r*gram_matrix(D.data.SS)*transpose(i))) for i in Lz)
Lz = ZZMatrix[divexact(i,gcd(_vec(i))) for i in Lz]
@hassert :K3Auto 2 all(all(x>=0 for x in _vec(r*gram_matrix(D.data.SS)*transpose(i))) for i in Lz)
return Lz
end

Expand Down Expand Up @@ -521,9 +521,9 @@ function enumerate_quadratic_triple(Q, b, c; algorithm=:short_vectors, equal=fal
L, p, dist = Hecke._convert_type(Q, b, QQ(c))
#@vprint :K3Auto 1 ambient_space(L), basis_matrix(L), p, dist
if equal
cv = Hecke.close_vectors(L, vec(p), dist, dist, check=false)
cv = Hecke.close_vectors(L, _vec(p), dist, dist, check=false)
else
cv = Hecke.close_vectors(L, vec(p), dist, check=false)
cv = Hecke.close_vectors(L, _vec(p), dist, check=false)
end
end
return cv
Expand Down Expand Up @@ -696,7 +696,7 @@ Return whether the isometry `g` of `S` acts as `+-1` on the discriminant group.
"""
function is_pm1_on_discr(S::ZZLat, g::ZZMatrix)
D = discriminant_group(S)
imgs = [D(vec(matrix(QQ,1,rank(S),lift(d))*g)) for d in gens(D)]
imgs = [D(_vec(matrix(QQ,1,rank(S),lift(d))*g)) for d in gens(D)]
return all(imgs[i] == gen(D, i) for i in 1:ngens(D)) || all(imgs[i] == -gen(D, i) for i in 1:ngens(D))
# OD = orthogonal_group(D)
# g1 = hom(D,D,[D(lift(d)*g) for d in gens(D)])
Expand Down Expand Up @@ -1109,7 +1109,7 @@ function _alg58_close_vector(data::BorcherdsCtx, w::ZZMatrix)
#cv = enumerate_quadratic_triple(Q,-b,-c,equal=true)
mul!(b, Qi, b)
#b = Qi*b
v = vec(b)
v = _vec(b)
upperbound = inner_product(V,v,v) + c
# solve the quadratic triple
cv = close_vectors(N, v, upperbound, upperbound, check=false)
Expand Down Expand Up @@ -1157,7 +1157,7 @@ function _walls_of_chamber(data::BorcherdsCtx, weyl_vector, algorithm::Symbol=:s
walls = Vector{ZZMatrix}(undef,d)
for i in 1:d
vs = numerator(FakeFmpqMat(walls1[i]))
g = gcd(vec(vs))
g = gcd(_vec(vs))
if g != 1
vs = divexact(vs, g)
end
Expand All @@ -1175,7 +1175,7 @@ function _walls_of_chamber(data::BorcherdsCtx, weyl_vector, algorithm::Symbol=:s
v = matrix(QQ, 1, degree(data.SS), r[i])
# rescale v to be primitive in S
vs = numerator(FakeFmpqMat(v))
g = gcd(vec(vs))
g = gcd(_vec(vs))
if g!=1
vs = divexact(vs, g)
end
Expand Down Expand Up @@ -1262,7 +1262,7 @@ Based on Algorithm 5.13 in [Shi15](@cite)
- `vS`: Given with respect to the basis of `S`.
"""
function unproject_wall(data::BorcherdsCtx, vS::ZZMatrix)
d = gcd(vec(vS*data.gramS))
d = gcd(_vec(vS*data.gramS))
v = QQ(1,d)*(vS*basis_matrix(data.S)) # primitive in Sdual
vsq = QQ((vS*data.gramS*transpose(vS))[1,1],d^2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function toric_line_bundle(v::NormalToricVarietyType, dc::ToricDivisorClass)
g = map_from_torusinvariant_cartier_divisor_group_to_torusinvariant_weil_divisor_group(v)
h = map_from_torusinvariant_cartier_divisor_group_to_picard_group(v)
cartier_class = preimage(g*f, divisor_class(dc))
td = toric_divisor(v, vec(g(cartier_class).coeff))
td = toric_divisor(v, _vec(g(cartier_class).coeff))
l = ToricLineBundle(v, h(cartier_class))
set_attribute!(td, :is_cartier, true)
set_attribute!(l, :toric_divisor, td)
Expand Down
15 changes: 15 additions & 0 deletions src/Modules/missing_functionality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,18 @@ function (==)(M1::SubquoModule{T}, M2::SubquoModule{T}) where {T<:AbsLocalizedRi
end


#to bypass the vec(collect(M)) which copies twice
function _vec(M::Generic.Mat)
return vec(M.entries)
end

function _vec(M::MatElem)
r = elem_type(base_ring(M))[]
sizehint!(r, nrows(M) * ncols(M))
for j=1:ncols(M)
for i=1:nrows(M)
push!(r, M[i, j])
end
end
return r
end
2 changes: 1 addition & 1 deletion src/Modules/mpoly-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function has_nonempty_intersection(U::MPolyProductOfMultSets, I::MPolyIdeal; che
T = pre_saturation_data(Iloc)
Bext = transpose(T * transpose(A))
#Bext = A*T
u = lcm(vec(denominator.(Bext)))
u = lcm(_vec(denominator.(Bext)))
B = map_entries(x->preimage(map_from_base_ring(Iloc), x), u*Bext)
return true, u*g, B
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function star_subdivision(Sigma::_FanLikeType, new_ray::AbstractVector{<:Integer

old_rays = matrix(ZZ, rays(Sigma))
# In case the new ray is an old ray.
new_ray_index = findfirst(i->vec(old_rays[i:i,:])==new_ray, 1:nrows(old_rays))
new_ray_index = findfirst(i->vec(old_rays[i,:])==new_ray, 1:nrows(old_rays))
new_rays = old_rays
if isnothing(new_ray_index)
new_rays = vcat(old_rays, matrix(ZZ, [new_ray]))
Expand Down
2 changes: 1 addition & 1 deletion src/PolyhedralGeometry/solving_integrally.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function solve_mixed(as::Type{SubObjectIterator{PointVector{ZZRingElem}}}, A::ZZ
@req nrows(C) == nrows(d) "solve_mixed(A,b,C,d): C and d must have the same number of rows."
@req ncols(b) == 1 "solve_mixed(A,b,C,d): b must be a matrix with a single column."
@req ncols(d) == 1 "solve_mixed(A,b,C,d): d must be a matrix with a single column."
P = polyhedron((-C, vec(-d)), (A, vec(b)))
P = polyhedron((-C, _vec(-d)), (A, _vec(b)))
if !permit_unbounded
return lattice_points(P)
else
Expand Down
2 changes: 1 addition & 1 deletion src/Rings/mpolyquo-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ function write_as_linear_combination(
for a in g
parent(a) === L || error("elements do not belong to the same ring")
end
return L.(vec(coordinates(lift(f), ideal(L, g)))[1:length(g)]) # temporary hack; to be replaced.
return L.(_vec(coordinates(lift(f), ideal(L, g)))[1:length(g)]) # temporary hack; to be replaced.
end

write_as_linear_combination(f::MPolyQuoLocRingElem, g::Vector) = write_as_linear_combination(f, parent(f).(g))
Expand Down

0 comments on commit bac429a

Please sign in to comment.