@@ -3,7 +3,7 @@ program test_linalg
3
3
use stdlib_error, only: check
4
4
use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64
5
5
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
7
7
8
8
implicit none
9
9
@@ -132,10 +132,27 @@ program test_linalg
132
132
call test_is_skew_symmetric_cdp
133
133
call test_is_skew_symmetric_cqp
134
134
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
139
156
140
157
contains
141
158
@@ -1426,6 +1443,62 @@ subroutine test_is_skew_symmetric_int64
1426
1443
end subroutine test_is_skew_symmetric_int64
1427
1444
1428
1445
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
+
1429
1502
pure recursive function catalan_number(n) result(value)
1430
1503
integer , intent (in ) :: n
1431
1504
integer :: value
0 commit comments