QSVD / QSVDS · MATLAB and Python
Quaternion singular value decomposition
A fast universal algorithm for quaternion singular value decomposition
Dong Zhang, Chuan Jiang, V. I. Vasil’ev, and Tongsong Jiang
Applied Mathematics Letters 182 (2026), 110047.
Updated 31 October 2026: the MATLAB package includes full QSVD and partial QSVDS. QSVDS defaults to MATLAB svds with quaternion-structure recovery and checked singular vectors. Select the pure krylov backend to avoid calling svds or eigs.
MATLAB quick start
- Download and extract the ZIP.
- In MATLAB, open the extracted
QSVD-AML-MATLABfolder. - Run the demo and checks:
demo_qsvd
test_qsvd
test_qsvd_partial
test_qsvds
test_qsvds_real_reference
test_qsvds_real_reference('krylov')
test_qsvds_backends
test_qsvds_fallback
Validated with MATLAB R2025a on Windows. No quaternion class or third-party toolbox is required. The ZIP includes English documentation, algorithm notes, examples, tests and a reproducible benchmark script.
Full QSVD or the leading k singular triplets
For A = A0 + A1 i + A2 j + A3 k, supply four same-size real matrices. The MATLAB 1i below is the ordinary complex unit. Dimensions m and n refer to the original quaternion matrix.
B1 = A0 + 1i*A1;
B2 = A2 + 1i*A3;
[m,n] = size(A0);
AC = quaternion_to_complex(B1,B2);
[U,E,V] = QSVD(AC,m,n); % Full decomposition
sigma_max = QSVDS(AC,m,n,1); % Largest value only
[Uk,Ek,Vk,info] = QSVDS(AC,m,n,k); % Top k values AND vectors
opts = struct('backend','krylov'); % No svds/eigs calls
[Uk,Ek,Vk,info] = QSVDS(AC,m,n,k,opts);
s = diag(Ek(1:k,1:k)); % k quaternion singular values
Ak = Uk*Ek*Vk'; % Rank-k approximation
disp(info.flag); % 0 means checks passed
disp(info.relative_residuals);
disp(info.used_builtin_svds); % Actual native-backend use
Outputs are complex representations of quaternion factors. k counts quaternion singular values, with genuine multiplicities retained. The partial factor sizes are 2m × 2k, 2k × 2k and 2n × 2k. Existing calls to qsvd_complex(AC,m,n,tol) retain their full-QSVD behavior.
Select a backend
backend='svds'(default): MATLAB svds, followed by quaternion pair recovery, thin QSVD refinement and residual/orthogonality checks. This recovery cost is included in the QSVDS timings below.backend='krylov': a self-contained, structure-preserving, thick-restarted block Krylov method. It retains search history to improve flat-spectrum convergence and uses the original QSVD on thin projections.backend='subspace': the previous two-sided subspace solver, retained for comparison. Flat spectra can converge slowly.
Default tolerance is 10−10. Inspect info.flag, info.relative_residuals and info.orthogonality. A failed check is reported rather than presented as successful convergence. A failed native attempt can use the pure Krylov backend, with the reason recorded in info.fallback_reason. An explicit k = min(m,n) request uses full QSVD.
Python with NumPy
Use qsvd for a full economy decomposition and qsvds for the leading k quaternion singular triplets. Python QSVDS uses paired block Krylov iteration with thin projected decompositions. It requires only NumPy.
Download Python package (ZIP) · Python source and tests
Extract the ZIP, open the folder containing qsvd.py, and install NumPy with python -m pip install numpy.
import numpy as np
from qsvd import quaternion_to_complex, qsvd, qsvds
rng = np.random.default_rng(8)
a0, a1, a2, a3 = rng.normal(size=(4, 16, 12))
ac = quaternion_to_complex(a0 + 1j*a1, a2 + 1j*a3)
u, s, v = qsvd(ac)
np.testing.assert_allclose((u * np.tile(s, 2)) @ v.conj().T, ac, atol=1e-11)
sigma_max = qsvds(ac, 1, values_only=True)[0]
uk, sk, vk = qsvds(ac, 3)
approx = (uk * np.tile(sk, 2)) @ vk.conj().TEach singular value appears once in s. The second half of the columns of v contains the quaternion partners of the first half. Run python -m unittest -v in the extracted folder to check the examples’ numerical properties and compare with an independent real representation. Tested with Python 3.12 and NumPy 2.3.5.
MATLAB speed and accuracy
MATLAB R2025a, Intel Core i5-12500, 6 computation threads. The table shows median wall time over three runs for a 1536 × 1024 quaternion matrix with a flat singular spectrum (3072 × 2048 complex representation). All results shown converged.
| k | Full QSVD | Pure Krylov | Default QSVDS including recovery | Raw MATLAB svds |
|---|---|---|---|---|
| 1 | 15.120 s | 17.252 s | 13.555 s | 11.717 s |
| 5 | 15.120 s | 22.943 s | 21.393 s | 18.879 s |
The pure backend converged in 218 and 244 block iterations; the previous subspace solver did not converge within 1000 iterations on the same matrices. Both new routes passed all 18 benchmark configurations. Partial decomposition does not always beat full QSVD, and the fastest backend depends on the spectrum and matrix size.
Across all tested large matrices, the default QSVDS had a maximum relative singular-value error of 4.24 × 10−15 and maximum two-equation residual of 5.77 × 10−14. The pure Krylov backend had corresponding maxima of 4.46 × 10−13 and 9.84 × 10−11. Raw svds requests 2k complex triplets and excludes quaternion-factor recovery; its requested tolerance is 10−10. Default QSVDS internally requests tol/10 before checking the recovered result. These are synthetic, known-spectrum measurements, not universal accuracy or speed guarantees.
Read the complete benchmark report. The downloadable package includes BENCHMARK.txt and benchmark_qsvds_optimized.m.
MATLAB correctness checks
The source and final extracted ZIP both passed the demo, 8 full-QSVD checks, 35 compatibility/top-k checks, 15 structured-spectrum checks, 30 independent real-representation comparisons per backend, 96 backend/boundary checks, and injected native-error/bad-factor recovery tests. Checks cover repeated singular values, rank deficiency, tall/wide and zero matrices, paired structure, both singular equations, orthogonality, RNG preservation and pure-backend execution paths.
Use the returned status and residuals for your own inputs. The README and algorithm notes describe options, stopping criteria and numerical limits.
Cite the paper
D. Zhang, C. Jiang, V. I. Vasil’ev, and T. Jiang, “A fast universal algorithm for quaternion singular value decomposition,” Applied Mathematics Letters, vol. 182, article 110047, 2026. doi:10.1016/j.aml.2026.110047.
The partial backends are software extensions; they are not claimed as algorithms already presented in the original paper. BibTeX citation.
Contact
Dong Zhang, Qufu Normal University
zhangdong@qfnu.edu.cn
dz_zhangdong@sina.com
dz_zhangdong@163.com