Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy! #131

Merged
merged 4 commits into from
Oct 24, 2023
Merged

Copy! #131

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading