Basic use

Compute a lazy Kronecker products between two matrices A and B by either

K = kronecker(A, B)

or, by using the binary operator:

K = A ⊗ B

Note, can be formed by typing \otimes<tab>.

The Kronecker product K behaves like a matrix, for which size(K), eltype(K) works as one would expect. Elements can be accessed via K[i,j]; every element is computed on the fly. The function collect can be used to turn K in a regular, dense matrix.

julia> using Kronecker
julia> A = randn(4, 4)4×4 Array{Float64,2}: 1.44076 1.86887 1.34913 0.0288659 -0.344788 0.229124 -0.459212 -0.336877 -0.421157 -1.63318 -1.72275 0.0477292 1.07864 0.999417 -2.25216 0.0602734
julia> B = rand(1:10, 5, 7)5×7 Array{Int64,2}: 2 3 5 7 3 3 3 8 7 6 8 10 7 9 9 5 3 3 5 3 2 1 5 2 5 3 7 4 5 1 8 3 1 4 6
julia> K = A ⊗ B20×28 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Int64,2}}: 2.88151 4.32227 7.20378 … 0.0865976 0.0865976 0.0865976 11.526 10.0853 8.64453 0.288659 0.202061 0.259793 12.9668 7.20378 4.32227 0.144329 0.0865976 0.0577317 1.44076 7.20378 2.88151 0.0865976 0.202061 0.115463 7.20378 1.44076 11.526 0.0288659 0.115463 0.173195 -0.689576 -1.03436 -1.72394 … -1.01063 -1.01063 -1.01063 -2.7583 -2.41352 -2.06873 -3.36877 -2.35814 -3.03189 -3.10309 -1.72394 -1.03436 -1.68439 -1.01063 -0.673754 -0.344788 -1.72394 -0.689576 -1.01063 -2.35814 -1.34751 -1.72394 -0.344788 -2.7583 -0.336877 -1.34751 -2.02126 -0.842314 -1.26347 -2.10579 … 0.143188 0.143188 0.143188 -3.36926 -2.9481 -2.52694 0.477292 0.334104 0.429563 -3.79042 -2.10579 -1.26347 0.238646 0.143188 0.0954584 -0.421157 -2.10579 -0.842314 0.143188 0.334104 0.190917 -2.10579 -0.421157 -3.36926 0.0477292 0.190917 0.286375 2.15728 3.23592 5.3932 … 0.18082 0.18082 0.18082 8.62912 7.55048 6.47184 0.602734 0.421914 0.542461 9.70777 5.3932 3.23592 0.301367 0.18082 0.120547 1.07864 5.3932 2.15728 0.18082 0.421914 0.241094 5.3932 1.07864 8.62912 0.0602734 0.241094 0.361641
julia> K[4, 5]4.322266767880391
julia> eltype(K) # promotionFloat64
julia> collect(K)20×28 Array{Float64,2}: 2.88151 4.32227 7.20378 … 0.0865976 0.0865976 0.0865976 11.526 10.0853 8.64453 0.288659 0.202061 0.259793 12.9668 7.20378 4.32227 0.144329 0.0865976 0.0577317 1.44076 7.20378 2.88151 0.0865976 0.202061 0.115463 7.20378 1.44076 11.526 0.0288659 0.115463 0.173195 -0.689576 -1.03436 -1.72394 … -1.01063 -1.01063 -1.01063 -2.7583 -2.41352 -2.06873 -3.36877 -2.35814 -3.03189 -3.10309 -1.72394 -1.03436 -1.68439 -1.01063 -0.673754 -0.344788 -1.72394 -0.689576 -1.01063 -2.35814 -1.34751 -1.72394 -0.344788 -2.7583 -0.336877 -1.34751 -2.02126 -0.842314 -1.26347 -2.10579 … 0.143188 0.143188 0.143188 -3.36926 -2.9481 -2.52694 0.477292 0.334104 0.429563 -3.79042 -2.10579 -1.26347 0.238646 0.143188 0.0954584 -0.421157 -2.10579 -0.842314 0.143188 0.334104 0.190917 -2.10579 -0.421157 -3.36926 0.0477292 0.190917 0.286375 2.15728 3.23592 5.3932 … 0.18082 0.18082 0.18082 8.62912 7.55048 6.47184 0.602734 0.421914 0.542461 9.70777 5.3932 3.23592 0.301367 0.18082 0.120547 1.07864 5.3932 2.15728 0.18082 0.421914 0.241094 5.3932 1.07864 8.62912 0.0602734 0.241094 0.361641

