Skip to content

Incorrect call to SLASET in schkst2stg.f #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serguei-patchkovskii opened this issue Aug 3, 2020 · 3 comments · Fixed by #438
Closed

Incorrect call to SLASET in schkst2stg.f #425

serguei-patchkovskii opened this issue Aug 3, 2020 · 3 comments · Fixed by #438
Milestone

Comments

@serguei-patchkovskii
Copy link

serguei-patchkovskii commented Aug 3, 2020

This appears to be related to #318 https://github.com/Reference-LAPACK/lapack/issues/318. The problem is not in SLASET but in the calling routine.

TESTING/EIG/schkst2stg.f contains the following code fragment (both in 3.9.0 and in the repo):

1000 * using the 1-stage.
1001 *
1002 CALL SLASET( 'Full', N, 1, ZERO, ZERO, SD, 1 )
1003 CALL SLASET( 'Full', N, 1, ZERO, ZERO, SE, 1 )
1004 CALL SLACPY( "U", N, N, A, LDA, V, LDU )
1005 LH = MAX(1, 4*N)
1006 LW = LWORK - LH

This code is incorrect, and causes a bounds violation in SLASET. The correct code is:

1002 CALL SLASET( 'Full', N, 1, ZERO, ZERO, SD, N )
1003 CALL SLASET( 'Full', N, 1, ZERO, ZERO, SE, N )

@serguei-patchkovskii
Copy link
Author

The same issue is present in TESTING/EIG/schksb2stg.f, around the line 673:

671 * using the SSBTRD.
672 *
673 CALL SLASET( 'Full', N, 1, ZERO, ZERO, SD, 1 )
674 CALL SLASET( 'Full', N, 1, ZERO, ZERO, SE, 1 )
675 CALL SLACPY( ' ', K+1, N, A, LDA, U, LDU )
676 LH = MAX(1, 4*N)
677 LW = LWORK - LH

The fix is the same.

@ereisch
Copy link

ereisch commented Feb 2, 2021

Actually, the fix isn't entirely correct either, since SLASET is expecting a single character for the first argument, and you're instead passing in a string.

@serguei-patchkovskii
Copy link
Author

Actually, the fix isn't entirely correct either, since SLASET is expecting a single character for the first argument, and you're instead passing in a string.

As a matter of Fortran pedantry, Fortran association rules explicitly allow passing a longer string of the default character kind, where the dummy argument is a shorter default-kind character type. This situation is covered by the clause 4 of the section 12.5.2.4 of Fortran 2008, ISO/IEC 1539:2010. (you can find an unofficial, believed accurate, copy of the standard at https://wg5-fortran.org/f2008.html).

Because 'Full' has type CHARACTER(LEN=4), it can be associated to a CHARACTER dummy argument in SLASET, and the code is standard-conformant.

Not that it really matters in the grand scheme of things.

@julielangou julielangou added this to the LAPACK 3.9.1 milestone Mar 25, 2021
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 a pull request may close this issue.

3 participants