Test module for LSQR.
These routines define a class of least-squares test problems for testing algorithms LSQR and CRAIG (Paige and Saunders, ACM TOMS, 1982).
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | lenrw | = | 10000 |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | nout | = | -1 |
output unit for printing |
|
| real(kind=wp), | public, | dimension(lenrw) | :: | rw |
workspace array |
| procedure, public :: lsqr => LSQR | main solver routine |
| procedure, public :: acheck | |
| procedure, public :: xcheck | |
| procedure, public :: aprod => aprod_test_solver | |
| procedure, public :: test | |
| procedure, public :: aprod1 | |
| procedure, public :: aprod2 | |
| procedure, public :: lstp |
Unit test.
This is an example driver routine for running LSQR. It generates a test problem, solves it, and examines the results. Note that subroutine aprod must be declared external if it is used only in the call to LSQR (and acheck).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(test_solver), | intent(inout) | :: | me | |||
| integer | :: | m | ||||
| integer | :: | n | ||||
| integer | :: | nduplc | ||||
| integer | :: | npower | ||||
| real(kind=wp) | :: | damp |
This is the matrix-vector product routine required by subroutines LSQR and CRAIG for a test matrix of the form A = HYDHZ. The quantities defining D, HY, HZ are in the work array rw, followed by a work array w. These are passed to aprod1 and aprod2 in order to make the code readable.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(test_solver), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | mode | |||
| integer, | intent(in) | :: | m | |||
| integer, | intent(in) | :: | n | |||
| real(kind=wp), | intent(inout), | dimension(:) | :: | x |
dimension n |
|
| real(kind=wp), | intent(inout), | dimension(:) | :: | y |
dimension m |
aprod1 computes y = y + Ax for subroutine aprod, where A is a test matrix of the form A = HYD*HZ, and the latter matrices HY, D, HZ are represented by input vectors with the same name.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(test_solver), | intent(inout) | :: | me | |||
| integer | :: | m | ||||
| integer | :: | n | ||||
| integer | :: | maxmn | ||||
| integer | :: | minmn | ||||
| real(kind=wp) | :: | x(n) | ||||
| real(kind=wp) | :: | y(m) | ||||
| real(kind=wp) | :: | d(minmn) | ||||
| real(kind=wp) | :: | hy(m) | ||||
| real(kind=wp) | :: | hz(n) | ||||
| real(kind=wp) | :: | w(maxmn) |
aprod2 computes x = x + A(t)y for subroutine aprod, where A is a test matrix of the form A = HYD*HZ, and the latter matrices HY, D, HZ are represented by input vectors with the same name.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(test_solver), | intent(inout) | :: | me | |||
| integer | :: | m | ||||
| integer | :: | n | ||||
| integer | :: | maxmn | ||||
| integer | :: | minmn | ||||
| real(kind=wp) | :: | x(n) | ||||
| real(kind=wp) | :: | y(m) | ||||
| real(kind=wp) | :: | d(minmn) | ||||
| real(kind=wp) | :: | hy(m) | ||||
| real(kind=wp) | :: | hz(n) | ||||
| real(kind=wp) | :: | w(maxmn) |
hprod applies a Householder transformation stored in hz to get y = ( I - 2hzhz(transpose) ) * x.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer | :: | n | ||||
| real(kind=wp) | :: | hz(n) | ||||
| real(kind=wp) | :: | x(n) | ||||
| real(kind=wp) | :: | y(n) |
lstp generate a sparse least-squares test problem of the form ( A )x = ( b ) ( dampI ) ( 0 ) for solution by LSQR, or a sparse underdetermined system Ax + damps = b for solution by CRAIG. The matrix A is m by n and is constructed in the form A = HYD*HZ, where D is an m by n diagonal matrix, and HY and HZ are Householder transformations.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(test_solver), | intent(inout) | :: | me | |||
| integer | :: | m | ||||
| integer | :: | n | ||||
| integer | :: | maxmn | ||||
| integer | :: | minmn | ||||
| integer | :: | nduplc | ||||
| integer | :: | npower | ||||
| real(kind=wp) | :: | damp | ||||
| real(kind=wp) | :: | x(n) | ||||
| real(kind=wp) | :: | b(m) | ||||
| real(kind=wp) | :: | d(minmn) | ||||
| real(kind=wp) | :: | hy(m) | ||||
| real(kind=wp) | :: | hz(n) | ||||
| real(kind=wp) | :: | w(maxmn) | ||||
| real(kind=wp) | :: | acond | ||||
| real(kind=wp) | :: | rnorm |