Constructing Kronecker products

Kronecker.kroneckerFunction
kronecker(A::AbstractMatrix, B::AbstractMatrix)

Construct a Kronecker product object between two arrays. Does not evaluate the Kronecker product explictly.

source
kronecker(A::AbstractMatrix, B::AbstractMatrix)

Higher-order Kronecker lazy kronecker product, e.g.

kronecker(A, B, C, D)
source
kronecker(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Kronecker.:⊗Function
⊗(A::AbstractMatrix, B::AbstractMatrix)

Binary operator for kronecker, computes as Lazy Kronecker product. See kronecker for documentation.

source
⊗(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Base.collectMethod
collect(K::GeneralizedKroneckerProduct)

Collects a lazy instance of the GeneralizedKroneckerProduct type into a dense, native matrix. Falls back to the element-wise case when not specialized method is defined.

source

Basic properties of Kronecker products

Base.getindexFunction
getindex(K::AbstractKroneckerProduct, i1::Integer, i2::Integer)

Computes and returns the (i,j)-th element of an AbstractKroneckerProduct K. Uses recursion if K is of an order greater than two.

source
Missing docstring.

Missing docstring for eltype. Check Documenter's build log for details.

Base.sizeMethod
size(K::AbstractKroneckerProduct)

Returns a the size of an AbstractKroneckerProduct instance.

source
Base.collectFunction
collect(K::GeneralizedKroneckerProduct)

Collects a lazy instance of the GeneralizedKroneckerProduct type into a dense, native matrix. Falls back to the element-wise case when not specialized method is defined.

source
collect(K::AbstractKroneckerSum)

Collects a lazy instance of the AbstractKroneckerSum type into a full, native matrix. Returns the result as a sparse matrix.

source
collect(E::Eigen{<:Number, <:Number, <:AbstractKroneckerProduct})

Collects eigenvalue decomposition of a AbstractKroneckerProduct type into a matrix.

source
Kronecker.collect!Function
collect!(C::AbstractMatrix, K::GeneralizedKroneckerProduct)

In-place collection of K in C. If possible, specialized routines are used to speed up the computation. The fallback is an element-wise iteration. In this case, this function might be slow.

source
collect!(C::AbstractMatrix, K::AbstractKroneckerProduct)

In-place collection of K in C where K is an AbstractKroneckerProduct, i.e., K = A ⊗ B. This is equivalent to the broadcasted assignment C .= K.

collect!(f, C::AbstractMatrix, K1::AbstractKroneckerProduct, Ks::AbstractKroneckerProduct...)

Evaluate f.(K1, Ks...) and assign it in-place to C. This is equivalent to the broadcasted operation C .= f.(K1, Ks...).

source
collect!(C::AbstractMatrix, K::AbstractKroneckerSum)

In-place collection of K in C where K is an AbstractKroneckerSum, i.e., K = A ⊗ B.

source
Kronecker.orderFunction
order(M::AbstractMatrix)

Returns the order of a matrix, i.e. how many matrices are involved in the Kronecker product (default to 1 for general matrices).

source
Kronecker.getmatricesFunction
getmatrices(K::AbstractKroneckerProduct)

Obtain the two matrices of an AbstractKroneckerProduct object.

source
getmatrices(A::AbstractArray)

Returns a matrix itself. Needed for recursion.

source
getmatrices(K::T) where T <: AbstractKroneckerSum

Obtain the two matrices of an AbstractKroneckerSum object.

source
Kronecker.issquareFunction
issquare(A::AbstractMatrix)

Checks if an array is a square matrix.

source
issquare(A::Factorization)

Checks if a Factorization struct represents a square matrix.

source
Missing docstring.

Missing docstring for sum. Check Documenter's build log for details.

Linear algebra

Many functions of the LinearAlgebra module are overloaded to work with subtypes of GeneralizedKroneckerProduct.

LinearAlgebra.logdetMethod
logdet(K::AbstractKroneckerProduct)

Compute the logarithm of the determinant of a Kronecker product.

source
Base.invMethod
inv(K::AbstractKroneckerProduct)

Compute the inverse of a Kronecker product.

source
Base.adjointMethod
adjoint(K::AbstractKroneckerProduct)

Compute the adjoint of a Kronecker product.

source
Base.transposeMethod
transpose(K::AbstractKroneckerProduct)

Compute the transpose of a Kronecker product.

source
Missing docstring.

Missing docstring for conj(K::AbstractKroneckerProduct). Check Documenter's build log for details.