@@ -5,6 +5,7 @@ module test_linalg
5
5
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
6
6
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
7
7
use stdlib_linalg, only: diag, eye, trace, outer_product, cross_product, kronecker_product
8
+ use stdlib_linalg_state
8
9
9
10
implicit none
10
11
@@ -49,9 +50,9 @@ contains
49
50
new_unittest("trace_int16", test_trace_int16), &
50
51
new_unittest("trace_int32", test_trace_int32), &
51
52
new_unittest("trace_int64", test_trace_int64), &
52
- #:for k1, t1 in RCI_KINDS_TYPES
53
+ #:for k1, t1 in RCI_KINDS_TYPES
53
54
new_unittest("kronecker_product_${t1[0]}$${k1}$", test_kronecker_product_${t1[0]}$${k1}$), &
54
- #:endfor
55
+ #:endfor
55
56
new_unittest("outer_product_rsp", test_outer_product_rsp), &
56
57
new_unittest("outer_product_rdp", test_outer_product_rdp), &
57
58
new_unittest("outer_product_rqp", test_outer_product_rqp), &
@@ -71,7 +72,8 @@ contains
71
72
new_unittest("cross_product_int8", test_cross_product_int8), &
72
73
new_unittest("cross_product_int16", test_cross_product_int16), &
73
74
new_unittest("cross_product_int32", test_cross_product_int32), &
74
- new_unittest("cross_product_int64", test_cross_product_int64) &
75
+ new_unittest("cross_product_int64", test_cross_product_int64), &
76
+ new_unittest("state_handling", test_state_handling) &
75
77
]
76
78
77
79
end subroutine collect_linalg
@@ -560,7 +562,7 @@ contains
560
562
561
563
562
564
#:for k1, t1 in RCI_KINDS_TYPES
563
- subroutine test_kronecker_product_${t1[0]}$${k1}$(error)
565
+ subroutine test_kronecker_product_${t1[0]}$${k1}$(error)
564
566
!> Error handling
565
567
type(error_type), allocatable, intent(out) :: error
566
568
integer, parameter :: m1 = 1, n1 = 2, m2 = 2, n2 = 3
@@ -593,7 +595,7 @@ contains
593
595
! Expected: C = [1*B, 2*B] = [[1,2,3, 2,4,6], [2,4,6, 4, 8, 12]]
594
596
595
597
end subroutine test_kronecker_product_${t1[0]}$${k1}$
596
- #:endfor
598
+ #:endfor
597
599
598
600
subroutine test_outer_product_rsp(error)
599
601
!> Error handling
@@ -911,6 +913,73 @@ contains
911
913
#:endif
912
914
end subroutine test_cross_product_cqp
913
915
916
+ subroutine test_state_handling(error)
917
+ !> Error handling
918
+ type(error_type), allocatable, intent(out) :: error
919
+
920
+ type(linalg_state) :: state,state_out
921
+
922
+ state = linalg_state(LINALG_SUCCESS,' 32-bit real: ',1.0_sp)
923
+ call check(error, &
924
+ state%message==' 32-bit real: 1.00000000E+00', &
925
+ "malformed state message with 32-bit reals.")
926
+ if (allocated(error)) return
927
+
928
+ state = linalg_state(LINALG_SUCCESS,' 64-bit real: ',1.0_dp)
929
+ call check(error, &
930
+ state%message==' 64-bit real: 1.0000000000000000E+000', &
931
+ "malformed state message with 64-bit reals.")
932
+ if (allocated(error)) return
933
+
934
+ #:if WITH_QP
935
+ state = linalg_state(LINALG_SUCCESS,' 128-bit real: ',1.0_qp)
936
+ call check(error, &
937
+ state%message==' 128-bit real: 1.00000000000000000000000000000000000E+0000', &
938
+ "malformed state message with 128-bit reals.")
939
+ if (allocated(error)) return
940
+ #:endif
941
+
942
+ state = linalg_state(LINALG_SUCCESS,' 32-bit complex: ',(1.0_sp,1.0_sp))
943
+ call check(error, &
944
+ state%message==' 32-bit complex: (1.00000000E+00,1.00000000E+00)', &
945
+ "malformed state message with 32-bit complex: "//trim(state%message))
946
+ if (allocated(error)) return
947
+
948
+ state = linalg_state(LINALG_SUCCESS,' 64-bit complex: ',(1.0_dp,1.0_dp))
949
+ call check(error, &
950
+ state%message==' 64-bit complex: (1.0000000000000000E+000,1.0000000000000000E+000)', &
951
+ "malformed state message with 64-bit complex.")
952
+ if (allocated(error)) return
953
+
954
+ #:if WITH_QP
955
+ state = linalg_state(LINALG_SUCCESS,'128-bit complex: ',(1.0_qp,1.0_qp))
956
+ call check(error, state%message== &
957
+ '128-bit complex: (1.00000000000000000000000000000000000E+0000,1.00000000000000000000000000000000000E+0000)', &
958
+ "malformed state message with 128-bit complex.")
959
+
960
+ #:endif
961
+
962
+ state = linalg_state(LINALG_SUCCESS,' 32-bit array: ',v1=[(1.0_sp,0.0_sp),(0.0_sp,1.0_sp)])
963
+ call check(error, state%message== &
964
+ ' 32-bit array: [(1.00000000E+00,0.00000000E+00) (0.00000000E+00,1.00000000E+00)]', &
965
+ "malformed state message with 32-bit real array.")
966
+ if (allocated(error)) return
967
+
968
+ !> State flag with location
969
+ state = linalg_state('test_formats',LINALG_SUCCESS,' 32-bit real: ',1.0_sp)
970
+ call check(error, &
971
+ state%print()=='[test_formats] returned Success!', &
972
+ "malformed state message with 32-bit real and location.")
973
+ if (allocated(error)) return
974
+
975
+ !> Test error handling procedure
976
+ call linalg_error_handling(state,state_out)
977
+ call check(error, state%print()==state_out%print(), &
978
+ "malformed state message on return from error handling procedure.")
979
+
980
+ end subroutine test_state_handling
981
+
982
+
914
983
pure recursive function catalan_number(n) result(value)
915
984
integer, intent(in) :: n
916
985
integer :: value
0 commit comments