Skip to content

NaN check in LAPACKE_?lantr isn't correct for m != n #737

@ACSimon33

Description

@ACSimon33

Description

The NaN check in LAPACKE_?lantr isn't checking the entire matrix for non-square matrices. The check is implemented like this:

if( LAPACKE_ztr_nancheck( matrix_layout, uplo, diag, MIN(m,n), a, lda ) ) {
    return -7;
}

There are two solutions to this. Either we add another check for the part which isn't checked - that could look like this for example:

if( LAPACKE_ztr_nancheck( matrix_layout, uplo, diag, MIN(m,n), a, lda ) ) {
    return -7;
}
if( LAPACKE_lsame( uplo, 'u' ) && n > m) {
    lapack_int offset = m * ((matrix_layout == LAPACK_COL_MAJOR) ? lda : 1);
    if( LAPACKE_zge_nancheck( matrix_layout, m, n - m, &a[offset], lda ) ) {
        return -7;
    }
}
if( LAPACKE_lsame( uplo, 'l' ) && m > n) {
    lapack_int offset = n * ((matrix_layout == LAPACK_ROW_MAJOR) ? lda : 1);
    if( LAPACKE_zge_nancheck( matrix_layout, m - n, n, &a[offset], lda ) ) {
        return -7;
    }
}

The cleaner solution in my opinion would be to change LAPACKE_?tr_nancheck to accept non-square matrices. That should be fairly simple by just adding a second size parameter and adjusting the loops. The NaN check in LAPACKE_zlarfb would benefit from this as well since there we have the same problem (which is already addressed via the first strategy).

The only downside of changing LAPACKE_?tr_nancheck is that there would be a lot of files that need fixes due to the interface change (64 files).

I'd like to know which strategy you would prefer.

Checklist

  • I'd be willing to make a PR to solve this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions