diff --git a/src/QR.cpp b/src/QR.cpp index c542ce6..f08713a 100644 --- a/src/QR.cpp +++ b/src/QR.cpp @@ -21,7 +21,13 @@ namespace QR { * GivensRotation: R * (a, b)^T = (r, 0)^T with R = [[c, s], [-s, c]], * r = +hypot(a, b), c = a/r, s = b/r. */ -static void GivensRotation(float a, float b, float &c, float &s) { +// [[maybe_unused]]: this helper is only referenced from template +// (EigenQR/Tridiagonalize), so in translation units that include this file +// but never instantiate those templates, the definition is legitimately +// unused. The attribute silences -Wunused-function there without hiding +// real dead code in TUs that do use the algorithm. +[[maybe_unused]] static void GivensRotation(float a, float b, float &c, + float &s) { float r = sqrtf(a * a + b * b); if (r == 0.0f) { c = 1.0f; @@ -111,7 +117,7 @@ static void ApplyRotationToVectors(Matrix &V, uint8_t i, float c, * WilkinsonShift: eigenvalue of [[a, b], [b, d]] closest to d. * mu = (a+d)/2 - sign(a-d) * sqrt(((a-d)/2)^2 + b^2), sign(0) = +1. */ -static float WilkinsonShift(float a, float b, float d) { +[[maybe_unused]] static float WilkinsonShift(float a, float b, float d) { float delta = 0.5f * (a - d); float spread = sqrtf(delta * delta + b * b); return 0.5f * (a + d) - (delta >= 0.0f ? spread : -spread); diff --git a/src/QR.hpp b/src/QR.hpp index 95c4f54..02d5b6d 100644 --- a/src/QR.hpp +++ b/src/QR.hpp @@ -90,20 +90,6 @@ template void EigenQR(Matrix &matrixToDecompose, Matrix &eigenVectors, Matrix &eigenValues, uint32_t maxIterations, float tolerance); -/** - * @brief Compute a Givens rotation that zeros the bottom entry of (a, b) - * - * Given the column vector (a, b), produces (c, s) defining the 2x2 - * rotation - * R = [ c s ] - * [ -s c ] - * such that R * (a, b)^T = (r, 0)^T with r = +hypot(a, b) >= 0, i.e. - * c = a / r, s = b / r. - * - * If (a, b) == (0, 0) the identity rotation (c = 1, s = 0) is returned. - */ -static void GivensRotation(float a, float b, float &c, float &s); - /** * @brief Apply the similarity transform A <- G A G^T on rows/cols (i, i+1) * @@ -143,20 +129,6 @@ template static void ApplyRotationToVectors(Matrix &V, uint8_t i, float c, float s); -/** - * @brief Wilkinson shift for a symmetric tridiagonal - * - * Given the trailing 2x2 block - * [ a b ] - * [ b d ] - * returns the eigenvalue of that block that is closest to d. This is the - * empirically best shift for the QR iteration (Trefethen & Bau 13.4.1). - * - * mu = (a+d)/2 - sign(a-d) * sqrt(((a-d)/2)^2 + b^2) - * (with sign(0) taken as +1). - */ -static float WilkinsonShift(float a, float b, float d); - /** * @brief Solve the 2x2 eigenproblem of block rows/cols (lo, lo+1) * diff --git a/src/SVD.cpp b/src/SVD.cpp index 53d95f7..aea037c 100644 --- a/src/SVD.cpp +++ b/src/SVD.cpp @@ -21,8 +21,8 @@ // template parameter N (a compile-time constant per instantiation). // ============================================================================ -float SVD::ComputeHouseholder(const float *x, uint8_t len, float *v, - float &alpha) { +[[maybe_unused]] float SVD::ComputeHouseholder(const float *x, uint8_t len, + float *v, float &alpha) { // Compute ||x|| float norm = 0.0f; for (uint8_t i = 0; i < len; i++) { @@ -506,7 +506,7 @@ template void SVD::SolveBidiagonalBlockJacobi(Matrix &W, uint8_t blockStart, uint8_t blockSize, uint8_t rowsQL, uint8_t rowsQR, Matrix &QL, - Matrix &QR, float tol) { + Matrix &QR) { // Full SVD of an unreduced upper-bidiagonal block of size > 2, computed // as the eigen-decomposition of the symmetric tridiagonal T = BᵀB: // @@ -948,7 +948,7 @@ void SVD::SVD(Matrix &matrixToDecompose, } else if (blockSize > 2) { // Larger block: cyclic Jacobi eigen-solve of BᵀB SVD::SolveBidiagonalBlockJacobi(W, blockStart, blockSize, m, n, QL, - QR, 1e-10f); + QR); } // Move to the next block diff --git a/src/SVD.hpp b/src/SVD.hpp index dfa579f..cf9024b 100644 --- a/src/SVD.hpp +++ b/src/SVD.hpp @@ -302,13 +302,12 @@ static void ApplyBlockFactorsToAccumulators(uint8_t blockStart, * @param rowsQR Number of meaningful rows of QR * @param QL Input/output: left transformation accumulator * @param QR Input/output: right transformation accumulator - * @param tol (unused: Jacobi convergence tolerance is internal) */ template static void SolveBidiagonalBlockJacobi(Matrix &W, uint8_t blockStart, uint8_t blockSize, uint8_t rowsQL, uint8_t rowsQR, Matrix &QL, - Matrix &QR, float tol); + Matrix &QR); /** * @brief Extract singular values from bidiagonal matrix diagonal and sort.