00001 /* Ergo, version 3.7, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, 00004 * and Anastasia Kruchinina. 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 * 00019 * Primary academic reference: 00020 * Ergo: An open-source program for linear-scaling electronic structure 00021 * calculations, 00022 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia 00023 * Kruchinina, 00024 * SoftwareX 7, 107 (2018), 00025 * <http://dx.doi.org/10.1016/j.softx.2018.03.005> 00026 * 00027 * For further information about Ergo, see <http://www.ergoscf.org>. 00028 */ 00029 00030 /* This file belongs to the template_lapack part of the Ergo source 00031 * code. The source files in the template_lapack directory are modified 00032 * versions of files originally distributed as CLAPACK, see the 00033 * Copyright/license notice in the file template_lapack/COPYING. 00034 */ 00035 00036 00037 #ifndef TEMPLATE_LAPACK_TPTRI_HEADER 00038 #define TEMPLATE_LAPACK_TPTRI_HEADER 00039 00040 #include "template_lapack_common.h" 00041 00042 template<class Treal> 00043 int template_lapack_tptri(const char *uplo, const char *diag, const integer *n, Treal * 00044 ap, integer *info) 00045 { 00046 /* -- LAPACK routine (version 3.0) -- 00047 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00048 Courant Institute, Argonne National Lab, and Rice University 00049 September 30, 1994 00050 00051 00052 Purpose 00053 ======= 00054 00055 DTPTRI computes the inverse of a real upper or lower triangular 00056 matrix A stored in packed format. 00057 00058 Arguments 00059 ========= 00060 00061 UPLO (input) CHARACTER*1 00062 = 'U': A is upper triangular; 00063 = 'L': A is lower triangular. 00064 00065 DIAG (input) CHARACTER*1 00066 = 'N': A is non-unit triangular; 00067 = 'U': A is unit triangular. 00068 00069 N (input) INTEGER 00070 The order of the matrix A. N >= 0. 00071 00072 AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) 00073 On entry, the upper or lower triangular matrix A, stored 00074 columnwise in a linear array. The j-th column of A is stored 00075 in the array AP as follows: 00076 if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; 00077 if UPLO = 'L', AP(i + (j-1)*((2*n-j)/2) = A(i,j) for j<=i<=n. 00078 See below for further details. 00079 On exit, the (triangular) inverse of the original matrix, in 00080 the same packed storage format. 00081 00082 INFO (output) INTEGER 00083 = 0: successful exit 00084 < 0: if INFO = -i, the i-th argument had an illegal value 00085 > 0: if INFO = i, A(i,i) is exactly zero. The triangular 00086 matrix is singular and its inverse can not be computed. 00087 00088 Further Details 00089 =============== 00090 00091 A triangular matrix A can be transferred to packed storage using one 00092 of the following program segments: 00093 00094 UPLO = 'U': UPLO = 'L': 00095 00096 JC = 1 JC = 1 00097 DO 2 J = 1, N DO 2 J = 1, N 00098 DO 1 I = 1, J DO 1 I = J, N 00099 AP(JC+I-1) = A(I,J) AP(JC+I-J) = A(I,J) 00100 1 CONTINUE 1 CONTINUE 00101 JC = JC + J JC = JC + N - J + 1 00102 2 CONTINUE 2 CONTINUE 00103 00104 ===================================================================== 00105 00106 00107 Test the input parameters. 00108 00109 Parameter adjustments */ 00110 /* Table of constant values */ 00111 integer c__1 = 1; 00112 00113 /* System generated locals */ 00114 integer i__1, i__2; 00115 /* Local variables */ 00116 integer j; 00117 logical upper; 00118 integer jc, jj; 00119 integer jclast; 00120 logical nounit; 00121 Treal ajj; 00122 00123 00124 --ap; 00125 00126 /* Initialization added by Elias to get rid of compiler warnings. */ 00127 jclast = 0; 00128 /* Function Body */ 00129 *info = 0; 00130 upper = template_blas_lsame(uplo, "U"); 00131 nounit = template_blas_lsame(diag, "N"); 00132 if (! upper && ! template_blas_lsame(uplo, "L")) { 00133 *info = -1; 00134 } else if (! nounit && ! template_blas_lsame(diag, "U")) { 00135 *info = -2; 00136 } else if (*n < 0) { 00137 *info = -3; 00138 } 00139 if (*info != 0) { 00140 i__1 = -(*info); 00141 template_blas_erbla("TPTRI ", &i__1); 00142 return 0; 00143 } 00144 00145 /* Check for singularity if non-unit. */ 00146 00147 if (nounit) { 00148 if (upper) { 00149 jj = 0; 00150 i__1 = *n; 00151 for (*info = 1; *info <= i__1; ++(*info)) { 00152 jj += *info; 00153 if (ap[jj] == 0.) { 00154 return 0; 00155 } 00156 /* L10: */ 00157 } 00158 } else { 00159 jj = 1; 00160 i__1 = *n; 00161 for (*info = 1; *info <= i__1; ++(*info)) { 00162 if (ap[jj] == 0.) { 00163 return 0; 00164 } 00165 jj = jj + *n - *info + 1; 00166 /* L20: */ 00167 } 00168 } 00169 *info = 0; 00170 } 00171 00172 if (upper) { 00173 00174 /* Compute inverse of upper triangular matrix. */ 00175 00176 jc = 1; 00177 i__1 = *n; 00178 for (j = 1; j <= i__1; ++j) { 00179 if (nounit) { 00180 ap[jc + j - 1] = 1. / ap[jc + j - 1]; 00181 ajj = -ap[jc + j - 1]; 00182 } else { 00183 ajj = -1.; 00184 } 00185 00186 /* Compute elements 1:j-1 of j-th column. */ 00187 00188 i__2 = j - 1; 00189 template_blas_tpmv("Upper", "No transpose", diag, &i__2, &ap[1], &ap[jc], & 00190 c__1); 00191 i__2 = j - 1; 00192 template_blas_scal(&i__2, &ajj, &ap[jc], &c__1); 00193 jc += j; 00194 /* L30: */ 00195 } 00196 00197 } else { 00198 00199 /* Compute inverse of lower triangular matrix. */ 00200 00201 jc = *n * (*n + 1) / 2; 00202 for (j = *n; j >= 1; --j) { 00203 if (nounit) { 00204 ap[jc] = 1. / ap[jc]; 00205 ajj = -ap[jc]; 00206 } else { 00207 ajj = -1.; 00208 } 00209 if (j < *n) { 00210 00211 /* Compute elements j+1:n of j-th column. */ 00212 00213 i__1 = *n - j; 00214 template_blas_tpmv("Lower", "No transpose", diag, &i__1, &ap[jclast], &ap[ 00215 jc + 1], &c__1); 00216 i__1 = *n - j; 00217 template_blas_scal(&i__1, &ajj, &ap[jc + 1], &c__1); 00218 } 00219 jclast = jc; 00220 jc = jc - *n + j - 2; 00221 /* L40: */ 00222 } 00223 } 00224 00225 return 0; 00226 00227 /* End of DTPTRI */ 00228 00229 } /* dtptri_ */ 00230 00231 #endif