Skip to content

Commit

Permalink
Untangle docstrings for similar, zero; MatElem, MatRingElem
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Nov 12, 2024
1 parent f7da828 commit cea07e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
30 changes: 8 additions & 22 deletions src/MatRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,46 +79,32 @@ is_finite(R::MatRing) = iszero(nrows(a)) || is_finite(base_ring(R))
###############################################################################

@doc raw"""
similar(x::Generic.MatrixElem, R::NCRing, r::Int, c::Int)
similar(x::Generic.MatrixElem, R::NCRing)
similar(x::Generic.MatrixElem, r::Int, c::Int)
similar(x::Generic.MatrixElem)
similar(x::MatRingElem, R::NCRing, n::Int)
similar(x::MatRingElem, R::NCRing)
similar(x::MatRingElem, n::Int)
similar(x::MatRingElem)
Create an uninitialized matrix over the given ring and dimensions,
with defaults based upon the given source matrix `x`.
Create an uninitialized matrix ring element over the given ring and dimension,
with defaults based upon the given source matrix ring element `x`.
"""
function similar(x::MatRingElem, R::NCRing, n::Int)
function similar(x::MatRingElem, R::NCRing=base_ring(x), n::Int=degree(x))
TT = elem_type(R)
M = Matrix{TT}(undef, (n, n))
return Generic.MatRingElem{TT}(R, M)
end

similar(x::MatRingElem, R::NCRing=base_ring(x)) = similar(x, R, degree(x))

similar(x::MatRingElem, n::Int) = similar(x, base_ring(x), n)

function similar(x::MatRingElem{T}, R::NCRing, m::Int, n::Int) where T <: NCRingElement
m != n && error("Dimensions don't match in similar")
return similar(x, R, n)
end

similar(x::MatRingElem, m::Int, n::Int) = similar(x, base_ring(x), m, n)

@doc raw"""
zero(x::MatrixElem, R::NCRing=base_ring(x))
zero(x::MatrixElem, R::NCRing, r::Int, c::Int)
zero(x::MatrixElem, r::Int, c::Int)
zero(x::MatRingElem, R::NCRing, n::Int)
zero(x::MatRingElem, R::NCRing)
zero(x::MatRingElem, n::Int)
zero(x::MatRingElem)
Create a zero matrix over the given ring and dimensions,
with defaults based upon the given source matrix `x`.
Create a zero matrix ring element over the given ring and dimension,
with defaults based upon the given source matrix ring element `x`.
"""
zero(x::MatRingElem, R::NCRing, n::Int) = zero!(similar(x, R, n))
zero(x::MatRingElem, R::NCRing=base_ring(x), n::Int=degree(x)) = zero!(similar(x, R, n))
zero(x::MatRingElem, n::Int) = zero!(similar(x, n))

################################################################################
Expand Down
41 changes: 25 additions & 16 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,6 @@ Return the zero matrix in the given matrix space.
"""
zero(a::MatSpace) = a()

@doc raw"""
zero(x::MatrixElem{T}, R::NCRing, r::Int, c::Int) where T <: NCRingElement
zero(x::MatrixElem{T}, r::Int, c::Int) where T <: NCRingElement
zero(x::MatrixElem{T}, R::NCRing) where T <: NCRingElement
zero(x::MatrixElem{T}) where T <: NCRingElement
Return a zero matrix similar to the given matrix, with optionally different
base ring or dimensions.
"""
zero(x::MatrixElem{T}, R::NCRing) where T <: NCRingElement = zero(x, R, nrows(x), ncols(x))
zero(x::MatrixElem{T}) where T <: NCRingElement = zero(x, nrows(x), ncols(x))
zero(x::MatrixElem{T}, R::NCRing, r::Int, c::Int) where T <: NCRingElement = zero!(similar(x, R, r, c))
zero(x::MatrixElem{T}, r::Int, c::Int) where T <: NCRingElement = zero!(similar(x, r, c))

@doc raw"""
one(a::MatSpace)
Expand Down Expand Up @@ -400,14 +386,37 @@ end
#
###############################################################################

similar(x::MatElem, R::NCRing, r::Int, c::Int) = zero_matrix(R, r, c)
@doc raw"""
similar(x::MatElem{T}, R::NCRing, r::Int, c::Int) where T <: NCRingElement
similar(x::MatElem{T}, R::NCRing) where T <: NCRingElement
similar(x::MatElem{T}, r::Int, c::Int) where T <: NCRingElement
similar(x::MatElem{T}) where T <: NCRingElement
Create an uninitialized matrix over the given ring and dimensions,
with defaults based upon the given source matrix `x`.
"""
similar(x::MatElem, R::NCRing, r::Int, c::Int) = zero_matrix(R, r, c)

similar(x::MatElem, R::NCRing) = similar(x, R, nrows(x), ncols(x))

similar(x::MatElem, r::Int, c::Int) = similar(x, base_ring(x), r, c)

similar(x::MatElem) = similar(x, nrows(x), ncols(x))

@doc raw"""
zero(x::MatElem{T}, R::NCRing, r::Int, c::Int) where T <: NCRingElement
zero(x::MatElem{T}, r::Int, c::Int) where T <: NCRingElement
zero(x::MatElem{T}, R::NCRing) where T <: NCRingElement
zero(x::MatElem{T}) where T <: NCRingElement
Create an zero matrix over the given ring and dimensions,
with defaults based upon the given source matrix `x`.
"""
zero(x::MatElem{T}, R::NCRing) where T <: NCRingElement = zero(x, R, nrows(x), ncols(x))
zero(x::MatElem{T}) where T <: NCRingElement = zero(x, nrows(x), ncols(x))
zero(x::MatElem{T}, R::NCRing, r::Int, c::Int) where T <: NCRingElement = zero!(similar(x, R, r, c))
zero(x::MatElem{T}, r::Int, c::Int) where T <: NCRingElement = zero!(similar(x, r, c))

###############################################################################
#
# Canonicalisation
Expand Down Expand Up @@ -1011,7 +1020,7 @@ function +(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
end

@doc raw"""
+(x::Generic.MatrixElem{T}, y::T) where {T <: RingElem}
+(x::MatrixElem{T}, y::T) where {T <: RingElem}
Return $x + S(y)$ where $S$ is the parent of $x$.
"""
Expand Down

0 comments on commit cea07e2

Please sign in to comment.