Skip to content

A general-purpose toolbox for efficient Kronecker-based algebra.

License

Notifications You must be signed in to change notification settings

MichielStock/Kronecker.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4518212 ยท Nov 29, 2023
Sep 10, 2022
Oct 14, 2020
Nov 23, 2022
Nov 12, 2019
Sep 11, 2019
Oct 24, 2023
Nov 14, 2023
Sep 18, 2019
Dec 4, 2018
Nov 29, 2023
Jan 11, 2021
Jul 28, 2019
Jul 4, 2019

Repository files navigation

Kronecker.jl

This is a Julia package to efficiently work with Kronecker products. It combines lazy evaluation and algebraic tricks such that it can implicitely work with huge matrices. It allows to work with large Kronecker systems both much faster and using much less memory than the naive implementation of the Kronecker product.

Features

Given two matrices (subtype of AbstractArray) A and B, one can construct an instance of the KroneckerProduct type as K = A โŠ— B (typed using \otimes TAB). Equivalently, the function kronecker function can be used as well. Several functions are implemented.

  • collect(K) computes the Kronecker product (not recommended!)
  • tr, det, size, eltype, inv, ... are efficient functions to work with Kronecker products. Either the result is a numeric value or a new KroneckerProduct type is returned
  • Multiplying with a vector v is efficient using the vec trick: K * v
  • Solving systems of the form A โŠ— B + cI
  • Working with incomplete systems using the sampled vec trick
  • Basic compatibility with higher-order Kronecker systems, e.g. A โŠ— B โŠ— C or kronecker(A, 4) which is equivalent with A โŠ— A โŠ— A โŠ— A
  • A KroneckerSum can be constructed with A โŠ• B (typed using \oplus TAB) or kroneckersum(A,B)
    • Multiplication with vectors uses a specialized version of the vec trick
    • Higher-order sums are supported, e.g. A โŠ• B โŠ• C or kroneckersum(A,4)
  • [in progress] GPU compatibility!
  • [in progress] Autodiff for machine learning models!

Read the documentation to get the specifics.

Benchmarks

Below is a comparision between the native kron function and Kronecker.jl for several operations.

Example

using Kronecker

A = randn(100, 100);
B = rand(50, 50);

v = rand(5000);

K = A โŠ— B

collect(K)  # equivalent with kron(A, B)

K[78, 43]

tr(K)
inv(K)  # yields another lazy Kronecker instance

K * v  # equivalent with vec(B * reshape(v, 50, 100) * A')

See the notebook for some more advanced use.

Installation

Directly available via the Julia package manager:

] add Kronecker

Issues

This is very much a work in progress! Please start an issue for bugs or requests to improve functionality. Any feedback is appreciated!

Status master branch

stable docsdev docsbuild status coverage DOIJULIACON

About

A general-purpose toolbox for efficient Kronecker-based algebra.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages