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

svd — Compute singular value decompositions with full, economy, and singular-value-only output forms.

svd(A) factors real or complex matrices into U * S * V', where S contains non-negative singular values in descending order. It supports MATLAB-compatible full, economy, and value-only call forms.

Syntax

S = svd(A)
S = svd(A, option)
S = svd(A, option1, option2)
[U, S] = svd(A)
[U, S] = svd(A, option)
[U, S] = svd(A, option1, option2)
All supported svd forms
S = svd(A)
S = svd(A, option)
S = svd(A, option1, option2)
[U, S] = svd(A)
[U, S] = svd(A, option)
[U, S] = svd(A, option1, option2)
[U, S, V] = svd(A)
[U, S, V] = svd(A, option)
[U, S, V] = svd(A, option1, option2)

Inputs

NameTypeRequiredDefaultDescription
ANumericArrayYes—Input matrix to decompose.
optionAnyYes—Option token (`0`, `econ`, `full`, `vector`, or `matrix`).
option1AnyYes—First option token (`0`, `econ`, `full`, `vector`, or `matrix`).
option2AnyYes—Second option token (`0`, `econ`, `full`, `vector`, or `matrix`).

Returns

NameTypeDescription
SNumericArraySingular values (vector by default).
UNumericArrayLeft singular vectors.
SNumericArrayDiagonal singular-value matrix or vector based on options.
VNumericArrayRight singular vectors.

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

Errors

IdentifierWhenMessage
RunMat:svd:InvalidArgumentOption arguments or requested output count are invalid.svd currently supports at most three outputs
RunMat:svd:InvalidInputInput is unsupported or not a 2-D numeric/logical matrix.svd: expected numeric or logical values
RunMat:svd:InternalRuntime cannot materialize SVD outputs.svd: internal runtime failure

How svd works

  • Single output s = svd(A) returns the singular values as a column vector sorted in descending order.
  • Three outputs [U,S,V] = svd(A) return the full-sized factors with U square m×m, S shaped m×n, and V square n×n (m = size(A,1), n = size(A,2)).
  • Economy form [U,S,V] = svd(A,'econ') (or svd(A,0)) reduces the shapes to the rank-defining dimension so that U and V drop the redundant orthogonal columns.
  • Vector form [U,s,V] = svd(A,'vector') supplies the singular values as a vector instead of a diagonal matrix. You can combine 'vector' with 'econ'.
  • The documented matrix classes are single and double. With RunMat extensions enabled, real logical and native integer matrices are also accepted; integer values must be exactly representable as double or the call rejects before factorisation.
  • Typed-integer zero can select economy size only when RunMat extensions are enabled. The selector is parsed structurally without a floating conversion.
  • Complex inputs yield unitary U and V (conjugate-transpose preserves orthogonality) with real, non-negative singular values.
  • Empty matrices, row/column vectors, and scalars are all supported and follow MATLAB’s shape conventions.

Does RunMat run svd on the GPU?

RunMat reserves a dedicated svd provider hook; once a backend implements it, the factors can stay on the device as gpuTensor handles without round-tripping through host memory.

Today no provider ships that hook, so gpuArray inputs are gathered to the host, the CPU SVD executes, and the factors are returned as host tensors. You can re-establish residency with gpuArray(s) if you need to continue on the GPU.

Because SVD is a residency sink, the fusion planner treats it as a barrier—preceding GPU tensors are gathered and subsequent ops run on the host unless you manually promote them again.

Examples

Getting the singular values of a matrix

A = [1 2 3; 4 5 6; 7 8 9];
s = svd(A)

Full SVD and reconstruction of a square matrix

A = [3 1; 0 2];
[U,S,V] = svd(A);
A_recon = U * S * V'

Economy-size SVD for a tall matrix

A = randn(6, 3);
[U,S,V] = svd(A, 'econ');
size(U) %  6 x 3
size(S) %  3 x 3
size(V) %  3 x 3

Economy-size SVD for a wide matrix

A = randn(3, 6);
[U,S,V] = svd(A, 'econ');
size(U) %  3 x 3
size(S) %  3 x 6
size(V) %  6 x 6

Requesting vector form of the singular values

A = [10 0; 0 1];
[U,s,V] = svd(A, 'vector')

Computing the SVD of a complex matrix

A = [1+2i, 2-1i; 0, 3i];
[U,S,V] = svd(A)

Running svd on a gpuArray (automatic host fallback today)

G = gpuArray(randn(128, 64));
s = svd(G);           % Values are gathered to host transparently

Using svd with coding agents

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

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

FAQ

How are the singular values ordered?⌄

They are returned in non-increasing order. MATLAB’s sign conventions are followed: values are non-negative and appear on the diagonal of S (or inside the vector form).

What is the difference between full and economy forms?⌄

Full SVD returns square U and V (m×m and n×n). Economy SVD trims them to m×min(m,n) and n×min(m,n). The S factor keeps the same column dimension as the input; it is min(m,n)×min(m,n) when m ≥ n and min(m,n)×n when m < n. Use economy when you do not need the redundant orthogonal columns.

What does the "vector" option change?⌄

It affects the second output. With "vector", S is returned as a column vector of singular values, matching svd(A) in the single-output form. Without it, S is a diagonal matrix.

Can I mix 'econ' and 'vector'?⌄

Yes. Any order of the options is accepted (svd(A,'vector','econ') and svd(A,'econ','vector') both work), and the returned dimensions mirror MATLAB’s behaviour.

What happens with scalars or empty matrices?⌄

svd of a scalar returns its absolute value. Empty matrices return empty factors with consistent dimensions so that downstream code can continue to operate without special cases.

Does RunMat require BLAS/LAPACK for svd?⌄

No. The builtin is always available. When BLAS/LAPACK is enabled, the host implementation leverages those libraries through nalgebra for performance; otherwise a pure-Rust algorithm is used under the hood.

Will the results stay on the GPU?⌄

Not yet. Presently the builtin gathers GPU operands to the host, runs the CPU factorisation, and returns host tensors. The GPU spec already reserves a hook so providers can keep everything device-resident once GPU kernels land.

Can svd accept an integer matrix?⌄

The compatibility surface documents single and double matrices. With RunMat extensions enabled, all eight real integer classes are accepted when every value is exactly representable as double. Wider values that would round at the binary64 boundary are rejected before factorisation; strict compatibility mode rejects typed-integer matrices.

Related Linalg functions

Factor

chol · decomposition · eig · eigs · lu · qr

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 svd is executed, line by line, in Rust.

  • View the source for svd 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 svd works
  • Does RunMat run svd on the GPU?
  • Examples
  • Getting the singular values of a matrix
  • Full SVD and reconstruction of a square matrix
  • Economy-size SVD for a tall matrix
  • Economy-size SVD for a wide matrix
  • Requesting vector form of the singular values
  • Computing the SVD of a complex matrix
  • Running svd on a gpuArray (automatic host fallback today)
  • Using svd with coding agents
  • FAQ
  • Related Linalg functions
  • Factor
  • Structure
  • Solve
  • Ops
  • Open-source implementation
  • About RunMat