Skip to content

Commit e75bb2f

Browse files
committed
add solve_lu test
1 parent c9f5f0c commit e75bb2f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ ADD_EXAMPLE(blas_gemv)
2020
ADD_EXAMPLE(lapack_getrf)
2121
ADD_EXAMPLE(solve1)
2222
ADD_EXAMPLE(solve2)
23+
ADD_EXAMPLE(solve3)
2324
ADD_EXAMPLE(determinant)
2425
ADD_EXAMPLE(determinant2)

example/linalg/example_solve3.f90

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
program example_solve3
2+
use stdlib_linalg_constants, only: sp
3+
use stdlib_linalg, only: solve_lu, linalg_state_type
4+
implicit none
5+
6+
integer(ilp) :: test
7+
complex(sp), allocatable :: A(:,:),b(:),x(:)
8+
9+
! Solve a system of 3 complex linear equations:
10+
! 2x + iy + 2z = (5-i)
11+
! -ix + (4-3i)y + 6z = i
12+
! 4x + 3y + z = 1
13+
14+
! Note: Fortran is column-major! -> transpose
15+
A = transpose(reshape([(2.0, 0.0),(0.0, 1.0),(2.0,0.0), &
16+
(0.0,-1.0),(4.0,-3.0),(6.0,0.0), &
17+
(4.0, 0.0),(3.0, 0.0),(1.0,0.0)] , [3,3]))
18+
b = [(5.0,-1.0),(0.0,1.0),(1.0,0.0)]
19+
20+
! Pre-allocate x
21+
allocate(x,source=b)
22+
23+
! Call system many times avoiding reallocation
24+
do test=1,100
25+
call solve_lu(A,b,x)
26+
print "(i2,'-th solution: ',*(1x,f12.6))", test,x
27+
end do
28+
29+
end program example_solve3
30+

0 commit comments

Comments
 (0)