Skip to content

Follow up on pr1146 (v2)#1221

Merged
langou merged 8 commits intoReference-LAPACK:masterfrom
langou:origin/follow_up_on_PR1146
Mar 31, 2026
Merged

Follow up on pr1146 (v2)#1221
langou merged 8 commits intoReference-LAPACK:masterfrom
langou:origin/follow_up_on_PR1146

Conversation

@langou
Copy link
Copy Markdown
Contributor

@langou langou commented Mar 28, 2026

Follow up on PR #1146. ( Thanks to @yizeyi18 for the PR.)

While reviewing, @angsch suggested

Shouldn't jobu = 'f' and jobu = 'r' be included here too?

I implemented the suggestion. This ended being easier for me to do a substantial rewrite.

I followed the explanation at

lapack/SRC/cgesvdq.f

Lines 159 to 198 in 034ada1

*> \param[out] U
*> \verbatim
*> U is COMPLEX array, dimension
*> LDU x M if JOBU = 'A'; see the description of LDU. In this case,
*> on exit, U contains the M left singular vectors.
*> LDU x N if JOBU = 'S', 'U', 'R' ; see the description of LDU. In this
*> case, U contains the leading N or the leading NUMRANK left singular vectors.
*> LDU x N if JOBU = 'F' ; see the description of LDU. In this case U
*> contains N x N unitary matrix that can be used to form the left
*> singular vectors.
*> If JOBU = 'N', U is not referenced.
*> \endverbatim
*>
*> \param[in] LDU
*> \verbatim
*> LDU is INTEGER.
*> The leading dimension of the array U.
*> If JOBU = 'A', 'S', 'U', 'R', LDU >= max(1,M).
*> If JOBU = 'F', LDU >= max(1,N).
*> Otherwise, LDU >= 1.
*> \endverbatim
*>
*> \param[out] V
*> \verbatim
*> V is COMPLEX array, dimension
*> LDV x N if JOBV = 'A', 'V', 'R' or if JOBA = 'E' .
*> If JOBV = 'A', or 'V', V contains the N-by-N unitary matrix V**H;
*> If JOBV = 'R', V contains the first NUMRANK rows of V**H (the right
*> singular vectors, stored rowwise, of the NUMRANK largest singular values).
*> If JOBV = 'N' and JOBA = 'E', V is used as a workspace.
*> If JOBV = 'N', and JOBA.NE.'E', V is not referenced.
*> \endverbatim
*>
*> \param[in] LDV
*> \verbatim
*> LDV is INTEGER
*> The leading dimension of the array V.
*> If JOBV = 'A', 'V', 'R', or JOBA = 'E', LDV >= max(1,N).
*> Otherwise, LDV >= 1.
*> \endverbatim

@langou langou mentioned this pull request Mar 28, 2026
mgates3
mgates3 previously approved these changes Mar 31, 2026
Copy link
Copy Markdown
Collaborator

@mgates3 mgates3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. Maybe a couple things could be improved later on.

API_SUFFIX(LAPACKE_lsame)( jobv, 'r' ) ) {
LAPACKE_free( v_t );
}
if ( ( m > 0 ) && ( n > 0 ) ) LAPACKE_free( v_t );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but since free( NULL ) does nothing, it would be simpler to have just one exit level and free all the pointers:

exit_level_0:
    LAPACKE_free( v_t );  v_t = NULL;
    LAPACKE_free( u_t );  u_t = NULL;
    LAPACKE_free( a_t );  a_t = NULL;

I tend to reset pointers to NULL after freeing them, to avoid any possible confusion.

If desired, perhaps that can be a future simplification of all of LAPACKE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am slowing down on that, so, as you suggest: "could be improved later on." So, if we get there, for sure, let us do a separate pull request.

I do like the idea to reset pointers to NULL after freeing them, to avoid any possible confusion.

Here is why I am slowing down: While free(NULL) does nothing, is it true that LAPACKE_free( NULL ) does nothing? What do we ask LAPACKE_free() to do? This proposed change would implicitly state that we require LAPACKE_free( NULL ) to do nothing.

I like the logic "if you fail to allocate at level 2, then do not forget to free level 0 and level 1 that were previously allocated." I feel it could be useful in some context, but maybe not for a C wrapper.

So all in all, are there more opinions about what @mgates3 suggest? In favor? Against?

…workspace would be helpful. (Per later comment when transposing results.)"
…freeing them, to avoid any possible confusion."
@langou langou merged commit 774b05d into Reference-LAPACK:master Mar 31, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants