Skip to content

Commit dc81688

Browse files
committed
workspace query schur_space
1 parent 908cab1 commit dc81688

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/stdlib_linalg.fypp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ module stdlib_linalg
662662
!! are provided, no internal allocations will take place during the decomposition.
663663
!!
664664
#:for rk,rt,ri in RC_KINDS_TYPES
665-
pure module subroutine get_schur_${ri}$_workspace(a,lwork,err)
665+
module subroutine get_schur_${ri}$_workspace(a,lwork,err)
666666
!> Input matrix a[m,m]
667667
${rt}$, intent(in), target :: a(:,:)
668668
!> Minimum workspace size for the decomposition operation

src/stdlib_linalg_schur.fypp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ submodule (stdlib_linalg) stdlib_linalg_schur
3838
!> Wrapper function to handle GEES error codes
3939
elemental subroutine handle_gees_info(info, m, n, ldvs, err)
4040
integer(ilp), intent(in) :: info, m, n, ldvs
41-
type(linalg_state), intent(out) :: err
41+
type(linalg_state_type), intent(out) :: err
4242

4343
! Process GEES output
4444
select case (info)
@@ -77,7 +77,53 @@ submodule (stdlib_linalg) stdlib_linalg_schur
7777

7878
end subroutine handle_gees_info
7979

80-
#:for rk, rt, ri in RC_KINDS_TYPES
80+
#:for rk, rt, ri in RC_KINDS_TYPES
81+
!> Workspace query
82+
subroutine get_schur_${ri}$_workspace(a,lwork,err)
83+
!> Input matrix a[m,m]
84+
${rt}$, intent(in), target :: a(:,:)
85+
!> Minimum workspace size for the decomposition operation
86+
integer(ilp), intent(out) :: lwork
87+
!> State return flag. Returns an error if the query failed
88+
type(linalg_state_type), optional, intent(out) :: err
89+
90+
integer(ilp) :: m,n,sdim,info
91+
character :: jobvs,sort
92+
logical(lk) :: bwork_dummy(1)
93+
${rt}$, pointer :: amat(:,:)
94+
real(${rk}$) :: rwork_dummy(1)
95+
${rt}$ :: wr_dummy(1),wi_dummy(1),vs_dummy(1,1),work_dummy(1)
96+
type(linalg_state_type) :: err0
97+
98+
!> Initialize problem
99+
lwork = -1_ilp
100+
m = size(a,1,kind=ilp)
101+
n = size(a,2,kind=ilp)
102+
103+
!> Create a dummy intent(inout) argument
104+
amat => a
105+
106+
!> Select dummy task
107+
jobvs = gees_vectors(.true.)
108+
sort = gees_sort_eigs(.false.)
109+
sdim = 0_ilp
110+
111+
!> Get Schur workspace
112+
call gees(jobvs,sort,do_not_select,n,amat,m,sdim,wr_dummy,#{if rt.startswith('r')}#wi_dummy, #{endif}#&
113+
vs_dummy,m,work_dummy,lwork,#{if rt.startswith('c')}#rwork_dummy,#{endif}#bwork_dummy,info)
114+
if (info==0) lwork = nint(real(work_dummy(1),kind=${rk}$),kind=ilp)
115+
call handle_gees_info(info,m,n,m,err0)
116+
call linalg_error_handling(err0,err)
117+
118+
contains
119+
120+
! Interface to dummy select routine
121+
pure logical(lk) function do_not_select(alpha#{if rt.startswith('r')}#r,alphai#{endif}#)
122+
${rt}$, intent(in) :: alpha#{if rt.startswith('r')}#r,alphai#{endif}#
123+
do_not_select = .false.
124+
end function do_not_select
125+
126+
end subroutine get_schur_${ri}$_workspace
81127

82128
! Schur decomposition subroutine
83129
pure module subroutine stdlib_linalg_${ri}$_schur(a, t, z, lwork, overwrite_a, sort, err)

0 commit comments

Comments
 (0)