RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • blkdiag
    • cat
    • circshift
    • diag
    • flip
    • fliplr
    • flipud
    • horzcat
    • ipermute
    • kron
    • permute
    • repelem
    • repmat
    • reshape
    • rot90
    • squeeze
    • toeplitz
    • tril
    • triu
    • vertcat

kron — Compute Kronecker products in MATLAB and RunMat.

kron(A, B) forms the Kronecker (tensor) product of A and B. Output sizing and column-major block ordering follow MATLAB semantics.

Syntax

C = kron(A, B)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Left numeric/logical/complex input array.
BAnyYes—Right numeric/logical/complex input array.

Returns

NameTypeDescription
CAnyKronecker product of inputs A and B.

Errors

IdentifierWhenMessage
RunMat:kron:TooManyInputsExtra arguments were supplied after A and B.kron: too many input arguments
RunMat:kron:UnsupportedInputInput values are not numeric/logical/complex arrays.kron: unsupported input type
RunMat:kron:InternalInternal conversion/allocation/provider path fails.kron: internal operation failed

How kron works

  • Works with scalars, vectors, and matrices. Higher-rank tensor inputs are a RunMat extension and are rejected while strict compatibility mode disables extensions.
  • If either input is complex, the output is complex and uses MATLAB's complex arithmetic rules.
  • Logical and char inputs are promoted to double precision before multiplication.
  • All eight integer classes are supported. Integer operands must have the same class, or the other operand must be a scalar double; multiplication preserves the integer class and saturates on overflow. Complex integer arithmetic is rejected.
  • Scalar arguments act as uniform scalars (kron(a, B) behaves like a * B).
  • Empty dimensions propagate; if any replicated dimension is zero, the result is empty along that axis.
  • Invalid inputs (non-numeric/non-logical, or values that would overflow the maximum size) raise descriptive MATLAB-style errors.

Does RunMat run kron on the GPU?

For real floating-point operands, RunMat uses the exact owning provider's kron hook when the operands share a compatible device and precision; mixed host/resident floating inputs may upload the host operand temporarily and use the same path. Provider outputs are validated for shape, ownership, device, storage, precision, and non-aliasing. Typed-integer and otherwise unsupported cases gather automatically, compute with class-preserving host semantics, and restore the result to the source provider when possible. An explicit gpuArray source must remain resident or the call errors, while automatically resident values may return to host only when their class cannot be represented safely.

GPU memory and residency

You usually do not need to call gpuArray explicitly. RunMat's planner keeps values resident on the GPU whenever it is profitable. Explicit gpuArray calls remain supported for MATLAB compatibility and for users who want direct control over residency.

Examples

Computing the Kronecker product of two matrices

A = [1 2; 3 4];
B = [0 5; 6 7];
C = kron(A, B)

Expected output:

C =
     0     5     0    10
     6     7    12    14
     0    15     0    20
    18    21    24    28

Kronecker product with row and column vectors

row = [1 2 3];
col = (1:3)';
K = kron(row, col);
size(K)

Expected output:

ans =
     3     9

Scaling a matrix with a scalar using kron

A = [1 2; 3 4];
S = kron(2, A)

Expected output:

S =
     2     4
     6     8

Building block-diagonal systems with kron

I = eye(3);
M = [1 0; 0 -1];
blockDiag = kron(I, M)

Kronecker product of complex matrices

A = [1+2i 0; 0 3-1i];
B = [0 1; 2 3i];
C = kron(A, B)

Using kron with logical masks

mask = logical([1 0; 0 1]);
tile = kron(mask, ones(2))

Running kron on GPU-resident tensors

G = gpuArray(rand(2));
H = gpuArray([1 -1; -1 1]);
K = kron(G, H);
isgpuarray(K)

Expected output:

ans = logical 1

Using kron with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how kron changes the result.

Run a small kron example, explain the result, then change one input and compare the output.

FAQ

When should I use kron instead of standard matrix multiplication?⌄

Use kron when you need block matrices built from every combination of two operands. Matrix multiplication collapses dimensions, while kron expands them.

Does kron preserve sparsity?⌄

The current dense runtime converts inputs to dense double or complex tensors. Sparse fidelity is on the roadmap; today, sparse inputs are first densified.

Can I mix real and complex inputs?⌄

Yes. If either operand is complex, the output is complex, with MATLAB-compatible real/imaginary components.

What happens with logical or boolean inputs?⌄

Logical arrays are converted to doubles (0 and 1) before the Kronecker product, mirroring MATLAB's behaviour.

Are character arrays supported?⌄

Yes. Character arrays are converted to their Unicode code points (double precision) before forming the product.

How big can the result be?⌄

kron checks for overflow when multiplying dimension sizes. If the result would exceed the maximum addressable size, the builtin raises a descriptive error before allocating memory.

Does the GPU path always stay on-device?⌄

Supported real floating-point operands stay on-device when their exact owning provider supplies a valid kron result. Unsupported cases gather automatically, compute on the host, and restore the class-preserving result to the source provider. Explicit gpuArray inputs either produce a resident result or raise an error; the source handles are not consumed.

Related Array functions

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · permute · repelem · repmat · reshape · rot90 · squeeze · toeplitz · tril · triu · vertcat

Grouping

accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Creation

colon · createArray · empty · eye · false · full · inf · linspace · logspace · magic · meshgrid · nan · nchoosek · ndgrid · nonzeros · ones · peaks · perms · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · zeros

Indexing

find · ind2sub · sub2ind

Introspection

iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how kron is executed, line by line, in Rust.

  • View the source for kron in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How kron works
  • Does RunMat run kron on the GPU?
  • GPU memory and residency
  • Examples
  • Computing the Kronecker product of two matrices
  • Kronecker product with row and column vectors
  • Scaling a matrix with a scalar using kron
  • Building block-diagonal systems with kron
  • Kronecker product of complex matrices
  • Using kron with logical masks
  • Running kron on GPU-resident tensors
  • Using kron with coding agents
  • FAQ
  • Related Array functions
  • Shape
  • Grouping
  • Sorting Sets
  • Creation
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat