From 13360f832d779fa1206136c711c913164b732361 Mon Sep 17 00:00:00 2001 From: Nathanael Bosch Date: Thu, 12 Oct 2023 10:37:47 +0200 Subject: [PATCH 1/4] Add a `Base.copy!` implementation --- src/base.jl | 5 +++++ 1 file changed, 5 insertions(+) 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)) From 83c381380adaeaac37af162322cc9cfe0f824b3a Mon Sep 17 00:00:00 2001 From: Nathanael Bosch Date: Thu, 12 Oct 2023 10:44:21 +0200 Subject: [PATCH 2/4] Add some tests --- test/testbase.jl | 4 ++++ test/testkroneckersum.jl | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/testbase.jl b/test/testbase.jl index 22bce9f..430af99 100644 --- a/test/testbase.jl +++ b/test/testbase.jl @@ -50,6 +50,10 @@ @test Kcopy isa AbstractKroneckerProduct @test similar(K) isa AbstractKroneckerProduct + + Kcopy = similar(A) ⊗ similar(B) + @test_nowarn copy!(Kcopy, K) + @test Kcopy ≈ K end @testset "Using vectors" begin diff --git a/test/testkroneckersum.jl b/test/testkroneckersum.jl index ddf9fc1..ae75966 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,10 @@ @test similar(KS) isa KroneckerSum + KScopy = similar(A) ⊕ similar(B) + @test_nowarn copy!(KScopy, KS) + @test KScopy ≈ KS + IC = oneunit(C) KS3 = A ⊕ B ⊕ C KS3AB = (A ⊕ B) ⊕ C From 5791ba2afaf46c752c08d20cb875c43b2ba78e0d Mon Sep 17 00:00:00 2001 From: Nathanael Bosch Date: Thu, 12 Oct 2023 10:45:03 +0200 Subject: [PATCH 3/4] Add KroneckerSum implementation --- src/kroneckersum.jl | 5 +++++ 1 file changed, 5 insertions(+) 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 From 4a86d569e2f368f323e9f162ded59ec7638fc83c Mon Sep 17 00:00:00 2001 From: michielstock Date: Tue, 24 Oct 2023 14:51:20 +0200 Subject: [PATCH 4/4] :ambulance: restrict versions `copy!` test --- test/testbase.jl | 8 +++++--- test/testkroneckersum.jl | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/testbase.jl b/test/testbase.jl index 430af99..290079e 100644 --- a/test/testbase.jl +++ b/test/testbase.jl @@ -51,9 +51,11 @@ @test similar(K) isa AbstractKroneckerProduct - Kcopy = similar(A) ⊗ similar(B) - @test_nowarn copy!(Kcopy, K) - @test Kcopy ≈ K + 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 ae75966..4a6a6e4 100644 --- a/test/testkroneckersum.jl +++ b/test/testkroneckersum.jl @@ -32,9 +32,11 @@ @test similar(KS) isa KroneckerSum - KScopy = similar(A) ⊕ similar(B) - @test_nowarn copy!(KScopy, KS) - @test KScopy ≈ KS + 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