846 static const G4int max_array = 25;
848 if (!xvec) xvec =
new std::vector<G4double> (max_array) ;
850 if (!pivv) pivv =
new std::vector<G4int> (max_array) ;
851 typedef std::vector<G4int>::iterator pivIter;
852 if (xvec->size() <
static_cast<unsigned int>(nrow)) xvec->resize(nrow);
853 if (pivv->size() <
static_cast<unsigned int>(nrow)) pivv->resize(nrow);
860 pivIter piv = pivv->begin();
873 for (i = 0; i < nrow; i++)
884 for (j=1; j < nrow; j+=ss)
886 mjj = m.begin() + j*(j-1)/2 + j-1;
889 ip = m.begin() + (j+1)*j/2 + j-1;
890 for (i=j+1; i <= nrow ; ip += i++)
892 if (std::fabs(*ip) >
lambda)
894 lambda = std::fabs(*ip);
910 if (std::fabs(*mjj) >= lambda*alpha)
918 ip = m.begin() + pivrow*(pivrow-1)/2+j-1;
919 for (k=j; k < pivrow; k++)
921 if (std::fabs(*ip) > sigma)
922 sigma = std::fabs(*ip);
925 if (sigma * std::fabs(*mjj) >= alpha * lambda *
lambda)
930 else if (std::fabs(*(m.begin()+pivrow*(pivrow-1)/2+pivrow-1))
944 temp2 = *mjj = 1./ *mjj;
947 for (i=j+1; i <= nrow; i++)
949 temp1 = *(m.begin() + i*(i-1)/2 + j-1) * temp2;
950 ip = m.begin()+i*(i-1)/2+j;
951 for (k=j+1; k<=i; k++)
953 *ip -= temp1 * *(m.begin() + k*(k-1)/2 + j-1);
954 if (std::fabs(*ip) <= epsilon)
960 ip = m.begin() + (j+1)*j/2 + j-1;
961 for (i=j+1; i <= nrow; ip += i++)
972 ip = m.begin() + pivrow*(pivrow-1)/2 + j;
973 for (i=j+1; i < pivrow; i++, ip++)
975 temp1 = *(m.begin() + i*(i-1)/2 + j-1);
976 *(m.begin() + i*(i-1)/2 + j-1)= *ip;
980 *mjj = *(m.begin()+pivrow*(pivrow-1)/2+pivrow-1);
981 *(m.begin()+pivrow*(pivrow-1)/2+pivrow-1) = temp1;
982 ip = m.begin() + (pivrow+1)*pivrow/2 + j-1;
984 for (i = pivrow+1; i <= nrow; ip += i, iq += i++)
996 temp2 = *mjj = 1./ *mjj;
999 for (i = j+1; i <= nrow; i++)
1001 temp1 = *(m.begin() + i*(i-1)/2 + j-1) * temp2;
1002 ip = m.begin()+i*(i-1)/2+j;
1003 for (k=j+1; k<=i; k++)
1005 *ip -= temp1 * *(m.begin() + k*(k-1)/2 + j-1);
1006 if (std::fabs(*ip) <= epsilon)
1012 ip = m.begin() + (j+1)*j/2 + j-1;
1013 for (i=j+1; i<=nrow; ip += i++)
1027 ip = m.begin() + pivrow*(pivrow-1)/2 + j+1;
1028 for (i=j+2; i < pivrow; i++, ip++)
1030 temp1 = *(m.begin() + i*(i-1)/2 + j);
1031 *(m.begin() + i*(i-1)/2 + j) = *ip;
1034 temp1 = *(mjj + j + 1);
1036 *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1);
1037 *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1) = temp1;
1039 *(mjj + j) = *(m.begin() + pivrow*(pivrow-1)/2 + j-1);
1040 *(m.begin() + pivrow*(pivrow-1)/2 + j-1) = temp1;
1041 ip = m.begin() + (pivrow+1)*pivrow/2 + j;
1042 iq = ip + pivrow-(j+1);
1043 for (i = pivrow+1; i <= nrow; ip += i, iq += i++)
1051 temp2 = *mjj * *(mjj + j + 1) - *(mjj + j) * *(mjj + j);
1056 "Error in pivot choice!");
1064 *mjj = *(mjj + j + 1) * temp2;
1065 *(mjj + j + 1) = temp1 * temp2;
1066 *(mjj + j) = - *(mjj + j) * temp2;
1071 for (i=j+2; i <= nrow ; i++)
1073 ip = m.begin() + i*(i-1)/2 + j-1;
1074 temp1 = *ip * *mjj + *(ip + 1) * *(mjj + j);
1075 if (std::fabs(temp1 ) <= epsilon)
1077 temp2 = *ip * *(mjj + j) + *(ip + 1) * *(mjj + j + 1);
1078 if (std::fabs(temp2 ) <=
epsilon)
1080 for (k = j+2; k <= i ; k++)
1082 ip = m.begin() + i*(i-1)/2 + k-1;
1083 iq = m.begin() + k*(k-1)/2 + j-1;
1084 *ip -= temp1 * *iq + temp2 * *(iq+1);
1085 if (std::fabs(*ip) <=
epsilon)
1090 for (i=j+2; i <= nrow ; i++)
1092 ip = m.begin() + i*(i-1)/2 + j-1;
1093 temp1 = *ip * *mjj + *(ip+1) * *(mjj + j);
1094 if (std::fabs(temp1) <= epsilon)
1096 *(ip+1) = *ip * *(mjj + j) + *(ip+1) * *(mjj + j + 1);
1097 if (std::fabs(*(ip+1)) <= epsilon)
1108 mjj = m.begin() + j*(j-1)/2 + j-1;
1122 for (j = nrow ; j >= 1 ; j -= ss)
1124 mjj = m.begin() + j*(j-1)/2 + j-1;
1130 ip = m.begin() + (j+1)*j/2 + j-1;
1131 for (i=0; i < nrow-j; ip += 1+j+i++)
1135 for (i=j+1; i<=nrow ; i++)
1138 ip = m.begin() + i*(i-1)/2 + j;
1139 for (k=0; k <= i-j-1; k++)
1140 { temp2 += *ip++ * x[k]; }
1141 for (ip += i-1; k < nrow-j; ip += 1+j+k++)
1142 { temp2 += *ip * x[k]; }
1143 *(m.begin()+ i*(i-1)/2 + j-1) = -temp2;
1146 ip = m.begin() + (j+1)*j/2 + j-1;
1147 for (k=0; k < nrow-j; ip += 1+j+k++)
1148 { temp2 += x[k] * *ip; }
1156 std::ostringstream message;
1157 message <<
"Error in pivot: " << piv[j-1];
1158 G4Exception(
"G4ErrorSymMatrix::invertBunchKaufman()",
1164 ip = m.begin() + (j+1)*j/2 + j-1;
1165 for (i=0; i < nrow-j; ip += 1+j+i++)
1169 for (i=j+1; i<=nrow ; i++)
1172 ip = m.begin() + i*(i-1)/2 + j;
1173 for (k=0; k <= i-j-1; k++)
1174 { temp2 += *ip++ * x[k]; }
1175 for (ip += i-1; k < nrow-j; ip += 1+j+k++)
1176 { temp2 += *ip * x[k]; }
1177 *(m.begin()+ i*(i-1)/2 + j-1) = -temp2;
1180 ip = m.begin() + (j+1)*j/2 + j-1;
1181 for (k=0; k < nrow-j; ip += 1+j+k++)
1182 { temp2 += x[k] * *ip; }
1185 ip = m.begin() + (j+1)*j/2 + j-2;
1186 for (i=j+1; i <= nrow; ip += i++)
1187 { temp2 += *ip * *(ip+1); }
1189 ip = m.begin() + (j+1)*j/2 + j-2;
1190 for (i=0; i < nrow-j; ip += 1+j+i++)
1194 for (i=j+1; i <= nrow ; i++)
1197 ip = m.begin() + i*(i-1)/2 + j;
1198 for (k=0; k <= i-j-1; k++)
1199 { temp2 += *ip++ * x[k]; }
1200 for (ip += i-1; k < nrow-j; ip += 1+j+k++)
1201 { temp2 += *ip * x[k]; }
1202 *(m.begin()+ i*(i-1)/2 + j-2)= -temp2;
1205 ip = m.begin() + (j+1)*j/2 + j-2;
1206 for (k=0; k < nrow-j; ip += 1+j+k++)
1207 { temp2 += x[k] * *ip; }
1215 pivrow = (piv[j-1]==0)? -piv[j-2] : piv[j-1];
1216 ip = m.begin() + pivrow*(pivrow-1)/2 + j;
1217 for (i=j+1;i < pivrow; i++, ip++)
1219 temp1 = *(m.begin() + i*(i-1)/2 + j-1);
1220 *(m.begin() + i*(i-1)/2 + j-1) = *ip;
1224 *mjj = *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1);
1225 *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1) = temp1;
1229 *(mjj-1) = *( m.begin() + pivrow*(pivrow-1)/2 + j-2);
1230 *( m.begin() + pivrow*(pivrow-1)/2 + j-2) = temp1;
1233 ip = m.begin() + (pivrow+1)*pivrow/2 + j-1;
1235 for (i = pivrow+1; i <= nrow; ip += i, iq += i++)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::vector< G4double >::iterator G4ErrorMatrixIter
static const G4double alpha
double epsilon(double density, double temperature)