How to change the tolerance of the QRPivoted method

Hi there :slight_smile:

I’m using the LinearAlgebra package in Julia to use the QRPivoted method. The documentation is not very clear about the use of the tolerance. I want to use que qr pivoted function on a matrix A but I want to be able to change the tolerance.
To use the qr pivoted function, the documentation says to do the following:

qr(A, Val(false)) which actually works once you do it in Julia for any matrix A

However, the only mention of tolerance in the documentation is
qr(A::SparseMatrixCSC; tol=_default_tol(A), ordering=ORDERING_DEFAULT)

I don’t know how to use it in Julia because I have tried
qr(A, 10e-10, ordering = false) and
qr(A, 10e-10)

and nothing works. Can anyone help with that?
I would like to do something like
qr(A, Val(false), 10e-10) to make a QRPivoted matrix with a tolerance of the method of 10e-10.

It should work on any matrix A so feel free to use any one you want.

Thanks in advanced

I would try qr(A, tol=10e-10).

1 Like

tol is keyword argument which is set by calling qr(A, tol=1e-10) as @goerch indicated. The clue for this in the documentation is the semicolon in

qr(A::SparseMatrixCSC; tol=_default_tol(A), ordering=ORDERING_DEFAULT)

For the function def f(x, y, z; a=default1, b=default2), the arguments x,y,z before the semicolon are required and specified by order. The arguments a and b come with default values and can be set in any order or left to default values, but you need to name them when calling, as in f(1,2,3, a="foo") or f(1,2,3, b="bar", a="foo").

Julia Doc: Keyword Arguments

By the way, 10e-10 is a literal for 10 \times 10^{-10} = 10^{-9}. If what you want is 10^{-10}, enter it as 1e-10. Just guessing here!

2 Likes

No, I have tried that and it doesn’t work.

I have tried both F = qr(A; tol = 10e-10) and F = qr(A, Val(true); tol = 10e-10) and none of them work.

Here’s a minimal working example that works (julia-1.6.0)

julia> using LinearAlgebra, SparseArrays

julia> i = [1,1,2,2,3,3,4,4]; 

julia> j = [1,2,2,3,3,4,4,2];

julia> v = [1.0,2.0,-5.0,3.0,-1.0,2.0,-2.0,4.0];

julia> A = sparse(i,j,v)
4Γ—4 SparseMatrixCSC{Float64, Int64} with 8 stored entries:
 1.0   2.0    β‹…     β‹… 
  β‹…   -5.0   3.0    β‹… 
  β‹…     β‹…   -1.0   2.0
  β‹…    4.0    β‹…   -2.0

julia> F = qr(A, tol=1-08)
SuiteSparse.SPQR.QRSparse{Float64, Int64}
Q factor:
4Γ—4 SuiteSparse.SPQR.QRSparseQ{Float64, Int64}:
 1.0   0.0        0.0       0.0
 0.0  -0.780869  -0.551142  0.294086
 0.0   0.624695  -0.688927  0.367607
 0.0   0.0        0.470767  0.882258
R factor:
4Γ—4 SparseMatrixCSC{Float64, Int64} with 8 stored entries:
 1.0  2.0        β‹…         β‹… 
  β‹…   6.40312  -2.34261  -1.24939
  β‹…    β‹…       -2.12419   2.31939
  β‹…    β‹…         β‹…        1.0293
Row permutation:
4-element Vector{Int64}:
 1
 2
 4
 3
Column permutation:
4-element Vector{Int64}:
 1
 2
 3
 4
julia>
2 Likes