@@ -5,6 +5,8 @@ module test_linalg_expm
5
5
use testdrive, only: error_type, check, new_unittest, unittest_type
6
6
use stdlib_linalg_constants
7
7
use stdlib_linalg, only: expm, eye, mnorm
8
+ use stdlib_linalg_state, only: linalg_state_type, linalg_error_handling, LINALG_ERROR, &
9
+ LINALG_INTERNAL_ERROR, LINALG_VALUE_ERROR
8
10
9
11
implicit none (type,external)
10
12
@@ -21,6 +23,7 @@ module test_linalg_expm
21
23
22
24
#:for rk,rt,ri in RC_KINDS_TYPES
23
25
tests = [tests, new_unittest("expm_${ri}$",test_expm_${ri}$)]
26
+ tests = [tests, new_unittest("Error-handling expm_${ri}$",test_error_handling_expm_${ri}$)]
24
27
#:endfor
25
28
26
29
end subroutine test_expm_computation
@@ -61,6 +64,39 @@ module test_linalg_expm
61
64
end subroutine test_expm_${ri}$
62
65
#:endfor
63
66
67
+ !> Test error handler.
68
+ #:for rk,rt,ri in RC_KINDS_TYPES
69
+ subroutine test_error_handling_expm_${ri}$(error)
70
+ type(error_type), allocatable, intent(out) :: error
71
+ ! Problem dimension.
72
+ integer(ilp), parameter :: n = 5, m = 6
73
+ ! Test matrix.
74
+ ${rt}$ :: A(n, n), E(n, n)
75
+ type(linalg_state_type) :: err
76
+ integer(ilp) :: i
77
+
78
+ ! Initialize matrix.
79
+ A = 0.0_${rk}$
80
+ do i = 1, n-1
81
+ A(i, i+1) = m*1.0_${rk}$
82
+ enddo
83
+
84
+ ! Compute matrix exponential.
85
+ E = expm(A, order=-1, err=err)
86
+ ! Check result.
87
+ call check(error, err%error(), "Negative Pade order")
88
+ if (allocated(error)) return
89
+
90
+ ! Compute matrix exponential.
91
+ E = expm(A(:n, :n-1), err=err)
92
+ ! Check result.
93
+ call check(error, err%error(), "Invalid matrix size")
94
+ if (allocated(error)) return
95
+
96
+ return
97
+ end subroutine test_error_handling_expm_${ri}$
98
+ #:endfor
99
+
64
100
end module test_linalg_expm
65
101
66
102
program test_expm
0 commit comments