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}: 0.284044 -0.278227 -1.58175 -2.68135 0.268104 0.627129 -2.36381 -0.64596 -0.759459 -0.103594 1.29329 0.257264 -0.397535 -3.69769 -0.335861 1.40882
julia> B = rand(1:10, 5, 7)5×7 Array{Int64,2}: 1 10 5 2 1 2 2 10 4 3 4 1 2 9 6 5 7 7 5 7 10 10 3 9 9 10 10 5 2 10 10 1 10 4 5
julia> K = A ⊗ B20×28 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Int64,2}}: 0.284044 2.84044 1.42022 … -2.68135 -5.3627 -5.3627 2.84044 1.13618 0.852132 -2.68135 -5.3627 -24.1321 1.70426 1.42022 1.98831 -13.4067 -18.7694 -26.8135 2.84044 0.852132 2.5564 -26.8135 -26.8135 -13.4067 0.568088 2.84044 2.84044 -26.8135 -10.7254 -13.4067 0.268104 2.68104 1.34052 … -0.64596 -1.29192 -1.29192 2.68104 1.07241 0.804311 -0.64596 -1.29192 -5.81364 1.60862 1.34052 1.87673 -3.2298 -4.52172 -6.4596 2.68104 0.804311 2.41293 -6.4596 -6.4596 -3.2298 0.536207 2.68104 2.68104 -6.4596 -2.58384 -3.2298 -0.759459 -7.59459 -3.79729 … 0.257264 0.514528 0.514528 -7.59459 -3.03783 -2.27838 0.257264 0.514528 2.31537 -4.55675 -3.79729 -5.31621 1.28632 1.80085 2.57264 -7.59459 -2.27838 -6.83513 2.57264 2.57264 1.28632 -1.51892 -7.59459 -7.59459 2.57264 1.02906 1.28632 -0.397535 -3.97535 -1.98768 … 1.40882 2.81765 2.81765 -3.97535 -1.59014 -1.19261 1.40882 2.81765 12.6794 -2.38521 -1.98768 -2.78275 7.04412 9.86177 14.0882 -3.97535 -1.19261 -3.57782 14.0882 14.0882 7.04412 -0.79507 -3.97535 -3.97535 14.0882 5.63529 7.04412
julia> K[4, 5]2.8404404058081347
julia> eltype(K) # promotionFloat64
julia> collect(K)20×28 Array{Float64,2}: 0.284044 2.84044 1.42022 … -2.68135 -5.3627 -5.3627 2.84044 1.13618 0.852132 -2.68135 -5.3627 -24.1321 1.70426 1.42022 1.98831 -13.4067 -18.7694 -26.8135 2.84044 0.852132 2.5564 -26.8135 -26.8135 -13.4067 0.568088 2.84044 2.84044 -26.8135 -10.7254 -13.4067 0.268104 2.68104 1.34052 … -0.64596 -1.29192 -1.29192 2.68104 1.07241 0.804311 -0.64596 -1.29192 -5.81364 1.60862 1.34052 1.87673 -3.2298 -4.52172 -6.4596 2.68104 0.804311 2.41293 -6.4596 -6.4596 -3.2298 0.536207 2.68104 2.68104 -6.4596 -2.58384 -3.2298 -0.759459 -7.59459 -3.79729 … 0.257264 0.514528 0.514528 -7.59459 -3.03783 -2.27838 0.257264 0.514528 2.31537 -4.55675 -3.79729 -5.31621 1.28632 1.80085 2.57264 -7.59459 -2.27838 -6.83513 2.57264 2.57264 1.28632 -1.51892 -7.59459 -7.59459 2.57264 1.02906 1.28632 -0.397535 -3.97535 -1.98768 … 1.40882 2.81765 2.81765 -3.97535 -1.59014 -1.19261 1.40882 2.81765 12.6794 -2.38521 -1.98768 -2.78275 7.04412 9.86177 14.0882 -3.97535 -1.19261 -3.57782 14.0882 14.0882 7.04412 -0.79507 -3.97535 -3.97535 14.0882 5.63529 7.04412

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.