Skip to content

Commit

Permalink
More helpful error for diagonal_matrix (#1876)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt authored Oct 20, 2024
1 parent ca2faf2 commit cc5db52
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Create the block diagonal matrix whose blocks are given by the matrices in `V`.
There must be at least one matrix in V.
"""
function block_diagonal_matrix(V::Vector{<:MatElem{T}}) where T <: NCRingElement
length(V) > 0 || error("At least one matrix is required")
@req !isempty(V) "Cannot infer base ring from empty vector; consider passing the desired base ring as first argument to `block_diagonal_matrix`"
rows = sum(nrows(N) for N in V)
cols = sum(ncols(N) for N in V)
R = base_ring(V[1])
Expand Down Expand Up @@ -6865,7 +6865,10 @@ function diagonal_matrix(x::T, xs::T...) where {T<:NCRingElement}
return diagonal_matrix([x, xs...])
end

diagonal_matrix(x::Vector{<:NCRingElement}) = diagonal_matrix(parent(x[1]), x)
function diagonal_matrix(x::Vector{<:NCRingElement})
@req !isempty(x) "Cannot infer base ring from empty vector; consider passing the desired base ring as first argument to `diagonal_matrix`"
return diagonal_matrix(parent(x[1]), x)
end

@doc raw"""
diagonal_matrix(V::Vector{T}) where T <: MatElem -> MatElem
Expand Down

0 comments on commit cc5db52

Please sign in to comment.