From 5ffbe646e12fe76682410674f5de4146c87aa973 Mon Sep 17 00:00:00 2001 From: Angelika Schwarz <17718454+angsch@users.noreply.github.com> Date: Sat, 11 Nov 2023 09:19:48 +0100 Subject: [PATCH] Improve matcopy interface * rows = 0 or cols = 0 is now a legal input and takes quick return path * Follow BLAS/LAPACK convention that the leading dimensions must be at least 1. --- interface/imatcopy.c | 22 ++++++++++++---------- interface/omatcopy.c | 22 ++++++++++++---------- interface/zimatcopy.c | 30 ++++++++++++++++-------------- interface/zomatcopy.c | 30 ++++++++++++++++-------------- 4 files changed, 56 insertions(+), 48 deletions(-) diff --git a/interface/imatcopy.c b/interface/imatcopy.c index 4cf0966cc8..6a1ad282c0 100644 --- a/interface/imatcopy.c +++ b/interface/imatcopy.c @@ -100,27 +100,29 @@ void CNAME( enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, if ( order == BlasColMajor) { - if ( trans == BlasNoTrans && *ldb < *rows ) info = 8; - if ( trans == BlasTrans && *ldb < *cols ) info = 8; + if ( trans == BlasNoTrans && *ldb < MAX(1,*rows) ) info = 8; + if ( trans == BlasTrans && *ldb < MAX(1,*cols) ) info = 8; } if ( order == BlasRowMajor) { - if ( trans == BlasNoTrans && *ldb < *cols ) info = 8; - if ( trans == BlasTrans && *ldb < *rows ) info = 8; + if ( trans == BlasNoTrans && *ldb < MAX(1,*cols) ) info = 8; + if ( trans == BlasTrans && *ldb < MAX(1,*rows) ) info = 8; } - if ( order == BlasColMajor && *lda < *rows ) info = 7; - if ( order == BlasRowMajor && *lda < *cols ) info = 7; - if ( *cols <= 0 ) info = 4; - if ( *rows <= 0 ) info = 3; - if ( trans < 0 ) info = 2; - if ( order < 0 ) info = 1; + if ( order == BlasColMajor && *lda < MAX(1,*rows) ) info = 7; + if ( order == BlasRowMajor && *lda < MAX(1,*cols) ) info = 7; + if ( *cols < 0 ) info = 4; + if ( *rows < 0 ) info = 3; + if ( trans < 0 ) info = 2; + if ( order < 0 ) info = 1; if (info >= 0) { BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME)); return; } + if ((*rows == 0) || (*cols == 0)) return; + #ifdef NEW_IMATCOPY if ( *lda == *ldb ) { if ( order == BlasColMajor ) diff --git a/interface/omatcopy.c b/interface/omatcopy.c index 59650cfa09..c26446f5c0 100644 --- a/interface/omatcopy.c +++ b/interface/omatcopy.c @@ -90,27 +90,29 @@ void CNAME(enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, #endif if ( order == BlasColMajor) { - if ( trans == BlasNoTrans && *ldb < *rows ) info = 9; - if ( trans == BlasTrans && *ldb < *cols ) info = 9; + if ( trans == BlasNoTrans && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasTrans && *ldb < MAX(1,*cols) ) info = 9; } if ( order == BlasRowMajor) { - if ( trans == BlasNoTrans && *ldb < *cols ) info = 9; - if ( trans == BlasTrans && *ldb < *rows ) info = 9; + if ( trans == BlasNoTrans && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasTrans && *ldb < MAX(1,*rows) ) info = 9; } - if ( order == BlasColMajor && *lda < *rows ) info = 7; - if ( order == BlasRowMajor && *lda < *cols ) info = 7; - if ( *cols <= 0 ) info = 4; - if ( *rows <= 0 ) info = 3; - if ( trans < 0 ) info = 2; - if ( order < 0 ) info = 1; + if ( order == BlasColMajor && *lda < MAX(1,*rows) ) info = 7; + if ( order == BlasRowMajor && *lda < MAX(1,*cols) ) info = 7; + if ( *cols < 0 ) info = 4; + if ( *rows < 0 ) info = 3; + if ( trans < 0 ) info = 2; + if ( order < 0 ) info = 1; if (info >= 0) { BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME)); return; } + if ((*rows == 0) || (*cols == 0)) return; + if ( order == BlasColMajor ) { if ( trans == BlasNoTrans ) diff --git a/interface/zimatcopy.c b/interface/zimatcopy.c index b0b32dc87b..b66489eb72 100644 --- a/interface/zimatcopy.c +++ b/interface/zimatcopy.c @@ -101,31 +101,33 @@ void CNAME( enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, if ( order == BlasColMajor) { - if ( trans == BlasNoTrans && *ldb < *rows ) info = 9; - if ( trans == BlasConj && *ldb < *rows ) info = 9; - if ( trans == BlasTrans && *ldb < *cols ) info = 9; - if ( trans == BlasTransConj && *ldb < *cols ) info = 9; + if ( trans == BlasNoTrans && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasConj && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasTrans && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasTransConj && *ldb < MAX(1,*cols) ) info = 9; } if ( order == BlasRowMajor) { - if ( trans == BlasNoTrans && *ldb < *cols ) info = 9; - if ( trans == BlasConj && *ldb < *cols ) info = 9; - if ( trans == BlasTrans && *ldb < *rows ) info = 9; - if ( trans == BlasTransConj && *ldb < *rows ) info = 9; + if ( trans == BlasNoTrans && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasConj && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasTrans && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasTransConj && *ldb < MAX(1,*rows) ) info = 9; } - if ( order == BlasColMajor && *lda < *rows ) info = 7; - if ( order == BlasRowMajor && *lda < *cols ) info = 7; - if ( *cols <= 0 ) info = 4; - if ( *rows <= 0 ) info = 3; - if ( trans < 0 ) info = 2; - if ( order < 0 ) info = 1; + if ( order == BlasColMajor && *lda < MAX(1,*rows) ) info = 7; + if ( order == BlasRowMajor && *lda < MAX(1,*cols) ) info = 7; + if ( *cols < 0 ) info = 4; + if ( *rows < 0 ) info = 3; + if ( trans < 0 ) info = 2; + if ( order < 0 ) info = 1; if (info >= 0) { BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME)); return; } + if ((*rows == 0) || (*cols == 0)) return; + #ifdef NEW_IMATCOPY if (*lda == *ldb ) { if ( order == BlasColMajor ) diff --git a/interface/zomatcopy.c b/interface/zomatcopy.c index 7345633a20..7121711d87 100644 --- a/interface/zomatcopy.c +++ b/interface/zomatcopy.c @@ -92,31 +92,33 @@ void CNAME(enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, #endif if ( order == BlasColMajor) { - if ( trans == BlasNoTrans && *ldb < *rows ) info = 9; - if ( trans == BlasConj && *ldb < *rows ) info = 9; - if ( trans == BlasTrans && *ldb < *cols ) info = 9; - if ( trans == BlasTransConj && *ldb < *cols ) info = 9; + if ( trans == BlasNoTrans && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasConj && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasTrans && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasTransConj && *ldb < MAX(1,*cols) ) info = 9; } if ( order == BlasRowMajor) { - if ( trans == BlasNoTrans && *ldb < *cols ) info = 9; - if ( trans == BlasConj && *ldb < *cols ) info = 9; - if ( trans == BlasTrans && *ldb < *rows ) info = 9; - if ( trans == BlasTransConj && *ldb < *rows ) info = 9; + if ( trans == BlasNoTrans && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasConj && *ldb < MAX(1,*cols) ) info = 9; + if ( trans == BlasTrans && *ldb < MAX(1,*rows) ) info = 9; + if ( trans == BlasTransConj && *ldb < MAX(1,*rows) ) info = 9; } - if ( order == BlasColMajor && *lda < *rows ) info = 7; - if ( order == BlasRowMajor && *lda < *cols ) info = 7; - if ( *cols <= 0 ) info = 4; - if ( *rows <= 0 ) info = 3; - if ( trans < 0 ) info = 2; - if ( order < 0 ) info = 1; + if ( order == BlasColMajor && *lda < MAX(1,*rows) ) info = 7; + if ( order == BlasRowMajor && *lda < MAX(1,*cols) ) info = 7; + if ( *cols < 0 ) info = 4; + if ( *rows < 0 ) info = 3; + if ( trans < 0 ) info = 2; + if ( order < 0 ) info = 1; if (info >= 0) { BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME)); return; } + if ((*rows == 0) || (*cols == 0)) return; + if ( order == BlasColMajor ) {