Skip to content

Commit f28bb47

Browse files
committed
Add tests for is_skew_symmetric and start is_triangular tests
1 parent 4c5fdf1 commit f28bb47

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

src/tests/linalg/test_linalg.f90

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ program test_linalg
33
use stdlib_error, only: check
44
use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64
55
use stdlib_linalg, only: diag, eye, trace, outer_product, is_square ,is_diagonal, &
6-
is_symmetric, is_skew_symmetric
6+
is_symmetric, is_skew_symmetric, is_triangular!, is_hessenberg
77

88
implicit none
99

@@ -132,10 +132,27 @@ program test_linalg
132132
call test_is_skew_symmetric_cdp
133133
call test_is_skew_symmetric_cqp
134134

135-
!call test_is_skew_symmetric_int8
136-
!call test_is_skew_symmetric_int16
137-
!call test_is_skew_symmetric_int32
138-
!call test_is_skew_symmetric_int64
135+
call test_is_skew_symmetric_int8
136+
call test_is_skew_symmetric_int16
137+
call test_is_skew_symmetric_int32
138+
call test_is_skew_symmetric_int64
139+
140+
141+
!
142+
! is_triangular
143+
!
144+
call test_is_triangular_rsp
145+
!call test_is_triangular_rdp
146+
!call test_is_triangular_rqp
147+
148+
!call test_is_triangular_csp
149+
!call test_is_triangular_cdp
150+
!call test_is_triangular_cqp
151+
152+
!call test_is_triangular_int8
153+
!call test_is_triangular_int16
154+
!call test_is_triangular_int32
155+
!call test_is_triangular_int64
139156

140157
contains
141158

@@ -1426,6 +1443,62 @@ subroutine test_is_skew_symmetric_int64
14261443
end subroutine test_is_skew_symmetric_int64
14271444

14281445

1446+
subroutine test_is_triangular_rsp
1447+
real(sp) :: A_true_s_u(2,2), A_false_s_u(2,2) !square matrices (upper triangular)
1448+
real(sp) :: A_true_sf_u(2,3), A_false_sf_u(2,3) !short and fat matrices
1449+
real(sp) :: A_true_ts_u(3,2), A_false_ts_u(3,2) !tall and skinny matrices
1450+
real(sp) :: A_true_s_l(2,2), A_false_s_l(2,2) !square matrices (lower triangular)
1451+
real(sp) :: A_true_sf_l(2,3), A_false_sf_l(2,3) !short and fat matrices
1452+
real(sp) :: A_true_ts_l(3,2), A_false_ts_l(3,2) !tall and skinny matrices
1453+
logical :: should_be_true_s_u, should_be_false_s_u, true_when_working_s_u !upper logicals
1454+
logical :: should_be_true_sf_u, should_be_false_sf_u, true_when_working_sf_u
1455+
logical :: should_be_true_ts_u, should_be_false_ts_u, true_when_working_ts_u
1456+
logical :: should_be_true_s_l, should_be_false_s_l, true_when_working_s_l !lower logicals
1457+
logical :: should_be_true_sf_l, should_be_false_sf_l, true_when_working_sf_l
1458+
logical :: should_be_true_ts_l, should_be_false_ts_l, true_when_working_ts_l
1459+
logical :: true_when_working_u, true_when_working_l, true_when_working
1460+
write(*,*) "test_is_triangular_rsp"
1461+
!upper triangular
1462+
A_true_s_u = reshape([1.,0.,3.,4.],[2,2]) !generate triangular and non-triangular matrices of 3 types
1463+
A_false_s_u = reshape([1.,2.,0.,4.],[2,2])
1464+
A_true_sf_u = reshape([1.,0.,3.,4.,0.,6.],[2,3])
1465+
A_false_sf_u = reshape([1.,2.,3.,4.,0.,6.],[2,3])
1466+
A_true_ts_u = reshape([1.,0.,0.,4.,5.,0.],[3,2])
1467+
A_false_ts_u = reshape([1.,0.,0.,4.,5.,6.],[3,2])
1468+
should_be_true_s_u = is_triangular(A_true_s_u,'u') !test generated matrices
1469+
should_be_false_s_u = is_triangular(A_false_s_u,'u')
1470+
should_be_true_sf_u = is_triangular(A_true_sf_u,'u')
1471+
should_be_false_sf_u = is_triangular(A_false_sf_u,'u')
1472+
should_be_true_ts_u = is_triangular(A_true_ts_u,'U')
1473+
should_be_false_ts_u = is_triangular(A_false_ts_u,'U')
1474+
true_when_working_s_u = (should_be_true_s_u .and. (.not. should_be_false_s_u)) !combine results
1475+
true_when_working_sf_u = (should_be_true_sf_u .and. (.not. should_be_false_sf_u))
1476+
true_when_working_ts_u = (should_be_true_ts_u .and. (.not. should_be_false_ts_u))
1477+
true_when_working_u = (true_when_working_s_u .and. true_when_working_sf_u .and. true_when_working_ts_u)
1478+
!lower triangular
1479+
A_true_s_l = reshape([1.,2.,0.,4.],[2,2]) !generate triangular and non-triangular matrices of 3 types
1480+
A_false_s_l = reshape([1.,0.,3.,4.],[2,2])
1481+
A_true_sf_l = reshape([1.,2.,0.,4.,0.,0.],[2,3])
1482+
A_false_sf_l = reshape([1.,2.,3.,4.,0.,0.],[2,3])
1483+
A_true_ts_l = reshape([1.,2.,3.,0.,5.,6.],[3,2])
1484+
A_false_ts_l = reshape([1.,2.,3.,4.,5.,6.],[3,2])
1485+
should_be_true_s_l = is_triangular(A_true_s_l,'l') !test generated matrices
1486+
should_be_false_s_l = is_triangular(A_false_s_l,'l')
1487+
should_be_true_sf_l = is_triangular(A_true_sf_l,'l')
1488+
should_be_false_sf_l = is_triangular(A_false_sf_l,'l')
1489+
should_be_true_ts_l = is_triangular(A_true_ts_l,'L')
1490+
should_be_false_ts_l = is_triangular(A_false_ts_l,'L')
1491+
true_when_working_s_l = (should_be_true_s_l .and. (.not. should_be_false_s_l)) !combine results
1492+
true_when_working_sf_l = (should_be_true_sf_l .and. (.not. should_be_false_sf_l))
1493+
true_when_working_ts_l = (should_be_true_ts_l .and. (.not. should_be_false_ts_l))
1494+
true_when_working_l = (true_when_working_s_l .and. true_when_working_sf_l .and. true_when_working_ts_l)
1495+
!combine upper and lower results
1496+
true_when_working = (true_when_working_u .and. true_when_working_l)
1497+
call check(true_when_working, &
1498+
msg="true_when_working failed.",warn=warn)
1499+
end subroutine test_is_triangular_rsp
1500+
1501+
14291502
pure recursive function catalan_number(n) result(value)
14301503
integer, intent(in) :: n
14311504
integer :: value

0 commit comments

Comments
 (0)