RunMat
GitHub

rref — Compute reduced row echelon form and pivot columns.

rref(A) returns the reduced row echelon form of a real or complex numeric matrix. [R, pivots] = rref(A) also returns the one-based pivot column indices. An optional tolerance controls which entries are considered zero during pivot selection.

Syntax

R = rref(A)
R = rref(A, tol)
[R, pivots] = rref(A)
[R, pivots] = rref(A, tol)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput matrix.
tolNumericScalarNoPivot tolerance.

Returns

NameTypeDescription
RNumericArrayReduced row echelon form of A.
pivotsNumericArrayOne-based pivot column indices.

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

Errors

IdentifierWhenMessage
RunMat:rref:InvalidArgumentOptional tolerance argument is malformed or outside accepted bounds.rref: invalid argument
RunMat:rref:InvalidInputInput shape/type cannot be processed for row reduction.rref: invalid input
RunMat:rref:TooManyOutputsMore than two output arguments are requested.rref: too many output arguments
RunMat:rref:InternalRuntime fails while computing row reduction or executing gather/upload paths.rref: internal runtime failure

How rref works

  • Inputs must behave like 2-D matrices. Trailing singleton dimensions are accepted; other higher-rank inputs raise RunMat:rref:InvalidInput.
  • The default tolerance is max(size(A)) * eps(norm(A, inf)), matching MATLAB row-reduction conventions.
  • rref(A, tol) uses a caller-provided finite, non-negative scalar pivot tolerance.
  • Logical and integer inputs are promoted to double precision before row reduction.
  • Complex inputs use complex Gauss-Jordan elimination with pivot selection by complex magnitude.
  • The second output is a row vector of one-based pivot column indices.
  • Non-finite values are accepted. The default tolerance still follows max(size(A)) * eps(norm(A, inf)); Inf and NaN therefore follow the runtime's IEEE floating-point tolerance and pivot arithmetic.

Does RunMat run rref on the GPU?

rref is an eager solve-style operation. It terminates fusion plans, gathers GPU-resident inputs for numerical row reduction, and returns ordinary MATLAB-compatible values.

GPU memory and residency

When the input is a real gpuArray, RunMat gathers it, computes the row-reduced matrix on the host, and re-uploads the reduced matrix if a provider is available. If that re-upload fails, the builtin raises RunMat:rref:Internal rather than silently changing residency. Pivot-column metadata is returned as a host vector.

Examples

Finding dependent columns

A = [1 2 3; 2 4 6; 1 1 1];
[R, pivots] = rref(A)

Expected output:

R = [1 0 -1; 0 1 2; 0 0 0]
pivots = [1 2]

Using a custom tolerance

A = diag([1, 1e-12]);
R = rref(A, 1e-6)

Expected output:

R = [1 0; 0 0]

Row-reducing an augmented system

A = [2 -1 3; 4 -2 6; 1 0 1];
b = [5; 10; 2];
RAug = rref([A b])

Using rref with coding agents

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

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

FAQ

How does rref choose pivots?

RunMat scans columns left to right, picks the largest available pivot by magnitude below the current pivot row, normalizes the pivot row, and eliminates the pivot column above and below the pivot.

Is the pivot vector one-based?

Yes. The second output uses MATLAB's one-based column indices.

Does rref use the same tolerance as rank?

No. rank uses an SVD tolerance. rref uses the MATLAB row-reduction tolerance based on the matrix infinity norm.

Solve

cond · det · inv · linsolve · norm · pinv · rank · rcond

Factor

chol · eig · lu · qr · svd

Open-source implementation

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

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.