@@ -30,7 +30,7 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
3030 ! Maximum size of the subproblems at the bottom of the computation (~25)
3131 smlsiz = stdlib_ilaenv(9,'${ri}$gelsd',' ',0,0,0,0)
3232
33- ! The exact minimum amount of workspace needed depends on M, N and NRHS. As long as LWORK is at least
33+ ! The exact minimum amount of workspace needed depends on M, N and NRHS.
3434 nlvl = max(0, ilog2(mnmin/(smlsiz+1))+1)
3535
3636 ! Real space
@@ -47,7 +47,8 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
4747 ! Integer space
4848 liwork = max(1, 3*mnmin*nlvl+11*mnmin)
4949
50- ! For good performance, the workspace should generally be larger.
50+ ! For good performance, the workspace should generally be larger.
51+ ! Allocate 25% more space than strictly needed.
5152 lrwork = ceiling(1.25*lrwork,kind=ilp)
5253 lcwork = ceiling(1.25*lcwork,kind=ilp)
5354 liwork = ceiling(1.25*liwork,kind=ilp)
@@ -117,8 +118,8 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
117118 err0 = linalg_state_type(this,LINALG_VALUE_ERROR,'invalid sizes: a=',[lda,n], &
118119 'b=',[ldb,nrhs])
119120 allocate(x${nde}$)
120- arank = 0
121- goto 1
121+ call linalg_error_handling(err0,err)
122+ if (present(rank)) rank = 0
122123 end if
123124
124125 ! Can A be overwritten? By default, do not overwrite
@@ -182,10 +183,10 @@ submodule (stdlib_linalg) stdlib_linalg_least_squares
182183 err0 = linalg_state_type(this,LINALG_INTERNAL_ERROR,'catastrophic error')
183184 end select
184185
185- if (.not. copy_a) deallocate(amat)
186+ if (copy_a) deallocate(amat)
186187
187188 ! Process output and return
188- 1 call linalg_error_handling(err0,err)
189+ call linalg_error_handling(err0,err)
189190 if (present(rank)) rank = arank
190191
191192 end function stdlib_linalg_${ri}$_lstsq_${ndsuf}$
0 commit comments