Skip to content

Commit

Permalink
ToricVarieties: Code improvements (#1099)
Browse files Browse the repository at this point in the history
* ToricVarieties: General code improvements

* ToricVarieties: Use @attr for more functions
  • Loading branch information
HereAround authored Feb 17, 2022
1 parent 8f19d50 commit fc36c05
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 45 deletions.
29 changes: 12 additions & 17 deletions src/ToricVarieties/NormalToricVarieties/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,10 @@ end
export cox_ring


function _minimal_nonfaces(v::AbstractNormalToricVariety)
return get_attribute(v, :minimal_nonfaces) do
I = ray_indices(maximal_cones(v))
K = SimplicialComplex(I)
return minimal_nonfaces(IncidenceMatrix, K)
end
@attr Polymake.IncidenceMatrixAllocated{Polymake.NonSymmetric} function _minimal_nonfaces(v::AbstractNormalToricVariety)
I = ray_indices(maximal_cones(v))
K = SimplicialComplex(I)
return minimal_nonfaces(IncidenceMatrix, K)
end

@doc Markdown.doc"""
Expand Down Expand Up @@ -201,17 +199,14 @@ stanley_reisner_ideal(v::AbstractNormalToricVariety) = stanley_reisner_ideal(cox
export stanley_reisner_ideal



function _irrelevant_ideal_monomials(v::AbstractNormalToricVariety)
return get_attribute!(v, :irrelevant_ideal_monomials) do
mc = ray_indices(maximal_cones(v))
result = Vector{Vector{Int}}()
onesv = ones(Int, Polymake.ncols(mc))
for i in 1:Polymake.nrows(mc)
push!(result, onesv - Vector{Int}(mc[i,:]))
end
return result
end::Vector{Vector{Int}}
@attr Vector{Vector{Int}} function _irrelevant_ideal_monomials(v::AbstractNormalToricVariety)
mc = ray_indices(maximal_cones(v))
result = Vector{Vector{Int}}()
onesv = ones(Int, Polymake.ncols(mc))
for i in 1:Polymake.nrows(mc)
push!(result, onesv - Vector{Int}(mc[i,:]))
end
return result
end


Expand Down
10 changes: 4 additions & 6 deletions src/ToricVarieties/ToricDivisorClasses/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ julia> toric_divisor(tdc)
A torus-invariant, prime divisor on a normal toric variety
```
"""
function toric_divisor(tdc::ToricDivisorClass)
return get_attribute!(tdc, :toric_divisor) do
f = map_from_torusinvariant_weil_divisor_group_to_class_group(toric_variety(tdc))
coeffs = vec([fmpz(x) for x in preimage(f, divisor_class(tdc)).coeff])
return ToricDivisor(toric_variety(tdc), coeffs)
end
@attr ToricDivisor function toric_divisor(tdc::ToricDivisorClass)
f = map_from_torusinvariant_weil_divisor_group_to_class_group(toric_variety(tdc))
coeffs = vec([fmpz(x) for x in preimage(f, divisor_class(tdc)).coeff])
return ToricDivisor(toric_variety(tdc), coeffs)
end
export toric_divisor
22 changes: 11 additions & 11 deletions src/ToricVarieties/ToricDivisorClasses/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#########################

@attributes mutable struct ToricDivisorClass
toric_variety::AbstractNormalToricVariety
class::GrpAbFinGenElem
function ToricDivisorClass(toric_variety::AbstractNormalToricVariety, class::GrpAbFinGenElem)
if !(parent(class) === class_group(toric_variety))
throw(ArgumentError("The class must belong to the class group of the toric variety."))
end
return new(toric_variety, class)
end
toric_variety::AbstractNormalToricVariety
class::GrpAbFinGenElem
function ToricDivisorClass(toric_variety::AbstractNormalToricVariety, class::GrpAbFinGenElem)
if parent(class) !== class_group(toric_variety)
throw(ArgumentError("The class must belong to the class group of the toric variety."))
end
return new(toric_variety, class)
end
end
export ToricDivisorClass

Expand Down Expand Up @@ -106,7 +106,7 @@ A divisor class on a normal toric variety
"""
function Base.:+(tdc1::ToricDivisorClass, tdc2::ToricDivisorClass)
# check input
if !(toric_variety(tdc1) === toric_variety(tdc2))
if toric_variety(tdc1) !== toric_variety(tdc2)
throw(ArgumentError("The toric classes must be defined on identically the same toric variety."))
end

Expand Down Expand Up @@ -137,7 +137,7 @@ A divisor class on a normal toric variety
"""
function Base.:-(tdc1::ToricDivisorClass, tdc2::ToricDivisorClass)
# check input
if !(toric_variety(tdc1) === toric_variety(tdc2))
if toric_variety(tdc1) !== toric_variety(tdc2)
throw(ArgumentError("The toric classes must be defined on identically the same toric variety."))
end

Expand Down Expand Up @@ -192,7 +192,7 @@ false
```
"""
function Base.:(==)(tdc1::ToricDivisorClass, tdc2::ToricDivisorClass)
if !(toric_variety(tdc1) === toric_variety(tdc2))
if toric_variety(tdc1) !== toric_variety(tdc2)
return false
end
return iszero(divisor_class(tdc1) - divisor_class(tdc2))
Expand Down
1 change: 1 addition & 0 deletions src/ToricVarieties/ToricDivisorClasses/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ false
```
"""
@attr Bool istrivial(tdc::ToricDivisorClass) = iszero(divisor_class(tdc))
export istrivial
6 changes: 3 additions & 3 deletions src/ToricVarieties/ToricDivisors/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ A torus-invariant, non-prime divisor on a normal toric variety
"""
function Base.:+(td1::ToricDivisor, td2::ToricDivisor)
# check input
if !(toric_variety(td1) === toric_variety(td2))
if toric_variety(td1) !== toric_variety(td2)
throw(ArgumentError("The toric divisors must be defined on identically the same toric variety."))
end

Expand Down Expand Up @@ -142,7 +142,7 @@ A torus-invariant, non-prime divisor on a normal toric variety
"""
function Base.:-(td1::ToricDivisor, td2::ToricDivisor)
# check input
if !(toric_variety(td1) === toric_variety(td2))
if toric_variety(td1) !== toric_variety(td2)
throw(ArgumentError("The toric divisors must be defined on identically the same toric variety."))
end

Expand Down Expand Up @@ -200,7 +200,7 @@ true
```
"""
function Base.:(==)(td1::ToricDivisor, td2::ToricDivisor)
if !(toric_variety(td1) === toric_variety(td2))
if toric_variety(td1) !== toric_variety(td2)
return false
end
return coefficients(td1) == coefficients(td2)
Expand Down
14 changes: 6 additions & 8 deletions src/ToricVarieties/ToricLineBundles/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ A toric line bundle on a normal toric variety
```
"""
function ToricLineBundle(v::AbstractNormalToricVariety, d::ToricDivisor)
if !(iscartier(d))
if !iscartier(d)
throw(ArgumentError("The toric divisor must be Cartier to define a toric line bundle."))
end
f = map_from_torusinvariant_cartier_divisor_group_to_picard_group(v)
Expand Down Expand Up @@ -102,7 +102,7 @@ A toric line bundle on a normal toric variety
"""
function Base.:*(l1::ToricLineBundle, l2::ToricLineBundle)
# check input
if !(toric_variety(l1) === toric_variety(l2))
if toric_variety(l1) !== toric_variety(l2)
throw(ArgumentError("The line bundles must be defined on identically the same toric variety."))
end

Expand Down Expand Up @@ -173,11 +173,9 @@ julia> StructureSheaf(v)
A toric line bundle on a normal toric variety
```
"""
function StructureSheaf(v::AbstractNormalToricVariety)
return get_attribute!(v, :structure_sheaf) do
class = zero(picard_group(v))
return ToricLineBundle(v, class)
end
@attr ToricLineBundle function StructureSheaf(v::AbstractNormalToricVariety)
class = zero(picard_group(v))
return ToricLineBundle(v, class)
end
structure_sheaf(v::AbstractNormalToricVariety) = StructureSheaf(v)
export StructureSheaf, structure_sheaf
Expand Down Expand Up @@ -208,7 +206,7 @@ true
```
"""
function Base.:(==)(l1::ToricLineBundle, l2::ToricLineBundle)
if !(toric_variety(l1) === toric_variety(l2))
if toric_variety(l1) !== toric_variety(l2)
return false
end
return iszero(divisor_class(l1) - divisor_class(l2))
Expand Down

0 comments on commit fc36c05

Please sign in to comment.