What does the rcond function do in MATLAB / RunMat?
rc = rcond(A) returns an estimate of the reciprocal of the condition number of a square matrix A
in the 1-norm. Well-conditioned matrices yield values close to 1, whereas singular or numerically
singular matrices yield values near zero. The estimate mirrors MATLAB: it is based on the ratio of
the smallest to largest singular values.
How does the rcond function behave in MATLAB / RunMat?
- Inputs must be square matrices (scalars count as
1 × 1). Non-square inputs trigger the MATLAB error"rcond: input must be a square matrix." - For the empty matrix (
0 × 0) the reciprocal condition number isInf. rcond(0)returns0. Non-zero scalars return1.- Logical and integer arrays are promoted to double precision before analysis.
- Complex matrices are supported; the singular values are computed in complex arithmetic.
- The implementation runs an SVD and computes
min(s) / max(s), honouring MATLAB's tolerance logic.
rcond function GPU execution behaviour
When the input resides on a GPU, RunMat first invokes the active provider's rcond hook that this
builtin registers. When that hook is unavailable the runtime attempts to reuse the provider's
linsolve factorisations to recover the reciprocal condition number. If neither path is implemented
the matrix is gathered to the host, the shared SVD-based estimator is executed, and the scalar
result is uploaded back to the device so subsequent GPU work keeps residency.
Examples of using the rcond function in MATLAB / RunMat
Reciprocal condition of the identity matrix
A = eye(3);
rc = rcond(A);
Expected output:
rc = 1
Detecting a nearly singular matrix
A = diag([1, 1e-8]);
rc = rcond(A);
Expected output:
rc = 1e-8
Reciprocal condition of a singular matrix
A = [1 2; 2 4];
rc = rcond(A);
Expected output:
rc = 0
Reciprocal condition for a complex matrix
A = [1+2i 0; 3i 2-1i];
rc = rcond(A);
Expected output (values rounded):
rc = 0.1887
Handling the empty matrix
rc = rcond([]);
Expected output:
rc = Inf
Estimating conditioning on GPU data
G = gpuArray([2 0; 0 0.5]);
rc_gpu = rcond(G);
rc = gather(rc_gpu);
Expected output:
rc = 0.25
GPU residency in RunMat (Do I need gpuArray?)
Manually calling gpuArray is rarely necessary. When matrices already live on the device, RunMat
invokes the provider hook if one exists, or automatically gathers, evaluates, and re-uploads the
scalar result. This preserves MATLAB compatibility while keeping the runtime efficient and ergonomic.
FAQ
What range of values should I expect from rcond?
rcond returns a value in [0, 1]. Values near 1 indicate a well-conditioned matrix. Values near
0 indicate singular or ill-conditioned matrices.
Why does rcond return Inf for the empty matrix?
The empty matrix is perfectly conditioned by convention, so the reciprocal condition number is Inf
(1 / 0).
Does rcond warn me about singular systems automatically?
rcond itself does not issue warnings. Use the value to decide whether the matrix is singular to
working precision, similar to MATLAB workflows (if rcond(A) < eps, ...).
Is the SVD tolerance the same as MATLAB?
Yes. The estimator matches MATLAB's definition by deriving the result from the singular values. The
same tolerance logic is shared with pinv and rank.
Will calling rcond move my data off the GPU?
Only if the active provider lacks a dedicated implementation. In that case RunMat transparently downloads the matrix, computes the estimate on the host, and re-uploads the scalar.
See also
inv, pinv, rank, det, linsolve, gpuArray, gather
Source & feedback
- The implementation lives at
crates/runmat-runtime/src/builtins/math/linalg/solve/rcond.rs. - Found a behavioural difference? Open an issue with a minimal reproduction.