This is the code repository associated with "Minimizing the Arithmetic and Communication Complexity of Jacobi's Method for Eigenvalues and Singular Values" by James Demmel, Hengrui Luo, Ryan Schneider, Yifu Wang, available at https://arxiv.org/abs/2506.03466.
The code has been tested with MATLAB R2024a, on an AMD Ryzen 9 7945HX CPU with Radeon Graphics.
The codes for experiments are organized into separate folders, each named according to the corresponding figures and tables in the paper. Each folder can be run independently. For experiments that are time-consuming, the precomputed data are provided in corresponding .mat files. To reproduce the figures, simply load the .mat file and run the plotting sections in the provided scripts.
ClassicalJacobi is a flexible implementation of the Classical Jacobi method that supports multiple strategies for computing rotation angles.
A: Symmetric matrix to be diagonalized.eps_threshold: Tolerance for convergence, based on off-diagonal norms.method: Specifies the rotation strategy. Options are'eig','trig'and'adversarial':'eig': Uses MATLAB's buit-ineig()function on the 2x2 submatrices.'trig': Computes rotation angles explicitly using trigonometric formulas.'adversarial': Deliberately adds pi/2 to the rotation angle computed bytrigto hinder convergence, following The Cyclic Jacobi Method for Computing the Principal Values of a Complex Matrix, by Forsythe and Henrici.
n3_ratio: Maximum computational budget as a fraction ofn^3floating-point operations.
Q: Orthogonal matrix of eigenvectors.D: Diagonal matrix of eigenvalues.flops: Total floating-point operations performed.sweeps: Total number of sweeps performedsweep_OffNorm_history: History recorded at the end of each sweep in the format[flops, sweeps, maximum off-diagonal absolute value, off-diagonal Frobenius norm].
-
Initialization:
- Validate matrix symmetry.
- Initialize
Qas the identity matrix and setflops,sweepsto zero. - Start tracking execution history as
sweep_OffNorm_history.
-
Iterative Updates:
- Depending on the
method:'eig': Diagonalize 2x2 submatrices using eigen decomposition.'trig': Use trigonometric formulas to compute rotation angles.'adversarial': Adding pi/2 to the trigonometric rotation angle to resist convergence
- Update matrix
Aand orthogonal matrixQwith each rotation. - Update cumulative FLOPs and
sweep_OffNorm_history.
- Depending on the
-
Convergence:
- Terminate when the off-diagonal norm falls below
eps_thresholdor the FLOP budget is exhausted.
- Terminate when the off-diagonal norm falls below
BlockJacobi performs a block Jacobi method for symmetric eigenproblems. The method partitions the input matrix into blocks and iteratively applies orthogonal transformations to reduce off-diagonal blocks. It supports multiple orderings, including row-cyclic, column-cyclic, and random ordering, as well as various pivoting strategies, including QR decomposition with column pivoting (QRCP, following A Global Convergence Proof for Cyclic Jacobi Methods with Block Rotations by Drmac), LU decomposition with partial pivoting (LUPP), and randomized pivoting.
A: Symmetric matrix to be diagonalized.blockSizes: Array specifying the sizes of each block. The sum ofblockSizesmust equal the size ofA.eps_threshold: Tolerance for convergence, based on off-diagonal norms.ordering: Specifies the iteration order. Options are:'columncyclic': Cyclically iterate over column pairs.'rowcyclic': Cyclically iterate over row pairs.'rowcyclic': Randomly iterate over block pairs.
pivot_method: Specifies the pivoting strategy for block transformations. Options are:'eig': Directly uses eigen-decomposition for block transformations without any pivoting (i.e. vanilla block Jacobi).'qrcp': Applies QRCP to permute the rotation matrix in addition to solving the block subproblem, which guarantees convergence of block Jacobi.'lupp': Applies LUPP to permute the rotation matrix in addition to solving the block subproblem, which guarantees convergence of block Jacobi.'fastlu': Replaces MATLAB's built-inlu()function with a recursive LU decomposition with partial pivoting, which requires fewer FLOPs for galactic matrices.'random': Applies random permutation to the rotation matrix, which serves as a comparison to QRCP and LUPP
n3_ratio: Maximum computational budget as a fraction ofn^3floating-point operations.
Q: Orthogonal matrix of eigenvectors.D: Diagonal matrix of eigenvalues.flops: Total floating-point operations performed.sweeps: Total number of sweeps performedsweep_OffNorm_history: History recorded at the end of each sweep in the format[flops, sweeps, maximum off-diagonal absolute value, off-diagonal Frobenius norm].
-
Initialization:
- Validate matrix symmetry.
- Initialize
Qas the identity matrix and setflops,sweepsto zero. - Start tracking execution history as
sweep_OffNorm_history.
-
Iterative Updates:
-
Loop over block pairs following the specified
ordering('rowcyclic','columncyclic', or'random'). -
For each block pair:
-
Compute the rotation matrix based on the specified
pivot_method:'eig': Use eigenvalue decomposition for the selected block pair.'qrcp': Apply QRCP to permute the rotation matrix after solving the block subproblem.'lupp': Apply LUPP to permute the rotation matrix after solving the block subproblem.'fastlu': Replace MATLAB buiilt-inlu()with recursive LU decomposition.'random': Apply random permutation to the rotational matrix.
-
Update matrix
Aand orthogonal matrixQafter each rotation. -
Update cumulative FLOPs and
sweep_OffNorm_history.
-
-
-
Convergence:
- Terminate when the off-diagonal norm falls below
eps_thresholdor the FLOP budget is exhausted.
- Terminate when the off-diagonal norm falls below
Below provides detailed descriptions and explanations of the Recursive Jacobi methods implemented in the provided MATLAB files. These methods solve symmetric eigenproblems using various techniques for the subproblem within each block such as LU decomposition, QR decomposition. Each function terminates when the off-diagonal norm falls below eps_threshold or the FLOP budget is exhausted.
This function implements the vanilla version of the Recursive Jacobi method for symmetric eigenproblems. It directly applies Algorithm 3 without pivoting (i.e., lines 11 - 13) , which serves as the baseline for all other specialized methods.
A: Symmetric matrix to be diagonalized.n_threshold: Threshold for solving the problem as base case directly, based on available fast memory.f: the log block size parameter, strictly between 0 and 1.eps_threshold: Tolerance for convergence, based on off-diagonal norms.recdepth: Current recursion depthbreak_flag: Flag to halt recursion prematurely.n3_ratio: Maximum computational budget as a fraction ofn^3floating-point operations.
Q: Orthogonal matrix of eigenvectors.D: Diagonal matrix of eigenvalues.flops: Total floating-point operations performed.sweeps: Total number of sweeps performedsweep_OffNorm_history: History recorded at the highest level and at the end of each ``sweep" in the format [flops, sweeps, maximum off-diagonal absolute value, off-diagonal Frobenius norm].
The below variants of Recursive Jacobi methods share similar inputs and outputs parameters compared to the RecursiveJacobiplain functions, therefore we only states the main difference:
-
Initialization:
- Validate matrix symmetry.
- Get input problem size
nand log block parameterb = n^f - Initialize
Qas the identity matrix and setflops,sweepsto zero. - If
rec_depth == 0, start tracking execution history assweep_OffNorm_history.
-
Solve bottom case directly
- If
n <= n_thresholdor2b >= n, solve the problem directly.
- If
-
Recursive Updates:
-
Iterate thorugh each sub-problem
A_hat:-
Solve the sub-problem by recursively calling
RecursiveJacobiplain(A_hat) -
Update matrix
A, orthogonal matrixQand cumulative FLOPs after each recursive call.
-
-
If
rec_depth == 0, updatesweep_OffNorm_history.
-
-
Convergence:
- Terminate when the off-diagonal norm falls below
eps_thresholdor the FLOP budget is exhausted.
- Terminate when the off-diagonal norm falls below
Difference:
- Implements LUPP in lines 11 - 13 to ensure convergence.
Difference:
- The same as RecursiveJacobiLUPP, but the built-in MATLAB
lu()function is replaced with recursive LUPP, which achieves the optimal asymptotic complexity for galactic matrices.
Difference:
- Implements QRCP in lines 11 - 13 to ensure convergence, however at the expense of higher computational cost.
blockOneSidedJacobi implements the classical one-sided Jacobi method to compute the singular value decomposition (SVD) of a square matrix. The algorithm applies a sequence of orthogonal rotations to jointly diagonalize the right singular vectors, driving the matrix towards orthogonal form.
G: n x n real matrix to be factorized (assumed square)b: Block size (must dividenexactly)tol: Stopping tolerance for "near orthogonality"maxSweeps: Maximum number of outer loop sweepswantVectors: Boolean flag indicating whether sigular vectors are needed
U: Approximate left singular vectorsSigma: Diagonal matrix of singular valuesV: Approximate right singular vectors
-
Initialization:
- Check that input matrix
Gis square. - Verify that block size
bdividesnexactly. - Compute number of blocks
nb = n / b. - Initialize
V = eye(n)ifwantVectors == true; otherwise setV = [].
- Check that input matrix
-
Outer Loop:
-
Repeat for at most
maxSweepsouter sweeps:-
If
Gis "near orthogonal", terminate early. -
For each block pair
(I, J)with1 <= I < J <= nb:-
Extract column indices
colsIandcolsJfor blocksIandJ. -
Form submatrix
Gsub = [G(:, colsI), G(:, colsJ)]. -
Compute
A_hat = Gsub' * Gsub. -
If
A_hatis far from digonal:- Compute eigen-decomposition
[V_hat, ~] = eig(A_hat). - Optional: If
det(V_hat) < 0, flip first column ofV_hatto ensure determinant positivity. - Apply rotation: update
Gaccordingly. - If
wantVectors == true, updateVaccordingly.
- Compute eigen-decomposition
-
-
-
-
Postprocessing:
- Compute column norms of
Gto form diagonal matrixSigma. - If
wantVectors == true, computeU = G * inv(Sigma); otherwise setU = [].
- Compute column norms of
We simultaneously track two types of off-diagonal norm to measure convergence.
Computes the maximum off-diagonal absolute value of the input matrix.
Computes the off-diagonal Frobenius norm of the input matrix.
In addition to standard random generation via A = randn(n_size); A = (A + A')/2, three types of adversarial symmetric matrices are provided to evaluate the algorithms under challenging scenarios.
Recursive implementation of LUPP, according to Fast Linear Algebra is Stable, by Demmel, Dumitriu and Holtz.
Citation If you use our code, please refer to LICENSE and please cite our paper using following BibTeX item (we need to change this once submitted):
@article{2025recursivejacobi,
title={Minimizing the Arithmetic and Communication Complexity of Jacobi's Method for Eigenvalues and Singular Values},
author={James Demmel and Hengrui Luo and Ryan Schneider and Yifu Wang},
year={2025},
eprint={2506.03466},
archivePrefix={arXiv},
primaryClass={math.NA},
url={https://arxiv.org/abs/2506.03466},
}
Thank you again for the interest and please reach out if you have further questions.