Skip to content

Commit

Permalink
Merge pull request #127 from MichielStock/copy
Browse files Browse the repository at this point in the history
Copy
  • Loading branch information
MichielStock authored Jun 15, 2023
2 parents b8b9fb3 + 9b11c33 commit a05cd80
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Kronecker"
uuid = "2c470bb0-bcc8-11e8-3dad-c9649493f05e"
authors = ["MichielStock <[email protected]>"]
version = "0.5.4"
version = "0.5.5"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
6 changes: 5 additions & 1 deletion src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ Returns a the size of an `GeneralizedKroneckerProduct` instance.
"""
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.similar(K::AbstractKroneckerProduct) = kronecker(similar(K.A), similar(K.B))

# CHECKS

"""
Expand Down Expand Up @@ -406,7 +411,6 @@ end
return _kron!(C, As, Bs, f)
end


"""
Matrix(K::GeneralizedKroneckerProduct)
Expand Down
4 changes: 4 additions & 0 deletions src/kroneckerpowers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ getmatrices(K::KroneckerPower) = (K.pow == 2 ? K.A : KroneckerPower(K.A, K.pow -

lastmatrix(K::KroneckerPower) = K.A

Base.copy(K::KroneckerPower) = kronecker(copy(K.A), K.pow)
Base.deepcopy(K::KroneckerPower) = kronecker(deepcopy(K.A), K.pow)
Base.similar(K::KroneckerPower) = kronecker(similar(K.A), K.pow)

order(K::KroneckerPower) = K.pow
Base.size(K::KroneckerPower) = size(K.A) .^ K.pow
issquare(K::KroneckerPower) = issquare(K.A)
Expand Down
4 changes: 4 additions & 0 deletions src/kroneckersum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ struct KroneckerSum{T<:Any,TA<:AbstractMatrix,TB<:AbstractMatrix} <: AbstractKro
end
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))

order(M::AbstractKroneckerSum) = order(M.A) + order(M.B)
issquare(M::AbstractKroneckerSum) = true

Expand Down
8 changes: 8 additions & 0 deletions test/testbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
@test K isa AbstractKroneckerProduct{Float64}

@test K isa AbstractMatrix{Float64}

@test copy(K) isa AbstractKroneckerProduct

Kcopy = deepcopy(K)
@test Kcopy K
@test Kcopy isa AbstractKroneckerProduct

@test similar(K) isa AbstractKroneckerProduct
end

@testset "Using vectors" begin
Expand Down
8 changes: 8 additions & 0 deletions test/testkroneckerpowers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

@test sum(K1) sum(K1dense)

@test copy(K2) isa KroneckerPower

Kcopy = deepcopy(K2)
@test Kcopy K2
@test Kcopy isa KroneckerPower

@test similar(K2) isa KroneckerPower

end

@testset "Inplace scaling" begin
Expand Down
8 changes: 8 additions & 0 deletions test/testkroneckersum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

@test issquare(KS)

@test copy(KS) isa KroneckerSum

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

@test similar(KS) isa KroneckerSum

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

0 comments on commit a05cd80

Please sign in to comment.