Skip to content

Commit c9b6714

Browse files
authored
Add early returns
1 parent 6797a3a commit c9b6714

File tree

10 files changed

+36
-18
lines changed

10 files changed

+36
-18
lines changed

relapack/src/dgetrf.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ void RELAPACK_dgetrf(
2929
return;
3030
}
3131

32-
const blasint sn = MIN(*m, *n);
32+
if (*m == 0 || *n == 0) return;
3333

34+
const blasint sn = MIN(*m, *n);
3435
RELAPACK_dgetrf_rec(m, &sn, A, ldA, ipiv, info);
3536

3637
// Right remainder
3738
if (*m < *n) {
3839
// Constants
3940
const double ONE[] = { 1. };
40-
const blasint iONE[] = { 1. };
41+
const blasint iONE[] = { 1 };
4142

4243
// Splitting
4344
const blasint rn = *n - *m;
@@ -60,13 +61,11 @@ static void RELAPACK_dgetrf_rec(
6061
double *A, const blasint *ldA, blasint *ipiv,
6162
blasint *info
6263
) {
63-
64-
if (*n <= MAX(CROSSOVER_DGETRF, 1)) {
64+
if ( *n <= MAX(CROSSOVER_DGETRF, 1)) {
6565
// Unblocked
66-
LAPACK(dgetf2)(m, n, A, ldA, ipiv, info);
66+
LAPACK(dgetrf2)(m, n, A, ldA, ipiv, info);
6767
return;
6868
}
69-
7069
// Constants
7170
const double ONE[] = { 1. };
7271
const double MONE[] = { -1. };
@@ -95,6 +94,7 @@ static void RELAPACK_dgetrf_rec(
9594

9695
// recursion(A_L, ipiv_T)
9796
RELAPACK_dgetrf_rec(m, &n1, A_L, ldA, ipiv_T, info);
97+
if (*info) return;
9898
// apply pivots to A_R
9999
LAPACK(dlaswp)(&n2, A_R, ldA, iONE, &n1, ipiv_T, iONE);
100100

relapack/src/dsytrf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RELAPACK_dsytrf(
3636
*info = -2;
3737
else if (*ldA < MAX(1, *n))
3838
*info = -4;
39-
else if (*lWork < minlWork && *lWork != -1)
39+
else if ((*lWork < 1 || *lWork < minlWork) && *lWork != -1)
4040
*info = -7;
4141
else if (*lWork == -1) {
4242
// Work size query
@@ -67,6 +67,7 @@ void RELAPACK_dsytrf(
6767
blasint nout;
6868

6969
// Recursive kernel
70+
if (*n != 0)
7071
RELAPACK_dsytrf_rec(&cleanuplo, n, n, &nout, A, ldA, ipiv, cleanWork, n, info);
7172

7273
#if XSYTRF_ALLOW_MALLOC

relapack/src/dsytrf_rook.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RELAPACK_dsytrf_rook(
3636
*info = -2;
3737
else if (*ldA < MAX(1, *n))
3838
*info = -4;
39-
else if (*lWork < minlWork && *lWork != -1)
39+
else if ((*lWork <1 || *lWork < minlWork) && *lWork != -1)
4040
*info = -7;
4141
else if (*lWork == -1) {
4242
// Work size query
@@ -56,7 +56,7 @@ void RELAPACK_dsytrf_rook(
5656

5757
if (*info) {
5858
const blasint minfo = -*info;
59-
LAPACK(xerbla)("DSYTRF", &minfo, strlen("DSYTRF"));
59+
LAPACK(xerbla)("DSYTRF_ROOK", &minfo, strlen("DSYTRF_ROOK"));
6060
return;
6161
}
6262

relapack/src/dtrsyl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ void RELAPACK_dtrsyl(
4949
return;
5050
}
5151

52+
if (*m == 0 || *n == 0) {
53+
*scale = 1.;
54+
return;
55+
}
56+
5257
// Clean char * arguments
5358
const char cleantranA = notransA ? 'N' : (transA ? 'T' : 'C');
5459
const char cleantranB = notransB ? 'N' : (transB ? 'T' : 'C');

relapack/src/zgetrf.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void RELAPACK_zgetrf(
3030
return;
3131
}
3232

33+
if (*m == 0 || *n == 0) return;
3334
const blasint sn = MIN(*m, *n);
3435

3536
RELAPACK_zgetrf_rec(m, &sn, A, ldA, ipiv, info);
@@ -62,9 +63,11 @@ static void RELAPACK_zgetrf_rec(
6263
blasint *info
6364
) {
6465

65-
if (*n <= MAX(CROSSOVER_ZGETRF, 1)) {
66+
if (*m == 0 || *n == 0) return;
67+
68+
if ( *n <= MAX(CROSSOVER_ZGETRF, 1)) {
6669
// Unblocked
67-
LAPACK(zgetf2)(m, n, A, ldA, ipiv, info);
70+
LAPACK(zgetrf2)(m, n, A, ldA, ipiv, info);
6871
return;
6972
}
7073

@@ -96,6 +99,8 @@ static void RELAPACK_zgetrf_rec(
9699

97100
// recursion(A_L, ipiv_T)
98101
RELAPACK_zgetrf_rec(m, &n1, A_L, ldA, ipiv_T, info);
102+
if (*info) return;
103+
99104
// apply pivots to A_R
100105
LAPACK(zlaswp)(&n2, A_R, ldA, iONE, &n1, ipiv_T, iONE);
101106

relapack/src/zhetrf_rook.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RELAPACK_zhetrf_rook(
3636
*info = -2;
3737
else if (*ldA < MAX(1, *n))
3838
*info = -4;
39-
else if (*lWork < minlWork && *lWork != -1)
39+
else if ((*lWork < 1 || *lWork < minlWork) && *lWork != -1)
4040
*info = -7;
4141
else if (*lWork == -1) {
4242
// Work size query
@@ -56,7 +56,7 @@ void RELAPACK_zhetrf_rook(
5656

5757
if (*info) {
5858
const blasint minfo = -*info;
59-
LAPACK(xerbla)("ZHETRF", &minfo, strlen("ZHETRF"));
59+
LAPACK(xerbla)("ZHETRF_ROOK", &minfo, strlen("ZHETRF_ROOK"));
6060
return;
6161
}
6262

relapack/src/zsytrf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RELAPACK_zsytrf(
3636
*info = -2;
3737
else if (*ldA < MAX(1, *n))
3838
*info = -4;
39-
else if (*lWork < minlWork && *lWork != -1)
39+
else if ((*lWork < 1 || *lWork < minlWork) && *lWork != -1)
4040
*info = -7;
4141
else if (*lWork == -1) {
4242
// Work size query
@@ -67,6 +67,7 @@ void RELAPACK_zsytrf(
6767
blasint nout;
6868

6969
// Recursive kernel
70+
if (*n != 0)
7071
RELAPACK_zsytrf_rec(&cleanuplo, n, n, &nout, A, ldA, ipiv, cleanWork, n, info);
7172

7273
#if XSYTRF_ALLOW_MALLOC

relapack/src/zsytrf_rook.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RELAPACK_zsytrf_rook(
3636
*info = -2;
3737
else if (*ldA < MAX(1, *n))
3838
*info = -4;
39-
else if (*lWork < minlWork && *lWork != -1)
39+
else if ((*lWork < 1 || *lWork < minlWork) && *lWork != -1)
4040
*info = -7;
4141
else if (*lWork == -1) {
4242
// Work size query
@@ -56,7 +56,7 @@ void RELAPACK_zsytrf_rook(
5656

5757
if (*info) {
5858
const blasint minfo = -*info;
59-
LAPACK(xerbla)("ZSYTRF", &minfo, strlen("ZSYTRF"));
59+
LAPACK(xerbla)("ZSYTRF_ROOK", &minfo, strlen("ZSYTRF_ROOK"));
6060
return;
6161
}
6262

@@ -67,6 +67,7 @@ void RELAPACK_zsytrf_rook(
6767
blasint nout;
6868

6969
// Recursive kernel
70+
if (*n != 0)
7071
RELAPACK_zsytrf_rook_rec(&cleanuplo, n, n, &nout, A, ldA, ipiv, cleanWork, n, info);
7172

7273
#if XSYTRF_ALLOW_MALLOC

relapack/src/ztrsyl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ void RELAPACK_ztrsyl(
4747
return;
4848
}
4949

50+
if (*m == 0 || *n == 0) {
51+
*scale = 1.;
52+
return;
53+
}
54+
5055
// Clean char * arguments
5156
const char cleantranA = notransA ? 'N' : 'C';
5257
const char cleantranB = notransB ? 'N' : 'C';

relapack/src/ztrtri.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static void RELAPACK_ztrtri_rec(
6969
}
7070

7171
// Constants
72-
const double ONE[] = { 1. };
73-
const double MONE[] = { -1. };
72+
const double ONE[] = { 1., 0. };
73+
const double MONE[] = { -1. , 0. };
7474

7575
// Splitting
7676
const blasint n1 = ZREC_SPLIT(*n);

0 commit comments

Comments
 (0)