Skip to content

Commit

Permalink
Merge pull request #131 from MichielStock/copy!
Browse files Browse the repository at this point in the history
Copy!
  • Loading branch information
MichielStock authored Oct 24, 2023
2 parents 71a6996 + 4a86d56 commit 9e2d1c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ size(K::GeneralizedKroneckerProduct, dim::Integer) = size(K)[dim]

Base.copy(K::AbstractKroneckerProduct) = kronecker(copy(K.A), copy(K.B))
Base.deepcopy(K::AbstractKroneckerProduct) = kronecker(deepcopy(K.A), deepcopy(K.B))
Base.copy!(K1::AbstractKroneckerProduct, K2::AbstractKroneckerProduct) = begin
Base.copy!(K1.A, K2.A)
Base.copy!(K1.B, K2.B)
return K1
end

Base.similar(K::AbstractKroneckerProduct) = kronecker(similar(K.A), similar(K.B))

Expand Down
5 changes: 5 additions & 0 deletions src/kroneckersum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ end
Base.copy(K::KroneckerSum) = kroneckersum(copy(K.A), copy(K.B))
Base.deepcopy(K::KroneckerSum) = kroneckersum(deepcopy(K.A), deepcopy(K.B))
Base.similar(K::KroneckerSum) = kroneckersum(similar(K.A), similar(K.B))
Base.copy!(K1::KroneckerSum, K2::KroneckerSum) = begin
Base.copy!(K1.A, K2.A)
Base.copy!(K1.B, K2.B)
return K1
end

order(M::AbstractKroneckerSum) = order(M.A) + order(M.B)
issquare(M::AbstractKroneckerSum) = true
Expand Down
6 changes: 6 additions & 0 deletions test/testbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
@test Kcopy isa AbstractKroneckerProduct

@test similar(K) isa AbstractKroneckerProduct

if VERSION v"1.1"
Kcopy = similar(A) similar(B)
@test_nowarn copy!(Kcopy, K)
@test Kcopy K
end
end

@testset "Using vectors" begin
Expand Down
8 changes: 7 additions & 1 deletion test/testkroneckersum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@

@test issquare(KS)

@test copy(KS) isa KroneckerSum
@test copy(KS) isa KroneckerSum

KScopy = deepcopy(KS)
@test KScopy KS
@test KScopy isa KroneckerSum

@test similar(KS) isa KroneckerSum

if VERSION v"1.1"
KScopy = similar(A) similar(B)
@test_nowarn copy!(KScopy, KS)
@test KScopy KS
end

IC = oneunit(C)
KS3 = A B C
KS3AB = (A B) C
Expand Down

0 comments on commit 9e2d1c8

Please sign in to comment.