Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commutation_matrix * vec method
Browse files Browse the repository at this point in the history
alyst committed Apr 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b6db6b1 commit 8d1dc61
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/additional_functions/commutation_matrix.jl
Original file line number Diff line number Diff line change
@@ -36,6 +36,13 @@ Base.size(A::CommutationMatrix, dim::Integer) =
Base.length(A::CommutationMatrix) = A.^2
Base.getindex(A::CommutationMatrix, i::Int, j::Int) = j == A.transpose_inds[i] ? 1 : 0

function Base.:(*)(A::CommutationMatrix, B::AbstractVector)
size(A, 2) == size(B, 1) || throw(
DimensionMismatch("A has $(size(A, 2)) columns, but B has $(size(B, 1)) elements"),
)
return B[A.transpose_inds]
end

function Base.:(*)(A::CommutationMatrix, B::AbstractMatrix)
size(A, 2) == size(B, 1) || throw(
DimensionMismatch("A has $(size(A, 2)) columns, but B has $(size(B, 1)) rows"),
2 changes: 2 additions & 0 deletions test/unit_tests/matrix_helpers.jl
Original file line number Diff line number Diff line change
@@ -21,8 +21,10 @@ m = 5
# lmul!
D = sprand(n^2, n^2, 0.1)
E = copy(D)
F = Matrix(E)
lmul!(K, D)
@test D == K * E
@test D == K * F
end

@testset "Duplication / elimination matrix" begin

0 comments on commit 8d1dc61

Please sign in to comment.