Skip to content

Commit 8d1dc61

Browse files
committed
commutation_matrix * vec method
1 parent b6db6b1 commit 8d1dc61

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/additional_functions/commutation_matrix.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ Base.size(A::CommutationMatrix, dim::Integer) =
3636
Base.length(A::CommutationMatrix) = A.^2
3737
Base.getindex(A::CommutationMatrix, i::Int, j::Int) = j == A.transpose_inds[i] ? 1 : 0
3838

39+
function Base.:(*)(A::CommutationMatrix, B::AbstractVector)
40+
size(A, 2) == size(B, 1) || throw(
41+
DimensionMismatch("A has $(size(A, 2)) columns, but B has $(size(B, 1)) elements"),
42+
)
43+
return B[A.transpose_inds]
44+
end
45+
3946
function Base.:(*)(A::CommutationMatrix, B::AbstractMatrix)
4047
size(A, 2) == size(B, 1) || throw(
4148
DimensionMismatch("A has $(size(A, 2)) columns, but B has $(size(B, 1)) rows"),

test/unit_tests/matrix_helpers.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ m = 5
2121
# lmul!
2222
D = sprand(n^2, n^2, 0.1)
2323
E = copy(D)
24+
F = Matrix(E)
2425
lmul!(K, D)
2526
@test D == K * E
27+
@test D == K * F
2628
end
2729

2830
@testset "Duplication / elimination matrix" begin

0 commit comments

Comments
 (0)