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.57575   -0.501709  -3.21159    1.47518
 -0.226798   1.29403   -0.864597  -0.645007
  1.11364    0.142855  -0.345008   2.77911
  1.63773    1.08353   -0.140607   1.93866

julia> B = rand(1:10, 5, 7)
5×7 Array{Int64,2}:
 2  3  10   7   6  10   2
 2  9   3  10  10  10   7
 7  3   5   8   5   4  10
 4  6   7   2  10   2  10
 8  9   5   8   3   8   6

julia> K = A ⊗ B
20×28 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Int64,2}}:
  3.15151    4.72726   15.7575    11.0303    …   8.8511   14.7518    2.95037
  3.15151   14.1818     4.72726   15.7575       14.7518   14.7518   10.3263
 11.0303     4.72726    7.87876   12.606         7.37592   5.90074  14.7518
  6.30301    9.45452   11.0303     3.15151      14.7518    2.95037  14.7518
 12.606     14.1818     7.87876   12.606         4.42555  11.8015    8.8511
 -0.453596  -0.680395  -2.26798   -1.58759   …  -3.87004  -6.45007  -1.29001
 -0.453596  -2.04118   -0.680395  -2.26798      -6.45007  -6.45007  -4.51505
 -1.58759   -0.680395  -1.13399   -1.81439      -3.22504  -2.58003  -6.45007
 -0.907193  -1.36079   -1.58759   -0.453596     -6.45007  -1.29001  -6.45007
 -1.81439   -2.04118   -1.13399   -1.81439      -1.93502  -5.16006  -3.87004
  2.22728    3.34092   11.1364     7.79548   …  16.6747   27.7911    5.55822
  2.22728   10.0228     3.34092   11.1364       27.7911   27.7911   19.4538
  7.79548    3.34092    5.5682     8.90912      13.8956   11.1164   27.7911
  4.45456    6.68184    7.79548    2.22728      27.7911    5.55822  27.7911
  8.90912   10.0228     5.5682     8.90912       8.33733  22.2329   16.6747
  3.27546    4.91319   16.3773    11.4641    …  11.632    19.3866    3.87732
  3.27546   14.7396     4.91319   16.3773       19.3866   19.3866   13.5706
 11.4641     4.91319    8.18866   13.1018        9.6933    7.75464  19.3866
  6.55092    9.82639   11.4641     3.27546      19.3866    3.87732  19.3866
 13.1018    14.7396     8.18866   13.1018        5.81598  15.5093   11.632

julia> K[4, 5]
15.7575287024678

julia> eltype(K)  # promotion
Float64

julia> collect(K)
20×28 Array{Float64,2}:
  3.15151    4.72726   15.7575    11.0303    …   8.8511   14.7518    2.95037
  3.15151   14.1818     4.72726   15.7575       14.7518   14.7518   10.3263
 11.0303     4.72726    7.87876   12.606         7.37592   5.90074  14.7518
  6.30301    9.45452   11.0303     3.15151      14.7518    2.95037  14.7518
 12.606     14.1818     7.87876   12.606         4.42555  11.8015    8.8511
 -0.453596  -0.680395  -2.26798   -1.58759   …  -3.87004  -6.45007  -1.29001
 -0.453596  -2.04118   -0.680395  -2.26798      -6.45007  -6.45007  -4.51505
 -1.58759   -0.680395  -1.13399   -1.81439      -3.22504  -2.58003  -6.45007
 -0.907193  -1.36079   -1.58759   -0.453596     -6.45007  -1.29001  -6.45007
 -1.81439   -2.04118   -1.13399   -1.81439      -1.93502  -5.16006  -3.87004
  2.22728    3.34092   11.1364     7.79548   …  16.6747   27.7911    5.55822
  2.22728   10.0228     3.34092   11.1364       27.7911   27.7911   19.4538
  7.79548    3.34092    5.5682     8.90912      13.8956   11.1164   27.7911
  4.45456    6.68184    7.79548    2.22728      27.7911    5.55822  27.7911
  8.90912   10.0228     5.5682     8.90912       8.33733  22.2329   16.6747
  3.27546    4.91319   16.3773    11.4641    …  11.632    19.3866    3.87732
  3.27546   14.7396     4.91319   16.3773       19.3866   19.3866   13.5706
 11.4641     4.91319    8.18866   13.1018        9.6933    7.75464  19.3866
  6.55092    9.82639   11.4641     3.27546      19.3866    3.87732  19.3866
 13.1018    14.7396     8.18866   13.1018        5.81598  15.5093   11.632

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
function 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.

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.