Skip to content

Commit

Permalink
Remove duplicate implementation of block diag matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Sep 14, 2023
1 parent 7ba6303 commit 8049a8c
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,31 +276,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")
rows = sum(nrows(N) for N in V)
cols = sum(ncols(N) for N in V)
R = base_ring(V[1])
M = similar(V[1], rows, cols)
start_row = 1
start_col = 1
for i = 1:length(V)
end_row = start_row + nrows(V[i]) - 1
end_col = start_col + ncols(V[i]) - 1
for j = start_row:end_row
for k = 1:start_col - 1
M[j, k] = zero(R)
end
for k = start_col:end_col
M[j, k] = V[i][j - start_row + 1, k - start_col + 1]
end
for k = end_col + 1:cols
M[j, k] = zero(R)
end
end
start_row = end_row + 1
start_col = end_col + 1
end
return M
return diagonal_matrix(V)
end

@doc raw"""
Expand All @@ -310,26 +286,7 @@ Create the block diagonal matrix over the ring `R` whose blocks are given
by the matrices in `V`. Entries are coerced into `R` upon creation.
"""
function block_diagonal_matrix(R::NCRing, V::Vector{<:Matrix{T}}) where T <: NCRingElement
if length(V) == 0
return zero_matrix(R, 0, 0)
end
rows = sum(size(N)[1] for N in V)
cols = sum(size(N)[2] for N in V)
M = zero_matrix(R, rows, cols)
start_row = 1
start_col = 1
for i = 1:length(V)
end_row = start_row + size(V[i])[1] - 1
end_col = start_col + size(V[i])[2] - 1
for j = start_row:end_row
for k = start_col:end_col
M[j, k] = R(V[i][j - start_row + 1, k - start_col + 1])
end
end
start_row = end_row + 1
start_col = end_col + 1
end
return M
return diagonal_matrix(R, V)
end

###############################################################################
Expand Down

0 comments on commit 8049a8c

Please sign in to comment.