Skip to content

Commit 50eb266

Browse files
committed
Add many @req !is_trivial checks
1 parent 0e8c63d commit 50eb266

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed

src/Fraction.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ that it will always be returned by a call to the constructor when the same
823823
base ring $R$ is supplied.
824824
"""
825825
function fraction_field(R::Ring; cached::Bool=true)
826+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
826827
return Generic.fraction_field(R; cached=cached)
827828
end
828829

src/MPoly.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,5 +1508,7 @@ true
15081508
Like [`polynomial_ring(R::Ring, s::Vector{Symbol})`](@ref) but return only the
15091509
multivariate polynomial ring.
15101510
"""
1511-
polynomial_ring_only(R::T, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring =
1512-
mpoly_ring_type(T)(R, s, internal_ordering, cached)
1511+
function polynomial_ring_only(R::T, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring
1512+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
1513+
return mpoly_ring_type(T)(R, s, internal_ordering, cached)
1514+
end

src/MatRing.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,5 +441,6 @@ Return parent object corresponding to the ring of $n\times n$ matrices over
441441
the ring $R$.
442442
"""
443443
function matrix_ring(R::NCRing, n::Int)
444-
Generic.matrix_ring(R, n)
444+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
445+
return Generic.matrix_ring(R, n)
445446
end

src/Matrix.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6633,6 +6633,7 @@ randmat_with_rank(S::MatSpace{T}, rank::Int, v...) where {T <: RingElement} =
66336633
Constructs the matrix over $R$ with entries as in `arr`.
66346634
"""
66356635
function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T}
6636+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
66366637
if elem_type(R) === T && all(e -> parent(e) === R, arr)
66376638
z = Generic.MatSpaceElem{elem_type(R)}(R, arr)
66386639
return z
@@ -6643,6 +6644,7 @@ function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T}
66436644
end
66446645

66456646
function matrix(R::NCRing, arr::MatElem)
6647+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
66466648
return map_entries(R, arr)
66476649
end
66486650

@@ -6681,6 +6683,7 @@ Constructs the $r \times c$ matrix over $R$, where the entries are taken
66816683
row-wise from `arr`.
66826684
"""
66836685
function matrix(R::NCRing, r::Int, c::Int, arr::AbstractVecOrMat{T}) where T
6686+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
66846687
_check_dim(r, c, arr)
66856688
ndims(arr) == 2 && return matrix(R, arr)
66866689
if elem_type(R) === T && all(e -> parent(e) === R, arr)
@@ -7062,6 +7065,7 @@ the ring $R$.
70627065
function matrix_space(R::NCRing, r::Int, c::Int; cached::Bool = true)
70637066
# TODO: the 'cached' argument is ignored and mainly here for backwards compatibility
70647067
# (and perhaps future compatibility, in case we need it again)
7068+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
70657069
(r < 0 || c < 0) && error("Dimensions must be non-negative")
70667070
T = elem_type(R)
70677071
return MatSpace{T}(R, r, c)

src/NCPoly.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,10 @@ end
764764
Like [`polynomial_ring(R::NCRing, s::Symbol)`](@ref) but return only the
765765
polynomial ring.
766766
"""
767-
polynomial_ring_only(R::T, s::Symbol; cached::Bool=true) where T<:NCRing =
768-
dense_poly_ring_type(T)(R, s, cached)
767+
function polynomial_ring_only(R::T, s::Symbol; cached::Bool=true) where T<:NCRing
768+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
769+
return dense_poly_ring_type(T)(R, s, cached)
770+
end
769771

770772
# Simplified constructor
771773

src/Residue.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ to the constructor with the same base ring $R$ and element $a$. A modulus
450450
of zero is not supported and throws an exception.
451451
"""
452452
function residue_ring(R::Ring, a::RingElement; cached::Bool = true)
453+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
453454
# Modulus of zero cannot be supported. E.g. A C library could not be expected to
454455
# do matrices over Z/0 using a Z/nZ type. The former is multiprecision, the latter not.
455456
iszero(a) && throw(DomainError(a, "Modulus must be nonzero"))
@@ -459,6 +460,7 @@ function residue_ring(R::Ring, a::RingElement; cached::Bool = true)
459460
end
460461

461462
function residue_ring(R::PolyRing, a::RingElement; cached::Bool = true)
463+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
462464
iszero(a) && throw(DomainError(a, "Modulus must be nonzero"))
463465
!is_unit(leading_coefficient(a)) && throw(DomainError(a, "Non-invertible leading coefficient"))
464466
T = elem_type(R)

src/ResidueField.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ residue ring parent object is cached and returned for any subsequent calls
490490
to the constructor with the same base ring $R$ and element $a$.
491491
"""
492492
function residue_field(R::Ring, a::RingElement; cached::Bool = true)
493+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
493494
iszero(a) && throw(DivideError())
494495
T = elem_type(R)
495496
S = EuclideanRingResidueField{T}(R(a), cached)

0 commit comments

Comments
 (0)