Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / strtri.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6 static integer c_n1 = -1;
7 static integer c__2 = 2;
8 static real c_b18 = 1.f;
9 static real c_b22 = -1.f;
10
11 /* Subroutine */ int strtri_(char *uplo, char *diag, integer *n, real *a, 
12         integer *lda, integer *info)
13 {
14     /* System generated locals */
15     address a__1[2];
16     integer a_dim1, a_offset, i__1, i__2[2], i__3, i__4, i__5;
17     char ch__1[2];
18
19     /* Builtin functions */
20     /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
21
22     /* Local variables */
23     integer j, jb, nb, nn;
24     extern logical lsame_(char *, char *);
25     logical upper;
26     extern /* Subroutine */ int strmm_(char *, char *, char *, char *, 
27             integer *, integer *, real *, real *, integer *, real *, integer *
28 ), strsm_(char *, char *, char *, 
29             char *, integer *, integer *, real *, real *, integer *, real *, 
30             integer *), strti2_(char *, char *
31 , integer *, real *, integer *, integer *), 
32             xerbla_(char *, integer *);
33     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
34             integer *, integer *);
35     logical nounit;
36
37
38 /*  -- LAPACK routine (version 3.1) -- */
39 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
40 /*     November 2006 */
41
42 /*     .. Scalar Arguments .. */
43 /*     .. */
44 /*     .. Array Arguments .. */
45 /*     .. */
46
47 /*  Purpose */
48 /*  ======= */
49
50 /*  STRTRI computes the inverse of a real upper or lower triangular */
51 /*  matrix A. */
52
53 /*  This is the Level 3 BLAS version of the algorithm. */
54
55 /*  Arguments */
56 /*  ========= */
57
58 /*  UPLO    (input) CHARACTER*1 */
59 /*          = 'U':  A is upper triangular; */
60 /*          = 'L':  A is lower triangular. */
61
62 /*  DIAG    (input) CHARACTER*1 */
63 /*          = 'N':  A is non-unit triangular; */
64 /*          = 'U':  A is unit triangular. */
65
66 /*  N       (input) INTEGER */
67 /*          The order of the matrix A.  N >= 0. */
68
69 /*  A       (input/output) REAL array, dimension (LDA,N) */
70 /*          On entry, the triangular matrix A.  If UPLO = 'U', the */
71 /*          leading N-by-N upper triangular part of the array A contains */
72 /*          the upper triangular matrix, and the strictly lower */
73 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
74 /*          leading N-by-N lower triangular part of the array A contains */
75 /*          the lower triangular matrix, and the strictly upper */
76 /*          triangular part of A is not referenced.  If DIAG = 'U', the */
77 /*          diagonal elements of A are also not referenced and are */
78 /*          assumed to be 1. */
79 /*          On exit, the (triangular) inverse of the original matrix, in */
80 /*          the same storage format. */
81
82 /*  LDA     (input) INTEGER */
83 /*          The leading dimension of the array A.  LDA >= max(1,N). */
84
85 /*  INFO    (output) INTEGER */
86 /*          = 0: successful exit */
87 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
88 /*          > 0: if INFO = i, A(i,i) is exactly zero.  The triangular */
89 /*               matrix is singular and its inverse can not be computed. */
90
91 /*  ===================================================================== */
92
93 /*     .. Parameters .. */
94 /*     .. */
95 /*     .. Local Scalars .. */
96 /*     .. */
97 /*     .. External Functions .. */
98 /*     .. */
99 /*     .. External Subroutines .. */
100 /*     .. */
101 /*     .. Intrinsic Functions .. */
102 /*     .. */
103 /*     .. Executable Statements .. */
104
105 /*     Test the input parameters. */
106
107     /* Parameter adjustments */
108     a_dim1 = *lda;
109     a_offset = 1 + a_dim1;
110     a -= a_offset;
111
112     /* Function Body */
113     *info = 0;
114     upper = lsame_(uplo, "U");
115     nounit = lsame_(diag, "N");
116     if (! upper && ! lsame_(uplo, "L")) {
117         *info = -1;
118     } else if (! nounit && ! lsame_(diag, "U")) {
119         *info = -2;
120     } else if (*n < 0) {
121         *info = -3;
122     } else if (*lda < max(1,*n)) {
123         *info = -5;
124     }
125     if (*info != 0) {
126         i__1 = -(*info);
127         xerbla_("STRTRI", &i__1);
128         return 0;
129     }
130
131 /*     Quick return if possible */
132
133     if (*n == 0) {
134         return 0;
135     }
136
137 /*     Check for singularity if non-unit. */
138
139     if (nounit) {
140         i__1 = *n;
141         for (*info = 1; *info <= i__1; ++(*info)) {
142             if (a[*info + *info * a_dim1] == 0.f) {
143                 return 0;
144             }
145 /* L10: */
146         }
147         *info = 0;
148     }
149
150 /*     Determine the block size for this environment. */
151
152 /* Writing concatenation */
153     i__2[0] = 1, a__1[0] = uplo;
154     i__2[1] = 1, a__1[1] = diag;
155     s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2);
156     nb = ilaenv_(&c__1, "STRTRI", ch__1, n, &c_n1, &c_n1, &c_n1);
157     if (nb <= 1 || nb >= *n) {
158
159 /*        Use unblocked code */
160
161         strti2_(uplo, diag, n, &a[a_offset], lda, info);
162     } else {
163
164 /*        Use blocked code */
165
166         if (upper) {
167
168 /*           Compute inverse of upper triangular matrix */
169
170             i__1 = *n;
171             i__3 = nb;
172             for (j = 1; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
173 /* Computing MIN */
174                 i__4 = nb, i__5 = *n - j + 1;
175                 jb = min(i__4,i__5);
176
177 /*              Compute rows 1:j-1 of current block column */
178
179                 i__4 = j - 1;
180                 strmm_("Left", "Upper", "No transpose", diag, &i__4, &jb, &
181                         c_b18, &a[a_offset], lda, &a[j * a_dim1 + 1], lda);
182                 i__4 = j - 1;
183                 strsm_("Right", "Upper", "No transpose", diag, &i__4, &jb, &
184                         c_b22, &a[j + j * a_dim1], lda, &a[j * a_dim1 + 1], 
185                         lda);
186
187 /*              Compute inverse of current diagonal block */
188
189                 strti2_("Upper", diag, &jb, &a[j + j * a_dim1], lda, info);
190 /* L20: */
191             }
192         } else {
193
194 /*           Compute inverse of lower triangular matrix */
195
196             nn = (*n - 1) / nb * nb + 1;
197             i__3 = -nb;
198             for (j = nn; i__3 < 0 ? j >= 1 : j <= 1; j += i__3) {
199 /* Computing MIN */
200                 i__1 = nb, i__4 = *n - j + 1;
201                 jb = min(i__1,i__4);
202                 if (j + jb <= *n) {
203
204 /*                 Compute rows j+jb:n of current block column */
205
206                     i__1 = *n - j - jb + 1;
207                     strmm_("Left", "Lower", "No transpose", diag, &i__1, &jb, 
208                             &c_b18, &a[j + jb + (j + jb) * a_dim1], lda, &a[j 
209                             + jb + j * a_dim1], lda);
210                     i__1 = *n - j - jb + 1;
211                     strsm_("Right", "Lower", "No transpose", diag, &i__1, &jb, 
212                              &c_b22, &a[j + j * a_dim1], lda, &a[j + jb + j * 
213                             a_dim1], lda);
214                 }
215
216 /*              Compute inverse of current diagonal block */
217
218                 strti2_("Lower", diag, &jb, &a[j + j * a_dim1], lda, info);
219 /* L30: */
220             }
221         }
222     }
223
224     return 0;
225
226 /*     End of STRTRI */
227
228 } /* strtri_ */