@@ -5,6 +5,8 @@ module test_linalg_expm
55 use testdrive, only: error_type, check, new_unittest, unittest_type
66 use stdlib_linalg_constants
77 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
810
911 implicit none (type,external)
1012
@@ -21,6 +23,7 @@ module test_linalg_expm
2123
2224 #:for rk,rt,ri in RC_KINDS_TYPES
2325 tests = [tests, new_unittest("expm_${ri}$",test_expm_${ri}$)]
26+ tests = [tests, new_unittest("Error-handling expm_${ri}$",test_error_handling_expm_${ri}$)]
2427 #:endfor
2528
2629 end subroutine test_expm_computation
@@ -61,6 +64,39 @@ module test_linalg_expm
6164 end subroutine test_expm_${ri}$
6265 #:endfor
6366
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+
64100end module test_linalg_expm
65101
66102program test_expm
0 commit comments