Skip to content

Commit e72d2f4

Browse files
committed
Added pivoting_qr_space example.
1 parent dd785a1 commit e72d2f4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ADD_EXAMPLE(determinant2)
5656
ADD_EXAMPLE(qr)
5757
ADD_EXAMPLE(pivoting_qr)
5858
ADD_EXAMPLE(qr_space)
59+
ADD_EXAMPLE(pivoting_qr_space)
5960
ADD_EXAMPLE(cholesky)
6061
ADD_EXAMPLE(chol)
6162
ADD_EXAMPLE(expm)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! QR example with pre-allocated storage
2+
program example_pivoting_qr_space
3+
use stdlib_linalg_constants, only: ilp
4+
use stdlib_linalg, only: qr, qr_space, linalg_state_type
5+
implicit none
6+
real :: A(104, 32), Q(104, 32), R(32, 32)
7+
real, allocatable :: work(:)
8+
integer(ilp) :: lwork, pivots(32)
9+
type(linalg_state_type) :: err
10+
11+
! Create a random matrix
12+
call random_number(A)
13+
14+
! Prepare QR workspace
15+
call qr_space(A, lwork, pivoting=.true.)
16+
allocate (work(lwork))
17+
18+
! Compute its QR factorization (reduced)
19+
call qr(A, Q, R, pivots, storage=work, err=err)
20+
21+
! Test factorization: Q*R = A
22+
print *, maxval(abs(matmul(Q, R) - A(:, pivots)))
23+
print *, err%print()
24+
25+
end program example_pivoting_qr_space

0 commit comments

Comments
 (0)