1 // =============================================================================
2 // === spqr_tol ================================================================
3 // =============================================================================
4 
5 // Return the default column 2-norm tolerance
6 
7 #include "spqr.hpp"
8 #include <limits>
9 #include <algorithm>
10 
11 // return the default tol (-1 if error)
spqr_tol(cholmod_sparse * A,cholmod_common * cc)12 template <typename Entry> double spqr_tol
13 (
14     // inputs, not modified
15     cholmod_sparse *A,
16 
17     // workspace and parameters
18     cholmod_common *cc
19 )
20 {
21     RETURN_IF_NULL_COMMON (EMPTY) ;
22     RETURN_IF_NULL (A, EMPTY) ;
23     double tol = (20 * ((double) A->nrow + (double) A->ncol) * DBL_EPSILON *
24                   spqr_maxcolnorm <Entry> (A, cc));
25     // MathWorks modification: if the tolerance becomes Inf, replace it with
26     // realmax; otherwise, we may end up with an all-zero matrix R
27     // (see g1284493)
28     tol = std::min(tol, std::numeric_limits<double>::max());
29 
30     return (tol) ;
31 }
32 
33 template double spqr_tol <Complex>   // return the default tol
34 (
35     // inputs, not modified
36     cholmod_sparse *A,
37 
38     // workspace and parameters
39     cholmod_common *cc
40 ) ;
41 
42 template double spqr_tol <double>    // return the default tol
43 (
44     // inputs, not modified
45     cholmod_sparse *A,
46 
47     // workspace and parameters
48     cholmod_common *cc
49 ) ;
50 
51