diff --git a/src/base.jl b/src/base.jl index a8165d5..e58342a 100644 --- a/src/base.jl +++ b/src/base.jl @@ -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)) diff --git a/src/kroneckersum.jl b/src/kroneckersum.jl index 177d952..f5ceb8b 100644 --- a/src/kroneckersum.jl +++ b/src/kroneckersum.jl @@ -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 diff --git a/test/testbase.jl b/test/testbase.jl index 22bce9f..290079e 100644 --- a/test/testbase.jl +++ b/test/testbase.jl @@ -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 diff --git a/test/testkroneckersum.jl b/test/testkroneckersum.jl index ddf9fc1..4a6a6e4 100644 --- a/test/testkroneckersum.jl +++ b/test/testkroneckersum.jl @@ -24,7 +24,7 @@ @test issquare(KS) - @test copy(KS) isa KroneckerSum + @test copy(KS) isa KroneckerSum KScopy = deepcopy(KS) @test KScopy ≈ KS @@ -32,6 +32,12 @@ @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