1 #include "relapack.h"
2 
3 static void RELAPACK_slauum_rec(const char *, const blasint *, float *,
4     const blasint *, blasint *);
5 
6 
7 /** SLAUUM computes the product U * U**T or L**T * L, where the triangular factor U or L is stored in the upper or lower triangular part of the array A.
8  *
9  * This routine is functionally equivalent to LAPACK's slauum.
10  * For details on its interface, see
11  * http://www.netlib.org/lapack/explore-html/dd/d5a/slauum_8f.html
12  * */
RELAPACK_slauum(const char * uplo,const blasint * n,float * A,const blasint * ldA,blasint * info)13 void RELAPACK_slauum(
14     const char *uplo, const blasint *n,
15     float *A, const blasint *ldA,
16     blasint *info
17 ) {
18 
19     // Check arguments
20     const blasint lower = LAPACK(lsame)(uplo, "L");
21     const blasint upper = LAPACK(lsame)(uplo, "U");
22     *info = 0;
23     if (!lower && !upper)
24         *info = -1;
25     else if (*n < 0)
26         *info = -2;
27     else if (*ldA < MAX(1, *n))
28         *info = -4;
29     if (*info) {
30         const blasint minfo = -*info;
31         LAPACK(xerbla)("SLAUUM", &minfo, strlen("SLAUUM"));
32         return;
33     }
34 
35     // Clean char * arguments
36     const char cleanuplo = lower ? 'L' : 'U';
37 
38     // Recursive kernel
39     RELAPACK_slauum_rec(&cleanuplo, n, A, ldA, info);
40 }
41 
42 
43 /** slauum's recursive compute kernel */
RELAPACK_slauum_rec(const char * uplo,const blasint * n,float * A,const blasint * ldA,blasint * info)44 static void RELAPACK_slauum_rec(
45     const char *uplo, const blasint *n,
46     float *A, const blasint *ldA,
47     blasint *info
48 ) {
49 
50     if (*n <= MAX(CROSSOVER_SLAUUM, 1)) {
51         // Unblocked
52         LAPACK(slauu2)(uplo, n, A, ldA, info);
53         return;
54     }
55 
56     // Constants
57     const float ONE[] = { 1. };
58 
59     // Splitting
60     const blasint n1 = SREC_SPLIT(*n);
61     const blasint n2 = *n - n1;
62 
63     // A_TL A_TR
64     // A_BL A_BR
65     float *const A_TL = A;
66     float *const A_TR = A + *ldA * n1;
67     float *const A_BL = A             + n1;
68     float *const A_BR = A + *ldA * n1 + n1;
69 
70     // recursion(A_TL)
71     RELAPACK_slauum_rec(uplo, &n1, A_TL, ldA, info);
72 
73     if (*uplo == 'L') {
74         // A_TL = A_TL + A_BL' * A_BL
75         BLAS(ssyrk)("L", "T", &n1, &n2, ONE, A_BL, ldA, ONE, A_TL, ldA);
76         // A_BL = A_BR' * A_BL
77         BLAS(strmm)("L", "L", "T", "N", &n2, &n1, ONE, A_BR, ldA, A_BL, ldA);
78     } else {
79         // A_TL = A_TL + A_TR * A_TR'
80         BLAS(ssyrk)("U", "N", &n1, &n2, ONE, A_TR, ldA, ONE, A_TL, ldA);
81         // A_TR = A_TR * A_BR'
82         BLAS(strmm)("R", "U", "T", "N", &n1, &n2, ONE, A_BR, ldA, A_TR, ldA);
83     }
84 
85     // recursion(A_BR)
86     RELAPACK_slauum_rec(uplo, &n2, A_BR, ldA, info);
87 }
88