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
    • chol
    • decomposition
    • eig
    • eigs
    • lu
    • qr
    • svd

qr — Compute QR factorizations in MATLAB and RunMat.

qr(A) computes orthogonal/unitary-upper-triangular factorizations of matrix A. Full, economy, and pivoted output forms follow MATLAB semantics.

Syntax

R = qr(A)
R = qr(A, option)
R = qr(A, option1, option2)
[Q, R] = qr(A)
[Q, R] = qr(A, option)
[Q, R] = qr(A, option1, option2)
All supported qr forms
R = qr(A)
R = qr(A, option)
R = qr(A, option1, option2)
[Q, R] = qr(A)
[Q, R] = qr(A, option)
[Q, R] = qr(A, option1, option2)
[Q, R, P] = qr(A)
[Q, R, P] = qr(A, option)
[Q, R, P] = qr(A, option1, option2)

Inputs

NameTypeRequiredDefaultDescription
ANumericArrayYes—Input matrix to factorize.
optionStringScalarYes—Option token (`0`, `econ`, `matrix`, or `vector`).
option1StringScalarYes—First option token (`0`, `econ`, `matrix`, or `vector`).
option2StringScalarYes—Second option token (`0`, `econ`, `matrix`, or `vector`).

Returns

NameTypeDescription
RNumericArrayUpper triangular (or trapezoidal) factor.
QNumericArrayOrthogonal/unitary factor.
PNumericArrayPermutation matrix or vector based on pivot mode.

Returned values from qr depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:qr:InvalidArgumentOptions are invalid or output count exceeds supported forms.qr currently supports at most three outputs
RunMat:qr:InvalidInputInput is non-numeric or has rank greater than two.qr: expected a numeric 2-D input matrix
RunMat:qr:InternalQR runtime fails to materialize output values.qr: internal runtime failure

How qr works

  • Single output: R = qr(A) returns the upper-triangular (or upper-trapezoidal) factor. Column pivoting is applied implicitly for numerical stability.
  • Two outputs: [Q, R] = qr(A) yields the orthonormal/unitary factor Q and the upper-triangular R such that Q * R = A * E, where E is the column permutation matrix selected during factorization. When you omit E, the columns of R already appear in that permuted order.
  • Three outputs: [Q, R, E] = qr(A) additionally returns the column permutation so that A * E = Q * R. Use the 'vector' option to receive a pivot vector instead of a permutation matrix.
  • Economy size: qr(A, 0) or qr(A, 'econ') returns the reduced-size factors: when m ≥ n, Q is m × n and R is n × n; for wide matrices (m < n) the economy form equals the full form. The legacy numeric-zero syntax selects vector permutation output when a third output is requested.
  • Public MATLAB matrix classes are single and double. RunMat mode separately admits logical matrices and every real integer class through named extensions; integer matrix values cross only after exact binary64 representability checks. Scalars and vectors are treated as 1-D or 2-D dense arrays.
  • Typed-integer and logical zero economy selectors are separately gated RunMat extensions. An explicit resident option is independently gated and read through its exact owner; nonzero or nonscalar numeric options reject.
  • Integer inputs never enter a floating provider QR kernel. Resident integer input gathers through its exact owner and restores the double Q, R, and permutation outputs to that owner when supported.

Does RunMat run qr on the GPU?

When the active acceleration provider exposes the dedicated QR hook (the bundled WGPU backend does), RunMat stages the input through the provider, performs the factorisation via the runtime implementation, and re-uploads all outputs so they remain resident as gpuTensor handles.

If no provider hook is present, RunMat gathers the input to the host, performs the CPU factorisation, and leaves the outputs on the host until an explicit gpuArray request.

Examples

Computing the full QR factorization of a square matrix

A = [12 -51 4; 6 167 -68; -4 24 -41];
[Q, R] = qr(A)

Obtaining orthonormal Q and upper-triangular R for a tall matrix

A = [1 2; 3 4; 5 6];
[Q, R] = qr(A)

Working with column pivoting when requesting three outputs

A = [1 1 0; 1 0 1; 0 1 1];
[Q, R, E] = qr(A)

Using economy-size QR to reduce memory footprint

A = randn(1000, 20);
[Q, R] = qr(A, 0)

Receiving the permutation vector instead of a matrix

A = magic(4);
[Q, R, p] = qr(A, 'vector')

Running QR on a gpuArray input (with automatic fallback)

G = gpuArray(rand(256, 64));
[Q, R] = qr(G, 'econ');
class(Q)

Using qr with coding agents

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

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

FAQ

Does qr(A) always perform column pivoting?⌄

Yes. MATLAB switched to pivoted QR for the single-output form many releases ago; RunMat mirrors that behaviour for improved numerical stability.

How do I request the reduced (economy) factors?⌄

Pass 0, '0', or 'econ' as the second argument. For example, [Q,R] = qr(A,0) or [Q,R] = qr(A,'econ').

How can I obtain the permutation vector instead of a matrix?⌄

Add the option 'vector', e.g., [Q,R,p] = qr(A,'vector'). When you also request economy size, use [Q,R,p] = qr(A,'econ','vector').

Are complex matrices supported?⌄

Yes. Inputs of type complex double produce complex orthonormal factors using complex Householder reflectors.

What precision do the returned factors use?⌄

The builtin always produces double-precision (or complex double) outputs, matching MATLAB’s dense QR behaviour.

Can I call qr on logical arrays?⌄

Yes. Logical inputs are converted to double precision before factorisation.

What happens if I pass more than two option arguments?⌄

The builtin raises a MATLAB-compatible error (qr: too many option arguments). Only one size option and one permutation option are accepted.

Do gpuArray outputs stay on the device?⌄

Yes when an acceleration provider exposes the QR hook; the bundled WGPU backend does so by staging through the host implementation and re-uploading the factors. Otherwise RunMat gathers the data to the host, factors it there, and uploads the results back automatically.

How can I verify the factorisation?⌄

Check that Q'*Q is (approximately) the identity matrix and that Q*R equals A*E. For vector permutations, A(:,p) reproduces the pivoted columns.

Related Linalg functions

Factor

chol · decomposition · eig · eigs · lu · svd

Structure

bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Ops

cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Open-source implementation

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

  • View the source for qr 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 qr works
  • Does RunMat run qr on the GPU?
  • Examples
  • Computing the full QR factorization of a square matrix
  • Obtaining orthonormal Q and upper-triangular R for a tall matrix
  • Working with column pivoting when requesting three outputs
  • Using economy-size QR to reduce memory footprint
  • Receiving the permutation vector instead of a matrix
  • Running QR on a gpuArray input (with automatic fallback)
  • Using qr with coding agents
  • FAQ
  • Related Linalg functions
  • Factor
  • Structure
  • Solve
  • Ops
  • Open-source implementation
  • About RunMat