validateSpectraParams

C++ Function Reference

1 Signature

std::tuple< int, int > BigDataStatMeth::validateSpectraParams(int n, int k, int ncv)

2 Description

Validate and adjust Spectra parameters for convergence.

3 Parameters

  • n (int): Matrix size
  • k (int): Number of eigenvalues requested
  • ncv (int): Number of Arnoldi vectors

4 Returns

Adjusted parameters that satisfy Spectra constraints

5 Details

nMatrix size kNumber of eigenvalues requested ncvNumber of Arnoldi vectors Adjusted parameters that satisfy Spectra constraints

6 Caller Graph

Function dependencies

7 Source Code

File: inst/include/hdf5Algebra/matrixEigenDecomposition.hppLines 72-92

inline std::tuple<int, int> validateSpectraParams(int n, int k, int ncv) {
        // Ensure k is reasonable
        if (k <= 0) k = std::min(n, 6);
        if (k >= n) k = n - 1;
        
        // Calculate optimal ncv following RSpectra defaults
        if (ncv <= 0) {
            ncv = std::min(n, std::max(2 * k + 1, k + 2));
        }
        
        // Enforce Spectra constraints: k + 2 <= ncv <= n
        ncv = std::max(ncv, k + 2);
        ncv = std::min(ncv, n);
        
        // Additional safety: ensure we have enough space for convergence
        if (ncv - k < 2) {
            ncv = std::min(n, k + 2);
        }
        
        return std::make_tuple(k, ncv);
    }

8 Usage Example

#include "BigDataStatMeth.hpp"

// Example usage
auto result = validateSpectraParams(...);