@@ -156,7 +156,7 @@ module stdlib_linalg_svd
156
156
157
157
if (.not.size(s,kind=ilp)>=k) then
158
158
err0 = linalg_state_type(this,LINALG_VALUE_ERROR,'singular value array has insufficient size:',&
159
- ' s=[',size (s,kind=ilp),'] , k=',k)
159
+ ' s=',shape (s,kind=ilp),', k=',k)
160
160
goto 1
161
161
endif
162
162
@@ -193,31 +193,37 @@ module stdlib_linalg_svd
193
193
194
194
! U, VT storage
195
195
if (present(u)) then
196
+ ! User input
196
197
umat => u
197
198
alloc_u = .false.
198
199
elseif ((copy_a .and. m>=n) .or. .not.compute_uv) then
199
200
! U not wanted, and A can be overwritten: do not allocate
200
201
umat => u_dummy
201
202
alloc_u = .false.
202
203
elseif (.not.full_storage) then
204
+ ! Allocate with minimum size
203
205
allocate(umat(m,k))
204
206
alloc_u = .true.
205
207
else
208
+ ! Allocate with regular size
206
209
allocate(umat(m,m))
207
210
alloc_u = .true.
208
211
end if
209
212
210
213
if (present(vt)) then
214
+ ! User input
211
215
vtmat => vt
212
216
alloc_vt = .false.
213
217
elseif ((copy_a .and. m<n) .or. .not.compute_uv) then
214
218
! amat can be overwritten, VT not wanted: VT is returned upon A
215
219
vtmat => vt_dummy
216
220
alloc_vt = .false.
217
221
elseif (.not.full_storage) then
222
+ ! Allocate with minimum size
218
223
allocate(vtmat(k,n))
219
224
alloc_vt = .true.
220
225
else
226
+ ! Allocate with regular size
221
227
allocate(vtmat(n,n))
222
228
alloc_vt = .true.
223
229
end if
@@ -245,10 +251,12 @@ module stdlib_linalg_svd
245
251
lrwork = max(1,5*k*(k+1),2*k*(k+max(m,n))+k)
246
252
endif
247
253
allocate(rwork(lrwork))
254
+ #:else
255
+ lrwork = -1_ilp ! not needed
248
256
#:endif
249
257
258
+ ! First call: request working storage space
250
259
lwork = -1_ilp
251
-
252
260
call gesdd(task,m,n,amat,lda,s,umat,ldu,vtmat,ldvt,&
253
261
work_dummy,lwork,#{if rt.startswith('complex')}#rwork,#{endif}#iwork,info)
254
262
call handle_gesdd_info(err0,info,m,n)
@@ -262,7 +270,7 @@ module stdlib_linalg_svd
262
270
263
271
!> Compute SVD
264
272
call gesdd(task,m,n,amat,lda,s,umat,ldu,vtmat,ldvt,&
265
- work,lwork,#{if rt.startswith('comp ')}#rwork,#{endif}#iwork,info)
273
+ work,lwork,#{if rt.startswith('complex ')}#rwork,#{endif}#iwork,info)
266
274
call handle_gesdd_info(err0,info,m,n)
267
275
268
276
endif
0 commit comments