| 1 |
/*! \file C_BlasRoutines.cpp |
| 2 |
\brief factorization routines LDL^t, LDU, forward/backward substitution |
| 3 |
\author François-Xavier Roux, ONERA, Laboratoire Jacques-Louis Lions |
| 4 |
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions |
| 5 |
\date Jul. 12th 2015 |
| 6 |
\date Nov. 30th 2016 |
| 7 |
*/ |
| 8 |
|
| 9 |
// This file is part of Dissection |
| 10 |
// |
| 11 |
// Dissection is free software: you can redistribute it and/or modify |
| 12 |
// it under the terms of the GNU General Public License as published by |
| 13 |
// the Free Software Foundation, either version 3 of the License, or |
| 14 |
// (at your option) any later version. |
| 15 |
// |
| 16 |
// Linking Dissection statically or dynamically with other modules is making |
| 17 |
// a combined work based on Disssection. Thus, the terms and conditions of |
| 18 |
// the GNU General Public License cover the whole combination. |
| 19 |
// |
| 20 |
// As a special exception, the copyright holders of Dissection give you |
| 21 |
// permission to combine Dissection program with free software programs or |
| 22 |
// libraries that are released under the GNU LGPL and with independent modules |
| 23 |
// that communicate with Dissection solely through the Dissection-fortran |
| 24 |
// interface. You may copy and distribute such a system following the terms of |
| 25 |
// the GNU GPL for Dissection and the licenses of the other code concerned, |
| 26 |
// provided that you include the source code of that other code when and as |
| 27 |
// the GNU GPL requires distribution of source code and provided that you do |
| 28 |
// not modify the Dissection-fortran interface. |
| 29 |
// |
| 30 |
// Note that people who make modified versions of Dissection are not obligated |
| 31 |
// to grant this special exception for their modified versions; it is their |
| 32 |
// choice whether to do so. The GNU General Public License gives permission to |
| 33 |
// release a modified version without this exception; this exception also makes |
| 34 |
// it possible to release a modified version which carries forward this |
| 35 |
// exception. If you modify the Dissection-fortran interface, this exception |
| 36 |
// does not apply to your modified version of Dissection, and you must remove |
| 37 |
// this exception when you distribute your modified version. |
| 38 |
// |
| 39 |
// This exception is an additional permission under section 7 of the GNU |
| 40 |
// General Public License, version 3 ("GPLv3") |
| 41 |
// |
| 42 |
// Dissection is distributed in the hope that it will be useful, |
| 43 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 44 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 45 |
// GNU General Public License for more details. |
| 46 |
// |
| 47 |
// You should have received a copy of the GNU General Public License |
| 48 |
// along with Dissection. If not, see <http://www.gnu.org/licenses/>. |
| 49 |
// |
| 50 |
|
| 51 |
#include "Driver/C_BlasRoutines.hpp" |
| 52 |
#include "Driver/C_threads_tasks.hpp" |
| 53 |
#include "Algebra/VectorArray.hpp" |
| 54 |
|
| 55 |
// T may be complex of U that is higher precision than Z |
| 56 |
template<typename T, typename U, typename Z> |
| 57 |
Z matrix_infty_norm_(const int n, T *a, const int lda) |
| 58 |
{ |
| 59 |
Z err(0.0); |
| 60 |
for (int i = 0; i < n; i++) { |
| 61 |
U err_tmp1(0.0); |
| 62 |
for (int j = 0; j < n; j++) { |
| 63 |
err_tmp1 += blas_abs<T, U>(a[i + j * lda]); |
| 64 |
} |
| 65 |
Z err_tmp0 = conv_prec<Z, U>(err_tmp1); // accuracy conversion : U to Z |
| 66 |
err = err > err_tmp0 ? err : err_tmp0; |
| 67 |
} |
| 68 |
return err; |
| 69 |
} |
| 70 |
|
| 71 |
template |
| 72 |
double matrix_infty_norm_<quadruple, quadruple, double>(const int n, |
| 73 |
quadruple *a, |
| 74 |
const int lda); |
| 75 |
#ifndef NO_OCTRUPLE |
| 76 |
template |
| 77 |
quadruple matrix_infty_norm_<octruple, octruple, quadruple>(const int n, |
| 78 |
octruple *a, |
| 79 |
const int lda); |
| 80 |
#endif |
| 81 |
template |
| 82 |
float matrix_infty_norm_<double, double, float>(const int n, |
| 83 |
double *a, |
| 84 |
const int lda); |
| 85 |
|
| 86 |
template |
| 87 |
double matrix_infty_norm_<complex<quadruple>, |
| 88 |
quadruple, |
| 89 |
double>(const int n, |
| 90 |
complex<quadruple> *a, |
| 91 |
const int lda); |
| 92 |
|
| 93 |
template |
| 94 |
float matrix_infty_norm_<complex<double>, |
| 95 |
double, |
| 96 |
float>(const int n, |
| 97 |
complex<double> *a, |
| 98 |
const int lda); |
| 99 |
|
| 100 |
#ifndef NO_OCTRUPLE |
| 101 |
template |
| 102 |
quadruple matrix_infty_norm_<complex<octruple>, |
| 103 |
octruple, |
| 104 |
quadruple>(const int n, |
| 105 |
complex<octruple> *a, const int lda); |
| 106 |
#endif |
| 107 |
// |
| 108 |
|
| 109 |
template<typename T, typename U> |
| 110 |
U matrix_infty_norm(const int n, T *a, const int lda) |
| 111 |
{ |
| 112 |
fprintf(stderr, "%s %d : general template is not implemented\n", |
| 113 |
__FILE__, __LINE__); |
| 114 |
return U(0.0); |
| 115 |
} |
| 116 |
|
| 117 |
template<> |
| 118 |
double matrix_infty_norm<quadruple, double>(const int n, |
| 119 |
quadruple *a, const int lda) |
| 120 |
{ |
| 121 |
return matrix_infty_norm_<quadruple, quadruple, double>(n, a, lda); |
| 122 |
} |
| 123 |
|
| 124 |
template<> |
| 125 |
float matrix_infty_norm<double, float>(const int n, |
| 126 |
double *a, const int lda) |
| 127 |
{ |
| 128 |
return matrix_infty_norm_<double, double, float>(n, a, lda); |
| 129 |
} |
| 130 |
|
| 131 |
#ifndef NO_OCTRUPLE |
| 132 |
template<> |
| 133 |
quadruple matrix_infty_norm<octruple, quadruple>(const int n, |
| 134 |
octruple *a, const int lda) |
| 135 |
{ |
| 136 |
return matrix_infty_norm_<octruple, octruple, quadruple>(n, a, lda); |
| 137 |
} |
| 138 |
#endif |
| 139 |
template<> |
| 140 |
double matrix_infty_norm<complex<quadruple>, |
| 141 |
double>(const int n, |
| 142 |
complex<quadruple> *a, const int lda) |
| 143 |
{ |
| 144 |
return matrix_infty_norm_<complex<quadruple>, quadruple, double>(n, a, lda); |
| 145 |
} |
| 146 |
|
| 147 |
template<> |
| 148 |
float matrix_infty_norm<complex<double>, |
| 149 |
float>(const int n, |
| 150 |
complex<double> *a, const int lda) |
| 151 |
{ |
| 152 |
return matrix_infty_norm_<complex<double>, double, float>(n, a, lda); |
| 153 |
} |
| 154 |
|
| 155 |
#ifndef NO_OCTRUPLE |
| 156 |
template<> |
| 157 |
quadruple matrix_infty_norm<complex<octruple>, |
| 158 |
quadruple>(const int n, |
| 159 |
complex<octruple> *a, const int lda) |
| 160 |
{ |
| 161 |
return matrix_infty_norm_<complex<octruple>, octruple, quadruple>(n, a, lda); |
| 162 |
} |
| 163 |
#endif |
| 164 |
|
| 165 |
// #define LDLT_LOWER |
| 166 |
|
| 167 |
// *pivot is dealt as "double", which give no defect on accuracy, because |
| 168 |
// magnitude is important in the value of pivot |
| 169 |
template<typename T, typename U> |
| 170 |
bool full_ldlt_permute(int *nn0, const int n0, const int n, |
| 171 |
T *a, const int lda, |
| 172 |
double *pivot, int *permute, |
| 173 |
const double eps, double *fop) |
| 174 |
{ |
| 175 |
const int lda1 = lda + 1; |
| 176 |
T alpha; |
| 177 |
const T one(1.0); |
| 178 |
const T none(-1.0); |
| 179 |
bool flag = true; |
| 180 |
VectorArray<T> col_k(n); |
| 181 |
VectorArray<T> col_km(n); |
| 182 |
alpha = none; |
| 183 |
for (int i = 0; i < n; i++) { |
| 184 |
permute[i] = i; |
| 185 |
} |
| 186 |
const int n1 = n - n0; |
| 187 |
int k = 0; |
| 188 |
while (k < n1) { |
| 189 |
int km = k; |
| 190 |
double vmax = 0.0; |
| 191 |
km = blas_iamax<T, U>((n - k), a + (k * lda1), lda1) + k; |
| 192 |
vmax = blas_abs<T, double>(a[km * lda1]); |
| 193 |
if (vmax < (*pivot * eps)) { // enough in doule precision |
| 194 |
flag = false; |
| 195 |
break; |
| 196 |
} |
| 197 |
*pivot = vmax; |
| 198 |
if (km > k) { |
| 199 |
int itmp = permute[km]; |
| 200 |
permute[km] = permute[k]; |
| 201 |
permute[k] = itmp; |
| 202 |
// swap row/column |
| 203 |
#ifdef LDLT_LOWER |
| 204 |
swap_sym_lower(n, a, lda, k, km, col_k.addrCoefs(), col_km.addrCoefs()); |
| 205 |
#else |
| 206 |
swap_sym_upper(n, a, lda, k, km, col_k.addrCoefs(), col_km.addrCoefs()); |
| 207 |
#endif |
| 208 |
} |
| 209 |
const T d = one / a[k * lda1]; |
| 210 |
a[k * lda1] = d; |
| 211 |
if (k == (n1 - 1)) { |
| 212 |
k++; |
| 213 |
break; |
| 214 |
} |
| 215 |
alpha = (-d); |
| 216 |
#ifdef LDLT_LOWER |
| 217 |
blas_syr<T>(CblasLower, (n - k - 1), alpha, |
| 218 |
&a[k * lda1 + 1], 1, |
| 219 |
&a[(k + 1) * lda1], lda); |
| 220 |
#else |
| 221 |
blas_syr<T>(CblasUpper, (n - k - 1), alpha, |
| 222 |
&a[k * lda1 + lda], lda, |
| 223 |
&a[(k + 1) * lda1], lda); |
| 224 |
#endif |
| 225 |
*fop += 3.0 * (double)(n - k - 1) * (double)(n - k) / 2.0; |
| 226 |
#ifdef LDLT_LOWER |
| 227 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + 1], 1); |
| 228 |
#else |
| 229 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + lda], lda); |
| 230 |
#endif |
| 231 |
*fop += double(n - k - 1); |
| 232 |
k++; |
| 233 |
} // while (k < n1) |
| 234 |
// symmetrize the results : copy lower to upper |
| 235 |
#ifdef LDLT_LOWER |
| 236 |
for (int j = 1; j < n1; j++) { |
| 237 |
for (int i = 0; i < j; i++) { |
| 238 |
a[i + j * lda] = a[j + i * lda]; |
| 239 |
} |
| 240 |
} |
| 241 |
#else |
| 242 |
for (int j = 1; j < n1; j++) { |
| 243 |
for (int i = 0; i < j; i++) { |
| 244 |
a[j + i * lda] = a[i + j * lda]; |
| 245 |
} |
| 246 |
} |
| 247 |
#endif |
| 248 |
*nn0 = n - k; |
| 249 |
return flag; |
| 250 |
} |
| 251 |
|
| 252 |
template |
| 253 |
bool full_ldlt_permute<double, double>(int *nn0, const int n0, |
| 254 |
const int n, |
| 255 |
double *a, const int lda, |
| 256 |
double *pivot, int *permute, |
| 257 |
const double eps, double *fop); |
| 258 |
|
| 259 |
template |
| 260 |
bool full_ldlt_permute<complex<double>, double>(int *nn0, const int n0, |
| 261 |
const int n, |
| 262 |
complex<double> *a, |
| 263 |
const int lda, |
| 264 |
double *pivot, int *permute, |
| 265 |
const double eps, double *fop); |
| 266 |
|
| 267 |
template |
| 268 |
bool full_ldlt_permute<float, float>(int *nn0, const int n0, |
| 269 |
const int n, |
| 270 |
float *a, const int lda, |
| 271 |
double *pivot, int *permute, |
| 272 |
const double eps, double *fop); |
| 273 |
|
| 274 |
template |
| 275 |
bool full_ldlt_permute<complex<float>, float>(int *nn0, const int n0, |
| 276 |
const int n, |
| 277 |
complex<float> *a, |
| 278 |
const int lda, |
| 279 |
double *pivot, int *permute, |
| 280 |
const double eps, double *fop); |
| 281 |
|
| 282 |
template |
| 283 |
bool full_ldlt_permute<quadruple, quadruple>(int *nn0, const int n0, |
| 284 |
const int n, |
| 285 |
quadruple *a, const int lda, |
| 286 |
double *pivot, int *permute, |
| 287 |
const double eps, double *fop); |
| 288 |
|
| 289 |
template |
| 290 |
bool full_ldlt_permute<complex<quadruple>, quadruple>(int *nn0, const int n0, |
| 291 |
const int n, |
| 292 |
complex<quadruple> *a, |
| 293 |
const int lda, |
| 294 |
double *pivot, |
| 295 |
int *permute, |
| 296 |
const double eps, |
| 297 |
double *fop); |
| 298 |
template |
| 299 |
bool full_ldlt_permute<octruple, octruple>(int *nn0, const int n0, |
| 300 |
const int n, |
| 301 |
octruple *a, const int lda, |
| 302 |
double *pivot, int *permute, |
| 303 |
const double eps, double *fop); |
| 304 |
|
| 305 |
template |
| 306 |
bool full_ldlt_permute<complex<octruple>, octruple>(int *nn0, const int n0, |
| 307 |
const int n, |
| 308 |
complex<octruple> *a, |
| 309 |
const int lda, |
| 310 |
double *pivot, |
| 311 |
int *permute, |
| 312 |
const double eps, |
| 313 |
double *fop); |
| 314 |
// |
| 315 |
|
| 316 |
template<typename T, typename U> |
| 317 |
bool full_ldu_permute(int *nn0, const int n0, |
| 318 |
const int n, T *a, const int lda, |
| 319 |
double *pivot, int *permute, |
| 320 |
const double eps, double *fop) |
| 321 |
{ |
| 322 |
const int lda1 = lda + 1; |
| 323 |
// T *col_k, *col_km; |
| 324 |
const T one(1.0); |
| 325 |
const T none(-1.0); |
| 326 |
bool flag = true; |
| 327 |
VectorArray<T> col_k(n); |
| 328 |
VectorArray<T> col_km(n); |
| 329 |
for (int i = 0; i < n; i++) { |
| 330 |
permute[i] = i; |
| 331 |
} |
| 332 |
const int n1 = n - n0; |
| 333 |
int k = 0; |
| 334 |
while (k < n1) { |
| 335 |
int km = k; |
| 336 |
double vmax = 0.0; |
| 337 |
km = blas_iamax<T, U>((n - k), a + (k * lda1), lda1) + k; |
| 338 |
vmax = blas_abs<T, double>(a[km * lda1]); |
| 339 |
if (vmax < (*pivot * eps)) { |
| 340 |
flag = false; |
| 341 |
break; |
| 342 |
} |
| 343 |
*pivot = vmax; |
| 344 |
if (km > k) { |
| 345 |
int itmp = permute[km]; |
| 346 |
permute[km] = permute[k]; |
| 347 |
permute[k] = itmp; |
| 348 |
// swap row/column |
| 349 |
swap_unsym(n, a, lda, k, km, col_k.addrCoefs(), col_km.addrCoefs()); |
| 350 |
} |
| 351 |
const T d = one / a[k * lda1]; |
| 352 |
a[k * lda1] = d; |
| 353 |
if (k == (n1 - 1)) { |
| 354 |
k++; |
| 355 |
break; |
| 356 |
} |
| 357 |
// alpha = none; |
| 358 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + lda], lda); |
| 359 |
blas_ger<T>((n - k - 1), (n - k - 1), none, |
| 360 |
&a[k * lda1 + 1], 1, &a[k * lda1 + lda], lda, |
| 361 |
&a[(k + 1) * lda1], lda); |
| 362 |
*fop += 3.0 * (double)(n - k - 1) * (double)(n - k) / 2.0; |
| 363 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + 1], 1); |
| 364 |
*fop += 2.0 * double(n - k - 1); |
| 365 |
k++; |
| 366 |
} // while (k < n1) |
| 367 |
|
| 368 |
*nn0 = n - k; |
| 369 |
return flag; |
| 370 |
} |
| 371 |
|
| 372 |
template |
| 373 |
bool full_ldu_permute<double, double>(int *nn0, const int n0, |
| 374 |
const int n, |
| 375 |
double *a, const int lda, |
| 376 |
double *pivot, int *permute, |
| 377 |
const double eps, double *fop); |
| 378 |
template |
| 379 |
bool full_ldu_permute<complex<double>, double>(int *nn0, const int n0, |
| 380 |
const int n, |
| 381 |
complex<double> *a, |
| 382 |
const int lda, |
| 383 |
double *pivot, int *permute, |
| 384 |
const double eps, double *fop); |
| 385 |
template |
| 386 |
bool full_ldu_permute<float, float>(int *nn0, const int n0, |
| 387 |
const int n, |
| 388 |
float *a, const int lda, |
| 389 |
double *pivot, int *permute, |
| 390 |
const double eps, double *fop); |
| 391 |
template |
| 392 |
bool full_ldu_permute<complex<float>, float>(int *nn0, const int n0, |
| 393 |
const int n, |
| 394 |
complex<float> *a, |
| 395 |
const int lda, |
| 396 |
double *pivot, int *permute, |
| 397 |
const double eps, double *fop); |
| 398 |
|
| 399 |
template |
| 400 |
bool full_ldu_permute<quadruple, quadruple>(int *nn0, const int n0, |
| 401 |
const int n, |
| 402 |
quadruple *a, const int lda, |
| 403 |
double *pivot, int *permute, |
| 404 |
const double eps, double *fop); |
| 405 |
template |
| 406 |
bool full_ldu_permute<complex<quadruple>, quadruple>(int *nn0, const int n0, |
| 407 |
const int n, |
| 408 |
complex<quadruple> *a, |
| 409 |
const int lda, |
| 410 |
double *pivot, |
| 411 |
int *permute, |
| 412 |
const double eps, |
| 413 |
double *fop); |
| 414 |
template |
| 415 |
bool full_ldu_permute<octruple, octruple>(int *nn0, const int n0, |
| 416 |
const int n, |
| 417 |
octruple *a, const int lda, |
| 418 |
double *pivot, int *permute, |
| 419 |
const double eps, double *fop); |
| 420 |
template |
| 421 |
bool full_ldu_permute<complex<octruple>, octruple>(int *nn0, const int n0, |
| 422 |
const int n, |
| 423 |
complex<octruple> *a, |
| 424 |
const int lda, |
| 425 |
double *pivot, |
| 426 |
int *permute, |
| 427 |
const double eps, |
| 428 |
double *fop); |
| 429 |
// |
| 430 |
template<typename T, typename U> |
| 431 |
bool ldu_full_permute(int *nn0, const int n0, |
| 432 |
const int n, T *a, const int lda, |
| 433 |
double *pivot, int *permute_right, int *permute_left, |
| 434 |
const double eps, double *fop) |
| 435 |
{ |
| 436 |
const int lda1 = lda + 1; |
| 437 |
// T *col_k, *col_km; |
| 438 |
const T one(1.0); |
| 439 |
const T none(-1.0); |
| 440 |
bool flag = true; |
| 441 |
VectorArray<T> coli(n); |
| 442 |
VectorArray<T> colj(n); |
| 443 |
for (int i = 0; i < n; i++) { |
| 444 |
permute_right[i] = i; |
| 445 |
permute_left[i] = i; |
| 446 |
} |
| 447 |
const int n1 = n - n0; |
| 448 |
int k = 0; |
| 449 |
while (k < n1) { |
| 450 |
int ki, kj, itmp; |
| 451 |
double vmax = 0.0; |
| 452 |
for (int i = k; i < n; i++) { |
| 453 |
for (int j = k; j < n; j++) { |
| 454 |
double tmp = blas_abs<T, double>(a[i + j * lda]); |
| 455 |
if (tmp > vmax) { |
| 456 |
vmax = tmp; |
| 457 |
ki = i; |
| 458 |
kj = j; |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
if (vmax < (*pivot * eps)) { |
| 463 |
flag = false; |
| 464 |
break; |
| 465 |
} |
| 466 |
*pivot = vmax; |
| 467 |
if (kj > k) { |
| 468 |
itmp = permute_right[kj]; |
| 469 |
permute_right[kj] = permute_right[k]; |
| 470 |
permute_right[k] = itmp; |
| 471 |
} |
| 472 |
if (ki > k) { |
| 473 |
itmp = permute_left[ki]; |
| 474 |
permute_left[ki] = permute_left[k]; |
| 475 |
permute_left[k] = itmp; |
| 476 |
} |
| 477 |
// swap row/column |
| 478 |
swap_full(n, a, lda, k, ki, kj, coli.addrCoefs(), colj.addrCoefs()); |
| 479 |
const T d = one / a[k * lda1]; |
| 480 |
a[k * lda1] = d; |
| 481 |
if (k == (n1 - 1)) { |
| 482 |
k++; |
| 483 |
break; |
| 484 |
} |
| 485 |
// alpha = none; |
| 486 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + lda], lda); |
| 487 |
blas_ger<T>((n - k - 1), (n - k - 1), none, |
| 488 |
&a[k * lda1 + 1], 1, &a[k * lda1 + lda], lda, |
| 489 |
&a[(k + 1) * lda1], lda); |
| 490 |
*fop += 3.0 * (double)(n - k - 1) * (double)(n - k) / 2.0; |
| 491 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + 1], 1); |
| 492 |
*fop += 2.0 * double(n - k - 1); |
| 493 |
k++; |
| 494 |
} // while (k < n1) |
| 495 |
|
| 496 |
*nn0 = n - k; |
| 497 |
return flag; |
| 498 |
} |
| 499 |
|
| 500 |
template |
| 501 |
bool ldu_full_permute<double, double>(int *nn0, const int n0, |
| 502 |
const int n, |
| 503 |
double *a, const int lda, |
| 504 |
double *pivot, |
| 505 |
int *permute_right, int *permute_left, |
| 506 |
const double eps, double *fop); |
| 507 |
template |
| 508 |
bool ldu_full_permute<complex<double>, double>(int *nn0, const int n0, |
| 509 |
const int n, |
| 510 |
complex<double> *a, |
| 511 |
const int lda, |
| 512 |
double *pivot, |
| 513 |
int *permute_right, |
| 514 |
int *permute_left, |
| 515 |
const double eps, double *fop); |
| 516 |
template |
| 517 |
bool ldu_full_permute<quadruple, quadruple>(int *nn0, const int n0, |
| 518 |
const int n, |
| 519 |
quadruple *a, const int lda, |
| 520 |
double *pivot, int *permute_right, |
| 521 |
int *permute_left, |
| 522 |
const double eps, double *fop); |
| 523 |
template |
| 524 |
bool ldu_full_permute<complex<quadruple>, quadruple>(int *nn0, const int n0, |
| 525 |
const int n, |
| 526 |
complex<quadruple> *a, |
| 527 |
const int lda, |
| 528 |
double *pivot, |
| 529 |
int *permute_right, |
| 530 |
int *permute_left, |
| 531 |
const double eps, |
| 532 |
double *fop); |
| 533 |
template |
| 534 |
bool ldu_full_permute<octruple, octruple>(int *nn0, const int n0, |
| 535 |
const int n, |
| 536 |
octruple *a, const int lda, |
| 537 |
double *pivot, int *permute_right, |
| 538 |
int *permute_left, |
| 539 |
const double eps, double *fop); |
| 540 |
template |
| 541 |
bool ldu_full_permute<complex<octruple>, octruple>(int *nn0, const int n0, |
| 542 |
const int n, |
| 543 |
complex<octruple> *a, |
| 544 |
const int lda, |
| 545 |
double *pivot, |
| 546 |
int *permute_right, |
| 547 |
int *permute_left, |
| 548 |
const double eps, |
| 549 |
double *fop); |
| 550 |
template |
| 551 |
bool ldu_full_permute<float, float>(int *nn0, const int n0, |
| 552 |
const int n, |
| 553 |
float *a, const int lda, |
| 554 |
double *pivot, |
| 555 |
int *permute_right, int *permute_left, |
| 556 |
const double eps, double *fop); |
| 557 |
template |
| 558 |
bool ldu_full_permute<complex<float>, float>(int *nn0, const int n0, |
| 559 |
const int n, |
| 560 |
complex<float> *a, |
| 561 |
const int lda, |
| 562 |
double *pivot, |
| 563 |
int *permute_right, |
| 564 |
int *permute_left, |
| 565 |
const double eps, double *fop); |
| 566 |
|
| 567 |
// |
| 568 |
template<typename T> |
| 569 |
void swap_sym_lower(const int n, T *a, const int lda, |
| 570 |
const int k, const int km, T *col_k, T *col_km) |
| 571 |
{ |
| 572 |
const int lda1 = lda + 1; |
| 573 |
for (int i = k; i < n; i++) { |
| 574 |
col_k[i] = a[i + k * lda]; // save lower column k |
| 575 |
} |
| 576 |
for (int j = 0; j < k; j++) { |
| 577 |
col_k[j] = a[k + j * lda]; // save lower row k |
| 578 |
} |
| 579 |
for (int i = km; i < n; i++) { |
| 580 |
col_km[i] = a[i + km * lda]; // save lower column km |
| 581 |
} |
| 582 |
for (int j = 0; j < km; j++) { |
| 583 |
col_km[j] = a[km + j * lda]; // save lower row km |
| 584 |
} |
| 585 |
for (int i = (k + 1); i < n; i++) { |
| 586 |
a[i + k * lda] = col_km[i]; // restore lower column k |
| 587 |
} |
| 588 |
for (int i = (km + 1); i < n; i++) { |
| 589 |
a[i + km * lda] = col_k[i]; // restore lower column km |
| 590 |
} |
| 591 |
for (int j = 0; j < k; j++) { |
| 592 |
a[k + j * lda] = col_km[j]; // restore lower row k |
| 593 |
} |
| 594 |
for (int j = 0; j < km; j++) { |
| 595 |
a[km + j * lda] = col_k[j]; // restore lower row km |
| 596 |
} |
| 597 |
a[k * lda1] = col_km[km]; |
| 598 |
a[km * lda1] = col_k[k]; |
| 599 |
a[km + k * lda] = col_k[km]; |
| 600 |
} |
| 601 |
|
| 602 |
template |
| 603 |
void swap_sym_lower<double>(const int n, double *a, const int lda, |
| 604 |
const int k, const int km, |
| 605 |
double *col_k, double *col_km); |
| 606 |
|
| 607 |
template |
| 608 |
void swap_sym_lower<complex<double> >(const int n, complex<double> *a, |
| 609 |
const int lda, |
| 610 |
const int k, const int km, |
| 611 |
complex<double> *col_k, |
| 612 |
complex<double> *col_km); |
| 613 |
template |
| 614 |
void swap_sym_lower<float>(const int n, float *a, const int lda, |
| 615 |
const int k, const int km, |
| 616 |
float *col_k, float *col_km); |
| 617 |
|
| 618 |
template |
| 619 |
void swap_sym_lower<complex<float> >(const int n, complex<float> *a, |
| 620 |
const int lda, |
| 621 |
const int k, const int km, |
| 622 |
complex<float> *col_k, |
| 623 |
complex<float> *col_km); |
| 624 |
|
| 625 |
template |
| 626 |
void swap_sym_lower<quadruple>(const int n, quadruple *a, const int lda, |
| 627 |
const int k, const int km, |
| 628 |
quadruple *col_k, quadruple *col_km); |
| 629 |
|
| 630 |
template |
| 631 |
void swap_sym_lower<complex<quadruple> >(const int n, complex<quadruple> *a, |
| 632 |
const int lda, |
| 633 |
const int k, const int km, |
| 634 |
complex<quadruple> *col_k, |
| 635 |
complex<quadruple> *col_km); |
| 636 |
// |
| 637 |
|
| 638 |
template<typename T> |
| 639 |
void swap_sym_upper(const int n, T *a, const int lda, |
| 640 |
const int k, const int km, T *col_k, T *col_km) |
| 641 |
{ |
| 642 |
const int lda1 = lda + 1; |
| 643 |
for (int i = k; i < n; i++) { |
| 644 |
col_k[i] = a[k + i * lda]; // save lower column k |
| 645 |
} |
| 646 |
for (int j = 0; j < k; j++) { |
| 647 |
col_k[j] = a[j + k * lda]; // save lower row k |
| 648 |
} |
| 649 |
for (int i = km; i < n; i++) { |
| 650 |
col_km[i] = a[km + i * lda]; // save lower column km |
| 651 |
} |
| 652 |
for (int j = 0; j < km; j++) { |
| 653 |
col_km[j] = a[j + km * lda]; // save lower row km |
| 654 |
} |
| 655 |
for (int i = (k + 1); i < n; i++) { |
| 656 |
a[k + i * lda] = col_km[i]; // restore lower column k |
| 657 |
} |
| 658 |
for (int i = (km + 1); i < n; i++) { |
| 659 |
a[km + i * lda] = col_k[i]; // restore lower column km |
| 660 |
} |
| 661 |
for (int j = 0; j < k; j++) { |
| 662 |
a[j + k * lda] = col_km[j]; // restore lower row k |
| 663 |
} |
| 664 |
for (int j = 0; j < km; j++) { |
| 665 |
a[j + km * lda] = col_k[j]; // restore lower row km |
| 666 |
} |
| 667 |
a[k * lda1] = col_km[km]; |
| 668 |
a[km * lda1] = col_k[k]; |
| 669 |
a[k + km * lda] = col_k[km]; |
| 670 |
} |
| 671 |
|
| 672 |
template |
| 673 |
void swap_sym_upper<double>(const int n, double *a, const int lda, |
| 674 |
const int k, const int km, |
| 675 |
double *col_k, double *col_km); |
| 676 |
|
| 677 |
template |
| 678 |
void swap_sym_upper<complex<double> >(const int n, complex<double> *a, |
| 679 |
const int lda, |
| 680 |
const int k, const int km, |
| 681 |
complex<double> *col_k, |
| 682 |
complex<double> *col_km); |
| 683 |
|
| 684 |
template |
| 685 |
void swap_sym_upper<float>(const int n, float *a, const int lda, |
| 686 |
const int k, const int km, |
| 687 |
float *col_k, float *col_km); |
| 688 |
|
| 689 |
template |
| 690 |
void swap_sym_upper<complex<float> >(const int n, complex<float> *a, |
| 691 |
const int lda, |
| 692 |
const int k, const int km, |
| 693 |
complex<float> *col_k, |
| 694 |
complex<float> *col_km); |
| 695 |
|
| 696 |
template |
| 697 |
void swap_sym_upper<quadruple>(const int n, quadruple *a, const int lda, |
| 698 |
const int k, const int km, |
| 699 |
quadruple *col_k, quadruple *col_km); |
| 700 |
|
| 701 |
template |
| 702 |
void swap_sym_upper<complex<quadruple> >(const int n, complex<quadruple> *a, |
| 703 |
const int lda, |
| 704 |
const int k, const int km, |
| 705 |
complex<quadruple> *col_k, |
| 706 |
complex<quadruple> *col_km); |
| 707 |
// |
| 708 |
|
| 709 |
template<typename T> |
| 710 |
void swap_unsym(const int n, T *a, const int lda, |
| 711 |
const int k, const int km, T *col_k, T *col_km) |
| 712 |
{ |
| 713 |
for (int i = 0; i < n; i++) { |
| 714 |
col_k[i] = a[i + k * lda]; // save lower column k |
| 715 |
col_km[i] = a[i + km * lda]; // save lower column km |
| 716 |
} |
| 717 |
for (int i = 0; i < n; i++) { |
| 718 |
a[i + km * lda] = col_k[i]; // save lower column km |
| 719 |
a[i + k * lda] = col_km[i]; |
| 720 |
} |
| 721 |
for (int i = 0; i < n; i++) { |
| 722 |
col_k[i] = a[k + i * lda]; // save lower column k |
| 723 |
col_km[i] = a[km + i * lda]; // save lower column km |
| 724 |
} |
| 725 |
for (int i = 0; i < n; i++) { |
| 726 |
a[km + i * lda] = col_k[i]; // save lower column km |
| 727 |
a[k + i * lda] = col_km[i]; |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
template |
| 732 |
void swap_unsym<double>(const int n, double *a, const int lda, |
| 733 |
const int k, const int km, |
| 734 |
double *col_k, double *col_km); |
| 735 |
|
| 736 |
template |
| 737 |
void swap_unsym<complex<double> >(const int n, complex<double> *a, |
| 738 |
const int lda, |
| 739 |
const int k, const int km, |
| 740 |
complex<double> *col_k, |
| 741 |
complex<double> *col_km); |
| 742 |
template |
| 743 |
void swap_unsym<float>(const int n, float *a, const int lda, |
| 744 |
const int k, const int km, |
| 745 |
float *col_k, float *col_km); |
| 746 |
|
| 747 |
template |
| 748 |
void swap_unsym<complex<float> >(const int n, complex<float> *a, |
| 749 |
const int lda, |
| 750 |
const int k, const int km, |
| 751 |
complex<float> *col_k, |
| 752 |
complex<float> *col_km); |
| 753 |
|
| 754 |
template |
| 755 |
void swap_unsym<quadruple>(const int n, quadruple *a, const int lda, |
| 756 |
const int k, const int km, |
| 757 |
quadruple *col_k, quadruple *col_km); |
| 758 |
|
| 759 |
template |
| 760 |
void swap_unsym<complex<quadruple> >(const int n, complex<quadruple> *a, |
| 761 |
const int lda, |
| 762 |
const int k, const int km, |
| 763 |
complex<quadruple> *col_k, |
| 764 |
complex<quadruple> *col_km); |
| 765 |
// |
| 766 |
|
| 767 |
template<typename T> |
| 768 |
void swap_full(const int n, T *a, const int lda, |
| 769 |
const int k, const int ki, const int kj, T *coli, T *colj) |
| 770 |
{ |
| 771 |
for (int i = 0; i < n; i++) { |
| 772 |
coli[i] = a[i + k * lda]; // save lower column k |
| 773 |
colj[i] = a[i + kj * lda]; // save lower column km |
| 774 |
} |
| 775 |
for (int i = 0; i < n; i++) { |
| 776 |
a[i + kj * lda] = coli[i]; // save lower column km |
| 777 |
a[i + k * lda] = colj[i]; |
| 778 |
} |
| 779 |
for (int i = 0; i < n; i++) { |
| 780 |
coli[i] = a[k + i * lda]; // save lower column k |
| 781 |
colj[i] = a[ki + i * lda]; // save lower column km |
| 782 |
} |
| 783 |
for (int i = 0; i < n; i++) { |
| 784 |
a[ki + i * lda] = coli[i]; // save lower column km |
| 785 |
a[k + i * lda] = colj[i]; |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
template |
| 790 |
void swap_full<double>(const int n, double *a, const int lda, |
| 791 |
const int k, const int ki, const int kj, |
| 792 |
double *coli, double *colj); |
| 793 |
|
| 794 |
template |
| 795 |
void swap_full<complex<double> >(const int n, complex<double> *a, |
| 796 |
const int lda, |
| 797 |
const int k, const int ki, const int kj, |
| 798 |
complex<double> *coli, |
| 799 |
complex<double> *colj); |
| 800 |
template |
| 801 |
void swap_full<quadruple>(const int n, quadruple *a, const int lda, |
| 802 |
const int k, const int ki, const int kj, |
| 803 |
quadruple *coli, quadruple *colj); |
| 804 |
|
| 805 |
template |
| 806 |
void swap_full<complex<quadruple> >(const int n, complex<quadruple> *a, |
| 807 |
const int lda, |
| 808 |
const int k, const int ki, const int kj, |
| 809 |
complex<quadruple> *coli, |
| 810 |
complex<quadruple> *colj); |
| 811 |
|
| 812 |
template |
| 813 |
void swap_full<float>(const int n, float *a, const int lda, |
| 814 |
const int k, const int ki, const int kj, |
| 815 |
float *coli, float *colj); |
| 816 |
|
| 817 |
template |
| 818 |
void swap_full<complex<float> >(const int n, complex<float> *a, |
| 819 |
const int lda, |
| 820 |
const int k, const int ki, const int kj, |
| 821 |
complex<float> *coli, |
| 822 |
complex<float> *colj); |
| 823 |
// |
| 824 |
template<typename T> |
| 825 |
void full_ldlt(const int n, T *a, const int lda) |
| 826 |
{ |
| 827 |
T alpha; |
| 828 |
const T one(1.0); |
| 829 |
const int lda1 = lda + 1; |
| 830 |
for (int k = 0; k < (n - 1); k++) { |
| 831 |
T d = one / a[k * lda1]; |
| 832 |
a[k * lda1] = d; |
| 833 |
alpha = (-d); |
| 834 |
blas_syr<T>(CblasLower, (n - k - 1), alpha, |
| 835 |
&a[(k + 1) + k * lda], 1, |
| 836 |
&a[(k + 1) * lda1], lda); |
| 837 |
blas_scal<T>((n - k - 1), d, &a[(k + 1) + k * lda], 1); |
| 838 |
} |
| 839 |
// symmetrize |
| 840 |
for (int j = 1; j < n; j++) { |
| 841 |
for (int i = 0; i < j; i++) { |
| 842 |
a[i + j * lda] = a[j + i * lda]; |
| 843 |
} |
| 844 |
} |
| 845 |
a[(n - 1) * lda1] = one / a[(n - 1) * lda1]; |
| 846 |
} |
| 847 |
|
| 848 |
template |
| 849 |
void full_ldlt<double>(const int n, double *a, const int lda); |
| 850 |
|
| 851 |
template |
| 852 |
void full_ldlt<quadruple>(const int n, quadruple *a, const int lda); |
| 853 |
|
| 854 |
template |
| 855 |
void full_ldlt<float>(const int n, float *a, const int lda); |
| 856 |
|
| 857 |
|
| 858 |
#ifndef NO_OCTRUPLE |
| 859 |
template |
| 860 |
void full_ldlt<octruple>(const int n, octruple *a, const int lda); |
| 861 |
#endif |
| 862 |
template |
| 863 |
void full_ldlt<complex<double> >(const int n, |
| 864 |
complex<double> *a, const int lda); |
| 865 |
|
| 866 |
template |
| 867 |
void full_ldlt<complex<quadruple> >(const int n, |
| 868 |
complex<quadruple> *a, const int lda); |
| 869 |
template |
| 870 |
void full_ldlt<complex<float> >(const int n, |
| 871 |
complex<float> *a, const int lda); |
| 872 |
|
| 873 |
|
| 874 |
#ifndef NO_OCTRUPLE |
| 875 |
template |
| 876 |
void full_ldlt<complex<octruple> >(const int n, |
| 877 |
complex<octruple> *a, const int lda); |
| 878 |
#endif |
| 879 |
// |
| 880 |
|
| 881 |
template<typename T> |
| 882 |
void full_ldlh(const int n, T *a, const int lda) |
| 883 |
{ |
| 884 |
T alpha; |
| 885 |
const T one(1.0); |
| 886 |
const int lda1 = lda + 1; |
| 887 |
for (int k = 0; k < (n - 1); k++) { |
| 888 |
const T d = one / a[k * lda1]; |
| 889 |
alpha = (-d); |
| 890 |
a[k * lda1] = d; |
| 891 |
blas_syrc<T>(CblasLower, (n - k - 1), alpha, |
| 892 |
&a[(k + 1) + k * lda], 1, |
| 893 |
&a[(k + 1) * lda1], lda); |
| 894 |
blas_scal<T>((n - k - 1), d, &a[(k + 1) + k * lda], 1); |
| 895 |
} |
| 896 |
// symmetrize |
| 897 |
for (int j = 1; j < n; j++) { |
| 898 |
for (int i = 0; i < j; i++) { |
| 899 |
a[i + j * lda] = std::conj(a[j + i * lda]); |
| 900 |
} |
| 901 |
} |
| 902 |
a[(n - 1) * lda1] = one / a[(n - 1) * lda1]; |
| 903 |
} |
| 904 |
|
| 905 |
template<> |
| 906 |
void full_ldlh<double>(const int n, double *a, const int lda) |
| 907 |
{ |
| 908 |
full_ldlt<double>(n, a, lda); |
| 909 |
} |
| 910 |
|
| 911 |
template<> |
| 912 |
void full_ldlh<quadruple>(const int n, quadruple *a, const int lda) |
| 913 |
{ |
| 914 |
full_ldlt<quadruple>(n, a, lda); |
| 915 |
} |
| 916 |
|
| 917 |
template<> |
| 918 |
void full_ldlh<float>(const int n, float *a, const int lda) |
| 919 |
{ |
| 920 |
full_ldlt<float>(n, a, lda); |
| 921 |
} |
| 922 |
|
| 923 |
#ifndef NO_OCTRUPLE |
| 924 |
template<> |
| 925 |
void full_ldlh<octruple>(const int n, octruple *a, const int lda) |
| 926 |
{ |
| 927 |
full_ldlt<octruple>(n, a, lda); |
| 928 |
} |
| 929 |
#endif |
| 930 |
template |
| 931 |
void full_ldlh<complex<double> >(const int n, |
| 932 |
complex<double> *a, const int lda); |
| 933 |
|
| 934 |
template |
| 935 |
void full_ldlh<complex<quadruple> >(const int n, |
| 936 |
complex<quadruple> *a, const int lda); |
| 937 |
|
| 938 |
template |
| 939 |
void full_ldlh<complex<float> >(const int n, |
| 940 |
complex<float> *a, const int lda); |
| 941 |
|
| 942 |
#ifndef NO_OCTRUPLE |
| 943 |
template |
| 944 |
void full_ldlh<complex<octruple> >(const int n, |
| 945 |
complex<octruple> *a, const int lda); |
| 946 |
#endif |
| 947 |
// |
| 948 |
|
| 949 |
template<typename T> |
| 950 |
void full_ldu(const int n, T *a, const int lda) |
| 951 |
{ |
| 952 |
const int lda1 = lda + 1; |
| 953 |
const T one(1.0); |
| 954 |
const T none(-1.0); |
| 955 |
// alpha = none; |
| 956 |
for (int k = 0; k < (n - 1); k++) { |
| 957 |
const T d = one / a[k * lda1]; |
| 958 |
a[k * lda1] = d; |
| 959 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + lda], lda); |
| 960 |
blas_ger<T>((n - k - 1), (n - k - 1), none, |
| 961 |
&a[k * lda1 + 1], 1, |
| 962 |
&a[k * lda1 + lda], lda, |
| 963 |
&a[(k + 1) * lda1], lda); |
| 964 |
blas_scal<T>((n - k - 1), d, &a[k * lda1 + 1], 1); |
| 965 |
} |
| 966 |
a[(n - 1) * lda1] = one / a[(n - 1) * lda1]; |
| 967 |
} |
| 968 |
|
| 969 |
template |
| 970 |
void full_ldu<double>(const int n, double *a, const int lda); |
| 971 |
|
| 972 |
template |
| 973 |
void full_ldu<quadruple>(const int n, quadruple *a, const int lda); |
| 974 |
|
| 975 |
template |
| 976 |
void full_ldu<float>(const int n, float *a, const int lda); |
| 977 |
|
| 978 |
|
| 979 |
#ifndef NO_OCTRUPLE |
| 980 |
template |
| 981 |
void full_ldu<octruple>(const int n, octruple *a, const int lda); |
| 982 |
#endif |
| 983 |
template |
| 984 |
void full_ldu<complex<double> >(const int n, |
| 985 |
complex<double> *a, const int lda); |
| 986 |
|
| 987 |
template |
| 988 |
void full_ldu<complex<quadruple> >(const int n, |
| 989 |
complex<quadruple> *a, const int lda); |
| 990 |
template |
| 991 |
void full_ldu<complex<float> >(const int n, |
| 992 |
complex<float> *a, const int lda); |
| 993 |
|
| 994 |
#ifndef NO_OCTRUPLE |
| 995 |
template |
| 996 |
void full_ldu<complex<octruple> >(const int n, |
| 997 |
complex<octruple> *a, const int lda); |
| 998 |
#endif |
| 999 |
// |
| 1000 |
|
| 1001 |
template<typename T> |
| 1002 |
void FillUpperBlock(const int nrow, T *coef, |
| 1003 |
const int *prow, |
| 1004 |
const int *indcols, const int *indvals, |
| 1005 |
const int *old2new_i, const int *old2new_j, |
| 1006 |
ColumnMatrix<T> &b) |
| 1007 |
{ |
| 1008 |
for (int i = 0; i < nrow; i++) { |
| 1009 |
const int ii = old2new_i[i]; |
| 1010 |
for (int k = prow[ii]; k < prow[ii + 1]; k++) { |
| 1011 |
const int jj = old2new_j[indcols[k]]; |
| 1012 |
b(ii, jj) = coef[indvals[k]]; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
template |
| 1018 |
void FillUpperBlock<double>(const int nnz, double *coef, const int *prow1, |
| 1019 |
const int *indcols1, const int *indvals1, |
| 1020 |
const int *new2old, const int *old_j, |
| 1021 |
ColumnMatrix<double> &b); |
| 1022 |
template |
| 1023 |
void FillUpperBlock<complex<double> >(const int nnz, complex<double> *coef, |
| 1024 |
const int *prow1, |
| 1025 |
const int *indcols1, const int *indvals1, |
| 1026 |
const int *new2old, const int *old_j, |
| 1027 |
ColumnMatrix<complex<double> > &b); |
| 1028 |
template |
| 1029 |
void FillUpperBlock<quadruple>(const int nnz, quadruple *coef, const int *prow1, |
| 1030 |
const int *indcols1, const int *indvals1, |
| 1031 |
const int *new2old, const int *old_j, |
| 1032 |
ColumnMatrix<quadruple> &b); |
| 1033 |
template |
| 1034 |
void FillUpperBlock<complex<quadruple> >(const int nnz, |
| 1035 |
complex<quadruple> *coef, |
| 1036 |
const int *prow1, |
| 1037 |
const int *indcols1, |
| 1038 |
const int *indvals1, |
| 1039 |
const int *new2old, const int *old_j, |
| 1040 |
ColumnMatrix<complex<quadruple> > &b); |
| 1041 |
template |
| 1042 |
void FillUpperBlock<float>(const int nnz, float *coef, const int *prow1, |
| 1043 |
const int *indcols1, const int *indvals1, |
| 1044 |
const int *new2old, const int *old_j, |
| 1045 |
ColumnMatrix<float> &b); |
| 1046 |
template |
| 1047 |
void FillUpperBlock<complex<float> >(const int nnz, complex<float> *coef, |
| 1048 |
const int *prow1, |
| 1049 |
const int *indcols1, const int *indvals1, |
| 1050 |
const int *new2old, const int *old_j, |
| 1051 |
ColumnMatrix<complex<float> > &b); |
| 1052 |
|
| 1053 |
// |
| 1054 |
|
| 1055 |
template<typename T> |
| 1056 |
void full_fw_multiprofile(bool isTransposed, const int nrow, const int n0, |
| 1057 |
const int ncol, |
| 1058 |
T *a, const int lda, |
| 1059 |
T *y, const int ldy, |
| 1060 |
vector<int> &i0, double *fop) |
| 1061 |
{ |
| 1062 |
const T one(1.0); |
| 1063 |
const T zero(0.0); |
| 1064 |
int jlast; |
| 1065 |
const int n1 = nrow - n0; |
| 1066 |
list<int> j1; |
| 1067 |
for (int j = 0; j < (ncol - 1); j++) { |
| 1068 |
if (i0[j] < i0[j + 1]) { |
| 1069 |
j1.push_back(j); |
| 1070 |
} |
| 1071 |
} |
| 1072 |
j1.push_back(ncol - 1); |
| 1073 |
jlast = (-1); |
| 1074 |
for (list<int>::const_iterator jt = j1.begin(); jt != j1.end(); ++jt) { |
| 1075 |
const int width = (*jt) - jlast; |
| 1076 |
const int ioffset = i0[(*jt)]; |
| 1077 |
const int height = nrow - ioffset - n0; |
| 1078 |
if (height > 0) { |
| 1079 |
if (width > 1) { |
| 1080 |
blas_trsm<T>(CblasLeft, |
| 1081 |
(isTransposed ? CblasUpper : CblasLower), |
| 1082 |
(isTransposed ? CblasTrans : CblasNoTrans), |
| 1083 |
CblasUnit, height, width, |
| 1084 |
one, |
| 1085 |
a + (ioffset * (nrow + 1)), nrow, |
| 1086 |
y + (ioffset + (jlast + 1) * ldy), ldy); |
| 1087 |
*fop += (double)height * (double)(height - 1) * (double)width; |
| 1088 |
} |
| 1089 |
else { |
| 1090 |
blas_trsv<T>((isTransposed ? CblasUpper : CblasLower), |
| 1091 |
(isTransposed ? CblasTrans : CblasNoTrans), |
| 1092 |
CblasUnit, height, |
| 1093 |
a + (ioffset * (nrow + 1)), nrow, |
| 1094 |
y + (ioffset + (jlast + 1) * ldy), 1); |
| 1095 |
*fop += (double)height * (double)(height - 1); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
jlast = (*jt); |
| 1099 |
} // loop : jt |
| 1100 |
for (int j = 0; j < ncol; j++) { |
| 1101 |
for (int i = n1; i < nrow; i++) { |
| 1102 |
y[i + j * ldy] = zero; |
| 1103 |
} |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
template |
| 1108 |
void full_fw_multiprofile<double>(bool isTransposed, const int nrow, |
| 1109 |
const int n0, |
| 1110 |
const int ncol, |
| 1111 |
double *a, const int lda, |
| 1112 |
double *y, const int ldy, |
| 1113 |
vector<int> &i0, double *fop); |
| 1114 |
|
| 1115 |
template |
| 1116 |
void full_fw_multiprofile<complex<double> >(bool isTransposed, const int nrow, |
| 1117 |
const int n0, |
| 1118 |
const int ncol, |
| 1119 |
complex<double> *a, |
| 1120 |
const int lda, |
| 1121 |
complex<double> *y, const int ldy, |
| 1122 |
vector<int> &i0, double *fop); |
| 1123 |
|
| 1124 |
template |
| 1125 |
void full_fw_multiprofile<quadruple>(bool isTransposed, const int nrow, |
| 1126 |
const int n0, |
| 1127 |
const int ncol, |
| 1128 |
quadruple *a, |
| 1129 |
const int lda, |
| 1130 |
quadruple *y, const int ldy, |
| 1131 |
vector<int> &i0, double *fop); |
| 1132 |
|
| 1133 |
template |
| 1134 |
void full_fw_multiprofile<complex<quadruple> >(bool isTransposed, |
| 1135 |
const int nrow, |
| 1136 |
const int n0, |
| 1137 |
const int ncol, |
| 1138 |
complex<quadruple> *a, |
| 1139 |
const int lda, |
| 1140 |
complex<quadruple> *y, |
| 1141 |
const int ldy, |
| 1142 |
vector<int> &i0, double *fop); |
| 1143 |
|
| 1144 |
template |
| 1145 |
void full_fw_multiprofile<float>(bool isTransposed, const int nrow, |
| 1146 |
const int n0, |
| 1147 |
const int ncol, |
| 1148 |
float *a, const int lda, |
| 1149 |
float *y, const int ldy, |
| 1150 |
vector<int> &i0, double *fop); |
| 1151 |
|
| 1152 |
template |
| 1153 |
void full_fw_multiprofile<complex<float> >(bool isTransposed, const int nrow, |
| 1154 |
const int n0, |
| 1155 |
const int ncol, |
| 1156 |
complex<float> *a, |
| 1157 |
const int lda, |
| 1158 |
complex<float> *y, const int ldy, |
| 1159 |
vector<int> &i0, double *fop); |
| 1160 |
// |
| 1161 |
|
| 1162 |
template<typename T> |
| 1163 |
void full_fw_multi(bool isTransposed, const int nrow, const int n0, |
| 1164 |
T *a, const int lda, |
| 1165 |
const int ncol, |
| 1166 |
T *y, const int ldy, |
| 1167 |
double *fop) |
| 1168 |
{ |
| 1169 |
const T one(1.0); |
| 1170 |
const T zero(0.0); |
| 1171 |
const int n1 = nrow - n0; |
| 1172 |
// alpha = 1.0 |
| 1173 |
// symmetric matrix should have upper part by symmeterization : LDL^t |
| 1174 |
blas_trsm<T>(CblasLeft, |
| 1175 |
(isTransposed ? CblasUpper : CblasLower), |
| 1176 |
(isTransposed ? CblasTrans : CblasNoTrans), |
| 1177 |
CblasUnit, n1, ncol, |
| 1178 |
one, a, lda, y, ldy); |
| 1179 |
*fop += (double)nrow * (double)(nrow - 1) * (double)ncol; |
| 1180 |
for (int j = 0; j < ncol; j++) { |
| 1181 |
for (int i = n1; i < nrow; i++) { |
| 1182 |
y[i + j * ldy] = zero; |
| 1183 |
} |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1187 |
template |
| 1188 |
void full_fw_multi<double>(bool isTransposed, const int nrow, const int n0, |
| 1189 |
double *a, const int lda, |
| 1190 |
const int ncol, |
| 1191 |
double *y, const int ldy, |
| 1192 |
double *fop); |
| 1193 |
|
| 1194 |
template |
| 1195 |
void full_fw_multi<complex<double> >(bool isTransposed, const int nrow, |
| 1196 |
const int n0, |
| 1197 |
complex<double> *a, const int lda, |
| 1198 |
const int ncol, |
| 1199 |
complex<double> *y, const int ldy, |
| 1200 |
double *fop); |
| 1201 |
|
| 1202 |
template |
| 1203 |
void full_fw_multi<quadruple>(bool isTransposed, const int nrow, const int n0, |
| 1204 |
quadruple *a, const int lda, |
| 1205 |
const int ncol, |
| 1206 |
quadruple *y, const int ldy, |
| 1207 |
double *fop); |
| 1208 |
|
| 1209 |
template |
| 1210 |
void full_fw_multi<complex<quadruple> >(bool isTransposed, const int nrow, |
| 1211 |
const int n0, |
| 1212 |
complex<quadruple> *a, const int lda, |
| 1213 |
const int ncol, |
| 1214 |
complex<quadruple> *y, const int ldy, |
| 1215 |
double *fop); |
| 1216 |
|
| 1217 |
template |
| 1218 |
void full_fw_multi<float>(bool isTransposed, const int nrow, const int n0, |
| 1219 |
float *a, const int lda, |
| 1220 |
const int ncol, |
| 1221 |
float *y, const int ldy, |
| 1222 |
double *fop); |
| 1223 |
|
| 1224 |
template |
| 1225 |
void full_fw_multi<complex<float> >(bool isTransposed, const int nrow, |
| 1226 |
const int n0, |
| 1227 |
complex<float> *a, const int lda, |
| 1228 |
const int ncol, |
| 1229 |
complex<float> *y, const int ldy, |
| 1230 |
double *fop); |
| 1231 |
|
| 1232 |
// |
| 1233 |
|
| 1234 |
template<typename T> |
| 1235 |
void full_fw_single(bool isTransposed, const int nrow, const int n0, |
| 1236 |
T *a, const int lda, |
| 1237 |
T *y, |
| 1238 |
double *fop) |
| 1239 |
{ |
| 1240 |
const T zero(0.0); |
| 1241 |
const int n1 = nrow - n0; |
| 1242 |
blas_trsv<T>((isTransposed ? CblasUpper : CblasLower), |
| 1243 |
(isTransposed ? CblasTrans : CblasNoTrans), |
| 1244 |
CblasUnit, n1, |
| 1245 |
a, lda, y, 1); |
| 1246 |
*fop += (double)nrow * (double)(nrow - 1); |
| 1247 |
for (int i = n1; i < nrow; i++) { |
| 1248 |
y[i] = zero; |
| 1249 |
} |
| 1250 |
} |
| 1251 |
|
| 1252 |
template |
| 1253 |
void full_fw_single<double>(bool isTransposed, const int nrow, const int n0, |
| 1254 |
double *a, const int lda, |
| 1255 |
double *y, |
| 1256 |
double *fop); |
| 1257 |
|
| 1258 |
template |
| 1259 |
void full_fw_single<complex<double> >(bool isTransposed, const int nrow, |
| 1260 |
const int n0, |
| 1261 |
complex<double> *a, const int lda, |
| 1262 |
complex<double> *y, |
| 1263 |
double *fop); |
| 1264 |
|
| 1265 |
template |
| 1266 |
void full_fw_single<quadruple>(bool isTransposed, const int nrow, const int n0, |
| 1267 |
quadruple *a, const int lda, |
| 1268 |
quadruple *y, |
| 1269 |
double *fop); |
| 1270 |
|
| 1271 |
template |
| 1272 |
void full_fw_single<complex<quadruple> >(bool isTransposed, const int nrow, |
| 1273 |
const int n0, |
| 1274 |
complex<quadruple> *a, const int lda, |
| 1275 |
complex<quadruple> *y, |
| 1276 |
double *fop); |
| 1277 |
|
| 1278 |
template |
| 1279 |
void full_fw_single<float>(bool isTransposed, const int nrow, const int n0, |
| 1280 |
float *a, const int lda, |
| 1281 |
float *y, |
| 1282 |
double *fop); |
| 1283 |
|
| 1284 |
template |
| 1285 |
void full_fw_single<complex<float> >(bool isTransposed, const int nrow, |
| 1286 |
const int n0, |
| 1287 |
complex<float> *a, const int lda, |
| 1288 |
complex<float> *y, |
| 1289 |
double *fop); |
| 1290 |
|
| 1291 |
// |
| 1292 |
|
| 1293 |
template<typename T> |
| 1294 |
void full_bw_single(bool isTransposed, const int nrow, const int n0, |
| 1295 |
T *a, const int lda, |
| 1296 |
T *y, |
| 1297 |
double *fop) |
| 1298 |
{ |
| 1299 |
const T zero(0.0); |
| 1300 |
const int n1 = nrow - n0; |
| 1301 |
blas_trsv<T>((isTransposed ? CblasLower : CblasUpper), |
| 1302 |
(isTransposed ? CblasTrans : CblasNoTrans), |
| 1303 |
CblasUnit, n1, |
| 1304 |
a, lda, y, 1); |
| 1305 |
*fop += (double)nrow * (double)(nrow - 1); |
| 1306 |
for (int i = n1; i < nrow; i++) { |
| 1307 |
y[i] = zero; |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
template |
| 1312 |
void full_bw_single<double>(bool isTransposed, const int nrow, const int n0, |
| 1313 |
double *a, const int lda, |
| 1314 |
double *y, |
| 1315 |
double *fop); |
| 1316 |
|
| 1317 |
template |
| 1318 |
void full_bw_single<complex<double> >(bool isTransposed, const int nrow, |
| 1319 |
const int n0, |
| 1320 |
complex<double> *a, const int lda, |
| 1321 |
complex<double> *y, |
| 1322 |
double *fop); |
| 1323 |
|
| 1324 |
template |
| 1325 |
void full_bw_single<quadruple>(bool isTransposed, const int nrow, const int n0, |
| 1326 |
quadruple *a, const int lda, |
| 1327 |
quadruple *y, |
| 1328 |
double *fop); |
| 1329 |
|
| 1330 |
template |
| 1331 |
void full_bw_single<complex<quadruple> >(bool isTransposed, const int nrow, |
| 1332 |
const int n0, |
| 1333 |
complex<quadruple> *a, const int lda, |
| 1334 |
complex<quadruple> *y, |
| 1335 |
double *fop); |
| 1336 |
|
| 1337 |
template |
| 1338 |
void full_bw_single<float>(bool isTransposed, const int nrow, const int n0, |
| 1339 |
float *a, const int lda, |
| 1340 |
float *y, |
| 1341 |
double *fop); |
| 1342 |
|
| 1343 |
template |
| 1344 |
void full_bw_single<complex<float> >(bool isTransposed, const int nrow, |
| 1345 |
const int n0, |
| 1346 |
complex<float> *a, const int lda, |
| 1347 |
complex<float> *y, |
| 1348 |
double *fop); |
| 1349 |
|
| 1350 |
// |
| 1351 |
|
| 1352 |
template<typename T> |
| 1353 |
void full_bw_multi(bool isTransposed, const int nrow, const int n0, |
| 1354 |
T *a, const int lda, |
| 1355 |
const int ncol, |
| 1356 |
T *y, const int ldy, |
| 1357 |
double *fop) |
| 1358 |
{ |
| 1359 |
const T one(1.0); |
| 1360 |
const T zero(0.0); |
| 1361 |
const int n1 = nrow - n0; |
| 1362 |
// alpha = 1.0 |
| 1363 |
// symmetric matrix should have upper part by symmeterization : LDL^t |
| 1364 |
blas_trsm<T>(CblasLeft, |
| 1365 |
(isTransposed ? CblasLower : CblasUpper), |
| 1366 |
(isTransposed ? CblasTrans : CblasNoTrans), |
| 1367 |
CblasUnit, n1, ncol, |
| 1368 |
one, a, lda, y, ldy); |
| 1369 |
*fop += (double)nrow * (double)(nrow - 1) * (double)ncol; |
| 1370 |
for (int j = 0; j < ncol; j++) { |
| 1371 |
for (int i = n1; i < nrow; i++) { |
| 1372 |
y[i + j * ldy] = zero; |
| 1373 |
} |
| 1374 |
} |
| 1375 |
} |
| 1376 |
|
| 1377 |
template |
| 1378 |
void full_bw_multi<double>(bool isTransposed, const int nrow, const int n0, |
| 1379 |
double *a, const int lda, |
| 1380 |
const int ncol, |
| 1381 |
double *y, const int ldy, |
| 1382 |
double *fop); |
| 1383 |
|
| 1384 |
template |
| 1385 |
void full_bw_multi<complex<double> >(bool isTransposed, const int nrow, |
| 1386 |
const int n0, |
| 1387 |
complex<double> *a, const int lda, |
| 1388 |
const int ncol, |
| 1389 |
complex<double> *y, const int ldy, |
| 1390 |
double *fop); |
| 1391 |
|
| 1392 |
template |
| 1393 |
void full_bw_multi<quadruple>(bool isTransposed, const int nrow, const int n0, |
| 1394 |
quadruple *a, const int lda, |
| 1395 |
const int ncol, |
| 1396 |
quadruple *y, const int ldy, |
| 1397 |
double *fop); |
| 1398 |
|
| 1399 |
template |
| 1400 |
void full_bw_multi<complex<quadruple> >(bool isTransposed, const int nrow, |
| 1401 |
const int n0, |
| 1402 |
complex<quadruple> *a, const int lda, |
| 1403 |
const int ncol, |
| 1404 |
complex<quadruple> *y, const int ldy, |
| 1405 |
double *fop); |
| 1406 |
|
| 1407 |
template |
| 1408 |
void full_bw_multi<float>(bool isTransposed, const int nrow, const int n0, |
| 1409 |
float *a, const int lda, |
| 1410 |
const int ncol, |
| 1411 |
float *y, const int ldy, |
| 1412 |
double *fop); |
| 1413 |
|
| 1414 |
template |
| 1415 |
void full_bw_multi<complex<float> >(bool isTransposed, const int nrow, |
| 1416 |
const int n0, |
| 1417 |
complex<float> *a, const int lda, |
| 1418 |
const int ncol, |
| 1419 |
complex<float> *y, const int ldy, |
| 1420 |
double *fop); |
| 1421 |
|
| 1422 |
// |
| 1423 |
|
| 1424 |
template<typename T> |
| 1425 |
void SparseSchur(const bool isSym, |
| 1426 |
const int dim2, const int dim1, |
| 1427 |
vector<int>& i0, |
| 1428 |
ColumnMatrix<T> &upper, |
| 1429 |
ColumnMatrix<T> &lower, |
| 1430 |
ColumnMatrix<T> &diag, |
| 1431 |
double *fop) |
| 1432 |
{ |
| 1433 |
const T zero(0.0); |
| 1434 |
const T none(-1.0); |
| 1435 |
// alpha = -1, beta = 0 |
| 1436 |
if (isSym) { |
| 1437 |
C_gemm_symm(dim2, dim1, none, |
| 1438 |
lower.addrCoefs(), dim1, |
| 1439 |
upper.addrCoefs(), dim1, zero, |
| 1440 |
diag.addrCoefs(), dim2); |
| 1441 |
// symmetrize : upper -> lower |
| 1442 |
for (int i = 0; i < dim2; i++) { |
| 1443 |
for (int j = 0; j < i; j++) { |
| 1444 |
diag(i, j) = diag(j, i); |
| 1445 |
} |
| 1446 |
} |
| 1447 |
} |
| 1448 |
else { |
| 1449 |
blas_gemm<T>(CblasTrans, CblasNoTrans, dim2, dim2, dim1, none, |
| 1450 |
lower.addrCoefs(), dim1, |
| 1451 |
upper.addrCoefs(), dim1, zero, |
| 1452 |
diag.addrCoefs(), dim2); |
| 1453 |
*fop = (double)dim2 * (double)dim2 * (double)dim1; |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
template |
| 1458 |
void SparseSchur<double>(const bool isSym, |
| 1459 |
const int dim2, const int dim1, vector<int>& i0, |
| 1460 |
ColumnMatrix<double> &upper, |
| 1461 |
ColumnMatrix<double> &lower, |
| 1462 |
ColumnMatrix<double> &diag, |
| 1463 |
double *fop); |
| 1464 |
|
| 1465 |
template |
| 1466 |
void SparseSchur<complex<double> >(const bool isSym, |
| 1467 |
const int dim2, const int dim1, |
| 1468 |
vector<int>& i0, |
| 1469 |
ColumnMatrix<complex<double> > &upper, |
| 1470 |
ColumnMatrix<complex<double> > &lower, |
| 1471 |
ColumnMatrix<complex<double> > &diag, |
| 1472 |
double *fop); |
| 1473 |
template |
| 1474 |
void SparseSchur<quadruple>(const bool isSym, |
| 1475 |
const int dim2, const int dim1, vector<int>& i0, |
| 1476 |
ColumnMatrix<quadruple> &upper, |
| 1477 |
ColumnMatrix<quadruple> &lower, |
| 1478 |
ColumnMatrix<quadruple> &diag, |
| 1479 |
double *fop); |
| 1480 |
|
| 1481 |
template |
| 1482 |
void SparseSchur<complex<quadruple> >(const bool isSym, |
| 1483 |
const int dim2, const int dim1, |
| 1484 |
vector<int>& i0, |
| 1485 |
ColumnMatrix<complex<quadruple> > &upper, |
| 1486 |
ColumnMatrix<complex<quadruple> > &lower, |
| 1487 |
ColumnMatrix<complex<quadruple> > &diag, |
| 1488 |
double *fop); |
| 1489 |
template |
| 1490 |
void SparseSchur<float>(const bool isSym, |
| 1491 |
const int dim2, const int dim1, vector<int>& i0, |
| 1492 |
ColumnMatrix<float> &upper, |
| 1493 |
ColumnMatrix<float> &lower, |
| 1494 |
ColumnMatrix<float> &diag, |
| 1495 |
double *fop); |
| 1496 |
|
| 1497 |
template |
| 1498 |
void SparseSchur<complex<float> >(const bool isSym, |
| 1499 |
const int dim2, const int dim1, |
| 1500 |
vector<int>& i0, |
| 1501 |
ColumnMatrix<complex<float> > &upper, |
| 1502 |
ColumnMatrix<complex<float> > &lower, |
| 1503 |
ColumnMatrix<complex<float> > &diag, |
| 1504 |
double *fop); |
| 1505 |
|
| 1506 |
// |
| 1507 |
|
| 1508 |
template<typename T> |
| 1509 |
void full_fwbw_single(const bool isTrans, const int n, const int n0, |
| 1510 |
T *a, const int lda, T *z) |
| 1511 |
{ |
| 1512 |
const T zero(0.0); |
| 1513 |
const int n1 = n - n0; |
| 1514 |
for (int i = n1; i < n; i++) { |
| 1515 |
z[i] = zero; |
| 1516 |
} |
| 1517 |
blas_trsv<T>((isTrans ? CblasUpper : CblasLower), |
| 1518 |
(isTrans ? CblasTrans : CblasNoTrans), CblasUnit, |
| 1519 |
n1, a, lda, z, 1); |
| 1520 |
for (int i = 0; i < n1; i++) { |
| 1521 |
z[i] *= a[i * (n + 1)]; |
| 1522 |
} |
| 1523 |
blas_trsv<T>((isTrans ? CblasLower : CblasUpper), |
| 1524 |
(isTrans ? CblasTrans : CblasNoTrans), CblasUnit, |
| 1525 |
n1, a, lda, z, 1); |
| 1526 |
} |
| 1527 |
|
| 1528 |
template |
| 1529 |
void full_fwbw_single<double>(const bool isTrans, const int n, const int n0, |
| 1530 |
double *a, const int lda, |
| 1531 |
double *z); |
| 1532 |
|
| 1533 |
template |
| 1534 |
void full_fwbw_single<complex<double> >(const bool isTrans, const int n, |
| 1535 |
const int n0, complex<double> *a, |
| 1536 |
const int lda, |
| 1537 |
complex<double> *z); |
| 1538 |
|
| 1539 |
template |
| 1540 |
void full_fwbw_single<quadruple>(const bool isTrans, const int n, const int n0, |
| 1541 |
quadruple *a, const int lda, |
| 1542 |
quadruple *z); |
| 1543 |
|
| 1544 |
template |
| 1545 |
void full_fwbw_single<complex<quadruple> >(const bool isTrans, const int n, |
| 1546 |
const int n0, complex<quadruple> *a, |
| 1547 |
const int lda, |
| 1548 |
complex<quadruple> *z); |
| 1549 |
template |
| 1550 |
void full_fwbw_single<float>(const bool isTrans, const int n, const int n0, |
| 1551 |
float *a, const int lda, |
| 1552 |
float *z); |
| 1553 |
|
| 1554 |
template |
| 1555 |
void full_fwbw_single<complex<float> >(const bool isTrans, const int n, |
| 1556 |
const int n0, complex<float> *a, |
| 1557 |
const int lda, |
| 1558 |
complex<float> *z); |
| 1559 |
|
| 1560 |
// |
| 1561 |
|
| 1562 |
template<typename T> |
| 1563 |
void full_fwbw_multi(const bool isTrans, const int n, const int n0, |
| 1564 |
T *a, const int lda, |
| 1565 |
const int m, T *x, const int ldx) |
| 1566 |
{ |
| 1567 |
const T one(1.0); |
| 1568 |
const T zero(0.0); |
| 1569 |
const int n1 = n - n0; |
| 1570 |
for (int j = 0; j < m; j++) { |
| 1571 |
for (int i = n1; i < n; i++) { |
| 1572 |
x[i + j * ldx] = zero; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
// alpha = 1.0 |
| 1576 |
blas_trsm<T>(CblasLeft, |
| 1577 |
(isTrans ? CblasUpper : CblasLower), |
| 1578 |
(isTrans ? CblasTrans : CblasNoTrans), CblasUnit, |
| 1579 |
n1, m, one, a, lda, |
| 1580 |
x, ldx); |
| 1581 |
for (int j = 0; j < m; j++) { |
| 1582 |
for (int i = 0; i < n1; i++) { |
| 1583 |
// x[i + j * ldx] *= a[i * (n + 1)]; // 3 Nov.2015 |
| 1584 |
x[i + j * ldx] *= a[i * (lda + 1)]; // 3 Nov.2015 |
| 1585 |
} |
| 1586 |
} |
| 1587 |
blas_trsm<T>(CblasLeft, |
| 1588 |
(isTrans ? CblasLower : CblasUpper), |
| 1589 |
(isTrans ? CblasTrans: CblasNoTrans), CblasUnit, |
| 1590 |
n1, m, one, a, lda, |
| 1591 |
x, ldx); |
| 1592 |
} |
| 1593 |
|
| 1594 |
template |
| 1595 |
void full_fwbw_multi<double>(const bool isTrans, |
| 1596 |
const int n, const int n0, |
| 1597 |
double *a, const int lda, |
| 1598 |
const int m, double *x, const int ldx); |
| 1599 |
|
| 1600 |
template |
| 1601 |
void full_fwbw_multi<complex<double> >(const bool isTrans, |
| 1602 |
const int n, const int n0, |
| 1603 |
complex<double> *a, const int lda, |
| 1604 |
const int m, complex<double> *x, |
| 1605 |
const int ldx); |
| 1606 |
|
| 1607 |
template |
| 1608 |
void full_fwbw_multi<quadruple>(const bool isTrans, |
| 1609 |
const int n, const int n0, |
| 1610 |
quadruple *a, const int lda, |
| 1611 |
const int m, quadruple *x, const int ldx); |
| 1612 |
|
| 1613 |
template |
| 1614 |
void full_fwbw_multi<complex<quadruple> >(const bool isTrans, |
| 1615 |
const int n, const int n0, |
| 1616 |
complex<quadruple> *a, const int lda, |
| 1617 |
const int m, complex<quadruple> *x, |
| 1618 |
const int ldx); |
| 1619 |
template |
| 1620 |
void full_fwbw_multi<float>(const bool isTrans, |
| 1621 |
const int n, const int n0, |
| 1622 |
float *a, const int lda, |
| 1623 |
const int m, float *x, const int ldx); |
| 1624 |
|
| 1625 |
template |
| 1626 |
void full_fwbw_multi<complex<float> >(const bool isTrans, |
| 1627 |
const int n, const int n0, |
| 1628 |
complex<float> *a, const int lda, |
| 1629 |
const int m, complex<float> *x, |
| 1630 |
const int ldx); |
| 1631 |
|
| 1632 |
// |
| 1633 |
|
| 1634 |
template<typename T> |
| 1635 |
void full_fwbw_part(const int n, T *a, const int lda, T*x) |
| 1636 |
{ |
| 1637 |
int ifirst; |
| 1638 |
const T zero(0.0); |
| 1639 |
ifirst = n; |
| 1640 |
for (int i = 0; i < n; i++) { |
| 1641 |
if (x[i] != zero) { |
| 1642 |
ifirst = i; |
| 1643 |
break; |
| 1644 |
} |
| 1645 |
} |
| 1646 |
if (ifirst == n) { |
| 1647 |
return; |
| 1648 |
} |
| 1649 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, (n - ifirst), |
| 1650 |
&a[ifirst * (lda + 1)], lda, |
| 1651 |
&x[ifirst], 1); |
| 1652 |
for (int i = ifirst; i < n; i++) { |
| 1653 |
x[i] *= a[i * (lda + 1)]; |
| 1654 |
} |
| 1655 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, n, |
| 1656 |
a, lda, |
| 1657 |
x, 1); |
| 1658 |
} |
| 1659 |
|
| 1660 |
template |
| 1661 |
void full_fwbw_part<double>(const int n, |
| 1662 |
double *a, const int lda, double *x); |
| 1663 |
|
| 1664 |
template |
| 1665 |
void full_fwbw_part<quadruple>(const int n, |
| 1666 |
quadruple *a, const int lda, quadruple *x); |
| 1667 |
|
| 1668 |
template |
| 1669 |
void full_fwbw_part<float>(const int n, |
| 1670 |
float *a, const int lda, float *x); |
| 1671 |
|
| 1672 |
|
| 1673 |
#ifndef NO_OCTRUPLE |
| 1674 |
template |
| 1675 |
void full_fwbw_part<octruple>(const int n, |
| 1676 |
octruple *a, const int lda, octruple *x); |
| 1677 |
#endif |
| 1678 |
template |
| 1679 |
void full_fwbw_part<complex<double> >(const int n, |
| 1680 |
complex<double> *a, const int lda, |
| 1681 |
complex<double> *x); |
| 1682 |
|
| 1683 |
template |
| 1684 |
void full_fwbw_part<complex<quadruple> >(const int n, |
| 1685 |
complex<quadruple> *a, |
| 1686 |
const int lda, |
| 1687 |
complex<quadruple> *x); |
| 1688 |
template |
| 1689 |
void full_fwbw_part<complex<float> >(const int n, |
| 1690 |
complex<float> *a, const int lda, |
| 1691 |
complex<float> *x); |
| 1692 |
|
| 1693 |
#ifndef NO_OCTRUPLE |
| 1694 |
template |
| 1695 |
void full_fwbw_part<complex<octruple> >(const int n, |
| 1696 |
complex<octruple> *a, |
| 1697 |
const int lda, |
| 1698 |
complex<octruple> *x); |
| 1699 |
#endif |
| 1700 |
// |
| 1701 |
|
| 1702 |
template<typename T> |
| 1703 |
void SchurProfileSym(const int nrow, const int ncol, vector<int> &i0, |
| 1704 |
ColumnMatrix<T> &b, ColumnMatrix<T> &c, |
| 1705 |
T *s, const int size_b1, double *fop) |
| 1706 |
{ |
| 1707 |
const T one(1.0); |
| 1708 |
const T zero(0.0); |
| 1709 |
#if 1 |
| 1710 |
const int num_block = ncol / size_b1 + ((ncol % size_b1) == 0 ? 0 : 1); |
| 1711 |
for (int j = 0; j < num_block; j++) { |
| 1712 |
const int jj = j * size_b1; |
| 1713 |
for (int i = 0; i < j; i++) { |
| 1714 |
const int ii = i * size_b1; |
| 1715 |
const int nrowb = std::min<int>(size_b1, ncol - ii); |
| 1716 |
const int ncolb = std::min<int>(size_b1, ncol - jj); |
| 1717 |
const int ioffset = std::max<int>(i0[ii], i0[jj]); |
| 1718 |
//const int ioffset = 0; |
| 1719 |
const int nnrow = nrow - ioffset; |
| 1720 |
// alpha = 1 |
| 1721 |
// beta = 0 |
| 1722 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 1723 |
nrowb, ncolb, |
| 1724 |
nnrow, |
| 1725 |
one, |
| 1726 |
c.addrCoefs() + (ioffset + ii * nrow), |
| 1727 |
nrow, |
| 1728 |
b.addrCoefs() + (ioffset + jj * nrow), |
| 1729 |
nrow, |
| 1730 |
zero, |
| 1731 |
s + (ii + jj * ncol), |
| 1732 |
ncol); |
| 1733 |
*fop += (double)nrowb * (double)ncolb * (double) nnrow; |
| 1734 |
} |
| 1735 |
{ |
| 1736 |
const int nrowb = std::min<int>(size_b1, ncol - jj); |
| 1737 |
const int ioffset = i0[jj]; |
| 1738 |
//const int ioffset = 0; |
| 1739 |
const int nnrow = nrow - ioffset; |
| 1740 |
// alpha = 1 |
| 1741 |
// beta = 0 |
| 1742 |
if (nnrow == 0) { |
| 1743 |
// clear upper entries |
| 1744 |
for (int j = 0; j < nrowb; j++) { |
| 1745 |
for (int i = 0; i <= j; i++) { |
| 1746 |
s[i + j * ncol + jj * (ncol + 1)] = zero; |
| 1747 |
} |
| 1748 |
} |
| 1749 |
} |
| 1750 |
else { |
| 1751 |
C_gemm_symm<T>(nrowb, |
| 1752 |
nnrow, |
| 1753 |
one, |
| 1754 |
c.addrCoefs() + (ioffset + jj * nrow), |
| 1755 |
nrow, |
| 1756 |
b.addrCoefs() + (ioffset + jj * nrow), |
| 1757 |
nrow, |
| 1758 |
zero, |
| 1759 |
s + (jj * (ncol + 1)), |
| 1760 |
ncol); |
| 1761 |
} |
| 1762 |
*fop += (double)nrowb * (double)nrowb * (double) nnrow / 2.0; |
| 1763 |
} |
| 1764 |
} // loop : j |
| 1765 |
#else // debug : compute all entries |
| 1766 |
// alpha = 1 |
| 1767 |
// beta = 0 |
| 1768 |
// blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 1769 |
// ncol, ncol, |
| 1770 |
C_gemm_symm<T>(ncol, |
| 1771 |
nrow, |
| 1772 |
one, |
| 1773 |
c.addrCoefs(), |
| 1774 |
nrow, |
| 1775 |
b.addrCoefs(), |
| 1776 |
nrow, |
| 1777 |
zero, |
| 1778 |
s, |
| 1779 |
ncol); |
| 1780 |
*fop += (double)ncol * (double)ncol * (double) nrow; |
| 1781 |
#endif |
| 1782 |
} |
| 1783 |
|
| 1784 |
template |
| 1785 |
void SchurProfileSym<double>(const int nrow, const int ncol, |
| 1786 |
vector<int> &i0, |
| 1787 |
ColumnMatrix<double> &b, |
| 1788 |
ColumnMatrix<double> &c, |
| 1789 |
double *s, |
| 1790 |
const int size_b1, |
| 1791 |
double *fop); |
| 1792 |
|
| 1793 |
template |
| 1794 |
void SchurProfileSym<complex<double> >(const int nrow, const int ncol, |
| 1795 |
vector<int> &i0, |
| 1796 |
ColumnMatrix<complex<double> > &b, |
| 1797 |
ColumnMatrix<complex<double> > &c, |
| 1798 |
complex<double> *s, |
| 1799 |
const int size_b1, |
| 1800 |
double *fop); |
| 1801 |
template |
| 1802 |
void SchurProfileSym<quadruple>(const int nrow, const int ncol, |
| 1803 |
vector<int> &i0, |
| 1804 |
ColumnMatrix<quadruple> &b, |
| 1805 |
ColumnMatrix<quadruple> &c, |
| 1806 |
quadruple *s, |
| 1807 |
const int size_b1, |
| 1808 |
double *fop); |
| 1809 |
|
| 1810 |
template |
| 1811 |
void SchurProfileSym<complex<quadruple> >(const int nrow, const int ncol, |
| 1812 |
vector<int> &i0, |
| 1813 |
ColumnMatrix<complex<quadruple> > &b, |
| 1814 |
ColumnMatrix<complex<quadruple> > &c, |
| 1815 |
complex<quadruple> *s, |
| 1816 |
const int size_b1, |
| 1817 |
double *fop); |
| 1818 |
|
| 1819 |
template |
| 1820 |
void SchurProfileSym<float>(const int nrow, const int ncol, |
| 1821 |
vector<int> &i0, |
| 1822 |
ColumnMatrix<float> &b, |
| 1823 |
ColumnMatrix<float> &c, |
| 1824 |
float *s, |
| 1825 |
const int size_b1, |
| 1826 |
double *fop); |
| 1827 |
|
| 1828 |
template |
| 1829 |
void SchurProfileSym<complex<float> >(const int nrow, const int ncol, |
| 1830 |
vector<int> &i0, |
| 1831 |
ColumnMatrix<complex<float> > &b, |
| 1832 |
ColumnMatrix<complex<float> > &c, |
| 1833 |
complex<float> *s, |
| 1834 |
const int size_b1, |
| 1835 |
double *fop); |
| 1836 |
|
| 1837 |
// |
| 1838 |
|
| 1839 |
template<typename T> |
| 1840 |
void SchurProfileUnSym(const int nrow, const int ncol, vector<int> &i0, |
| 1841 |
ColumnMatrix<T> &b, ColumnMatrix<T> &c, |
| 1842 |
T* s, const int size_b1, double *fop) |
| 1843 |
{ |
| 1844 |
const T one(1.0); |
| 1845 |
const T zero(0.0); |
| 1846 |
const int num_block = ncol / size_b1 + (ncol % size_b1 == 0 ? 0 : 1); |
| 1847 |
for (int j = 0; j < num_block; j++) { |
| 1848 |
const int jj = j * size_b1; |
| 1849 |
for (int i = 0; i < num_block; i++) { |
| 1850 |
const int ii = i * size_b1; |
| 1851 |
const int nrowb = std::min<int>(size_b1, ncol - ii); |
| 1852 |
const int ncolb = std::min<int>(size_b1, ncol - jj); |
| 1853 |
const int ioffset = std::max<int>(i0[ii], i0[jj]); |
| 1854 |
const int nnrow = nrow - ioffset; |
| 1855 |
// alpha=1 |
| 1856 |
// beta=0 |
| 1857 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 1858 |
nrowb, ncolb, |
| 1859 |
nnrow, |
| 1860 |
one, |
| 1861 |
c.addrCoefs() + (ioffset + ii * nrow), |
| 1862 |
nrow, |
| 1863 |
b.addrCoefs() + (ioffset + jj * nrow), |
| 1864 |
nrow, |
| 1865 |
zero, |
| 1866 |
s + (ii + jj * ncol), |
| 1867 |
ncol); |
| 1868 |
*fop += (double)nrowb * (double)ncolb * (double) nnrow; |
| 1869 |
} |
| 1870 |
} |
| 1871 |
} |
| 1872 |
|
| 1873 |
template |
| 1874 |
void SchurProfileUnSym<double>(const int nrow, const int ncol, |
| 1875 |
vector<int> &i0, |
| 1876 |
ColumnMatrix<double> &b, |
| 1877 |
ColumnMatrix<double> &c, |
| 1878 |
double *s, const int size_b1, double *fop); |
| 1879 |
|
| 1880 |
template |
| 1881 |
void SchurProfileUnSym<complex<double> >(const int nrow, const int ncol, |
| 1882 |
vector<int> &i0, |
| 1883 |
ColumnMatrix<complex<double> > &b, |
| 1884 |
ColumnMatrix<complex<double> > &c, |
| 1885 |
complex<double> *s, const int size_b1, |
| 1886 |
double *fop); |
| 1887 |
template |
| 1888 |
void SchurProfileUnSym<quadruple>(const int nrow, const int ncol, |
| 1889 |
vector<int> &i0, |
| 1890 |
ColumnMatrix<quadruple> &b, |
| 1891 |
ColumnMatrix<quadruple> &c, |
| 1892 |
quadruple *s, const int size_b1, double *fop); |
| 1893 |
|
| 1894 |
template |
| 1895 |
void |
| 1896 |
SchurProfileUnSym<complex<quadruple> >(const int nrow, const int ncol, |
| 1897 |
vector<int> &i0, |
| 1898 |
ColumnMatrix<complex<quadruple> > &b, |
| 1899 |
ColumnMatrix<complex<quadruple> > &c, |
| 1900 |
complex<quadruple> *s, const int size_b1, |
| 1901 |
double *fop); |
| 1902 |
template |
| 1903 |
void SchurProfileUnSym<float>(const int nrow, const int ncol, |
| 1904 |
vector<int> &i0, |
| 1905 |
ColumnMatrix<float> &b, |
| 1906 |
ColumnMatrix<float> &c, |
| 1907 |
float *s, const int size_b1, double *fop); |
| 1908 |
|
| 1909 |
template |
| 1910 |
void SchurProfileUnSym<complex<float> >(const int nrow, const int ncol, |
| 1911 |
vector<int> &i0, |
| 1912 |
ColumnMatrix<complex<float> > &b, |
| 1913 |
ColumnMatrix<complex<float> > &c, |
| 1914 |
complex<float> *s, const int size_b1, |
| 1915 |
double *fop); |
| 1916 |
|
| 1917 |
// |
| 1918 |
|
| 1919 |
// Z for perturbation has lower precision than T (real or complex valued) |
| 1920 |
template<typename T, typename Z> |
| 1921 |
void full_fwbw_perturb_single(const int n, |
| 1922 |
T *a, const int lda, T *a_fact, T *x, |
| 1923 |
const int dim_augkern, const Z &eps, |
| 1924 |
bool flag_sym) |
| 1925 |
{ |
| 1926 |
// T alpha, beta; |
| 1927 |
// T *upper, *lower, *schur; |
| 1928 |
const T one(1.0); |
| 1929 |
const T none(-1.0); |
| 1930 |
const T Teps = conv_prec<T, Z>(eps); |
| 1931 |
int n1; |
| 1932 |
if (dim_augkern < n) { |
| 1933 |
n1 = n - dim_augkern; |
| 1934 |
} |
| 1935 |
else { |
| 1936 |
n1 = 0; |
| 1937 |
} |
| 1938 |
if (n1 > 0) { |
| 1939 |
ColumnMatrix<T> upper(dim_augkern, n1); // new T[dim_augkern * n1]; |
| 1940 |
ColumnMatrix<T> lower(dim_augkern, n1); // lower = new T[dim_augkern * n1]; |
| 1941 |
ColumnMatrix<T> schur(n1, n1); // = new T[n1 * n1]; |
| 1942 |
|
| 1943 |
// factorization with perturbation should be shared with both sing and multi |
| 1944 |
for (int j = 0; j < n1; j++) { |
| 1945 |
for (int i = 0; i < dim_augkern; i++) { |
| 1946 |
upper(i, j) = a[i + (j + dim_augkern) * lda]; |
| 1947 |
} |
| 1948 |
for (int i = 0; i < n1; i++) { |
| 1949 |
schur(i, j) = a[i + dim_augkern + (j + dim_augkern) * lda]; |
| 1950 |
} |
| 1951 |
} |
| 1952 |
{ |
| 1953 |
// alpha = one; |
| 1954 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 1955 |
dim_augkern, n1, one, a_fact, lda, |
| 1956 |
upper.addrCoefs(), dim_augkern); |
| 1957 |
for (int i = 0; i < dim_augkern; i++) { |
| 1958 |
for (int j = 0; j < n1; j++) { |
| 1959 |
upper(i, j) *= a_fact[i * (lda + 1)]; |
| 1960 |
} |
| 1961 |
} |
| 1962 |
// alphe = one; |
| 1963 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 1964 |
dim_augkern, n1, one, a_fact, lda, |
| 1965 |
upper.addrCoefs(), dim_augkern); |
| 1966 |
// emulating machine eplison in double |
| 1967 |
for (int j = 0; j < n1; j++) { |
| 1968 |
upper((dim_augkern - 1), j) += Teps; |
| 1969 |
} |
| 1970 |
} |
| 1971 |
if (!flag_sym) { |
| 1972 |
for (int j = 0; j < n1; j++) { |
| 1973 |
for (int i = 0; i < dim_augkern; i++) { |
| 1974 |
lower(i, j) = a[(j + dim_augkern) + i * lda]; |
| 1975 |
} |
| 1976 |
} |
| 1977 |
// alpha = one; |
| 1978 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasTrans, CblasUnit, |
| 1979 |
dim_augkern, n1, one, a_fact, lda, |
| 1980 |
lower.addrCoefs(), dim_augkern); |
| 1981 |
for (int i = 0; i < dim_augkern; i++) { |
| 1982 |
for (int j = 0; j < n1; j++) { |
| 1983 |
lower(i, j) *= a_fact[i * (lda + 1)]; |
| 1984 |
} |
| 1985 |
} |
| 1986 |
// alpha = one; |
| 1987 |
blas_trsm<T>(CblasLeft, CblasLower, CblasTrans, CblasUnit, |
| 1988 |
dim_augkern, n1, one, a_fact, lda, |
| 1989 |
lower.addrCoefs(), dim_augkern); |
| 1990 |
for (int j = 0; j < n1; j++) { |
| 1991 |
lower((dim_augkern - 1), j) += Teps; |
| 1992 |
} |
| 1993 |
} |
| 1994 |
// alpha = none; |
| 1995 |
// beta = one; |
| 1996 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, n1, n1, dim_augkern, |
| 1997 |
none, &a[dim_augkern], lda, |
| 1998 |
upper.addrCoefs(), dim_augkern, |
| 1999 |
one, schur.addrCoefs(), n1); |
| 2000 |
if (flag_sym) { |
| 2001 |
full_ldlt<T>(n1, schur.addrCoefs(), n1); |
| 2002 |
} |
| 2003 |
else { |
| 2004 |
full_ldu<T>(n1, schur.addrCoefs(), n1); |
| 2005 |
} |
| 2006 |
// alpha = none; |
| 2007 |
// beta = one; |
| 2008 |
if (flag_sym) { |
| 2009 |
blas_gemv<T>(CblasTrans, dim_augkern, n1, none, |
| 2010 |
upper.addrCoefs(), dim_augkern, |
| 2011 |
x, 1, one, &x[dim_augkern], 1); |
| 2012 |
} |
| 2013 |
else { |
| 2014 |
blas_gemv<T>(CblasTrans, dim_augkern, n1, none, |
| 2015 |
lower.addrCoefs(), dim_augkern, |
| 2016 |
x, 1, one, &x[dim_augkern], 1); |
| 2017 |
} |
| 2018 |
// forward |
| 2019 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, |
| 2020 |
dim_augkern, a_fact, lda, x, 1); |
| 2021 |
for (int j = 0; j < dim_augkern; j++) { |
| 2022 |
x[j] *= a_fact[j * (lda + 1)]; |
| 2023 |
} |
| 2024 |
// backward |
| 2025 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, |
| 2026 |
dim_augkern, a_fact, lda, x, 1); |
| 2027 |
// forward |
| 2028 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, |
| 2029 |
dim_augkern, schur.addrCoefs(), n1, &x[dim_augkern], 1); |
| 2030 |
// diagonal divide |
| 2031 |
for (int j = 0; j < n1; j++) { |
| 2032 |
x[j + dim_augkern] *= schur(j, j); //[j * (n1 + 1)]; |
| 2033 |
} |
| 2034 |
// backward |
| 2035 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, |
| 2036 |
dim_augkern, schur.addrCoefs(), n1, &x[dim_augkern], 1); |
| 2037 |
// alpha = none; |
| 2038 |
// beta = one; |
| 2039 |
blas_gemv<T>(CblasNoTrans, dim_augkern, n1, none, |
| 2040 |
upper.addrCoefs(), dim_augkern, |
| 2041 |
&x[dim_augkern], 1, one, x, 1); |
| 2042 |
} |
| 2043 |
else { |
| 2044 |
// forward |
| 2045 |
blas_trsv<T>(CblasLower, CblasNoTrans, CblasUnit, |
| 2046 |
n, a_fact, lda, x, 1); |
| 2047 |
for (int j = 0; j < n; j++) { |
| 2048 |
x[j] *= a_fact[j * (lda + 1)]; |
| 2049 |
} |
| 2050 |
x[(n - 1)] += Teps; |
| 2051 |
// backward |
| 2052 |
blas_trsv<T>(CblasUpper, CblasNoTrans, CblasUnit, |
| 2053 |
n, a_fact, lda, x, 1); |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
template |
| 2058 |
void full_fwbw_perturb_single<quadruple, double>(const int n, |
| 2059 |
quadruple *a, const int lda, |
| 2060 |
quadruple *a_fact, |
| 2061 |
quadruple *x, |
| 2062 |
const int dim_augkern, |
| 2063 |
const double &eps, |
| 2064 |
bool flag_sym); |
| 2065 |
|
| 2066 |
template |
| 2067 |
void full_fwbw_perturb_single<double, float>(const int n, |
| 2068 |
double *a, const int lda, |
| 2069 |
double *a_fact, |
| 2070 |
double *x, |
| 2071 |
const int dim_augkern, |
| 2072 |
const float &eps, |
| 2073 |
bool flag_sym); |
| 2074 |
|
| 2075 |
#ifndef NO_OCTRUPLE |
| 2076 |
template |
| 2077 |
void full_fwbw_perturb_single<octruple, quadruple>(const int n, |
| 2078 |
octruple *a, const int lda, |
| 2079 |
octruple *a_fact, |
| 2080 |
octruple *x, |
| 2081 |
const int dim_augkern, |
| 2082 |
const quadruple &eps, |
| 2083 |
bool flag_sym); |
| 2084 |
#endif |
| 2085 |
template |
| 2086 |
void full_fwbw_perturb_single<complex<quadruple>, |
| 2087 |
double>(const int n, |
| 2088 |
complex<quadruple> *a, const int lda, |
| 2089 |
complex<quadruple> *a_fact, |
| 2090 |
complex<quadruple> *x, |
| 2091 |
const int dim_augkern, |
| 2092 |
const double &eps, |
| 2093 |
bool flag_sym); |
| 2094 |
template |
| 2095 |
void full_fwbw_perturb_single<complex<double>, |
| 2096 |
float>(const int n, |
| 2097 |
complex<double> *a, const int lda, |
| 2098 |
complex<double> *a_fact, |
| 2099 |
complex<double> *x, |
| 2100 |
const int dim_augkern, |
| 2101 |
const float &eps, |
| 2102 |
bool flag_sym); |
| 2103 |
|
| 2104 |
#ifndef NO_OCTRUPLE |
| 2105 |
template |
| 2106 |
void full_fwbw_perturb_single<complex<octruple>, |
| 2107 |
quadruple>(const int n, |
| 2108 |
complex<octruple> *a, const int lda, |
| 2109 |
complex<octruple> *a_fact, |
| 2110 |
complex<octruple> *x, |
| 2111 |
const int dim_augkern, |
| 2112 |
const quadruple &eps, |
| 2113 |
bool flag_sym); |
| 2114 |
#endif |
| 2115 |
// |
| 2116 |
// Z for perturbation has lower precision than T (real or complex valued) |
| 2117 |
template<typename T, typename Z> |
| 2118 |
void full_fwbw_perturb_multi(const int n, const int m, |
| 2119 |
T *a, const int lda, T *a_fact, T *x, |
| 2120 |
const int dim_augkern, const Z &eps, bool flag_sym) |
| 2121 |
{ |
| 2122 |
// T alpha, beta; |
| 2123 |
// T *upper, *lower, *schur, *v; |
| 2124 |
const T one(1.0); |
| 2125 |
const T none(-1.0); |
| 2126 |
const T Teps = conv_prec<T, Z>(eps); |
| 2127 |
if (dim_augkern >= n) { |
| 2128 |
// forward |
| 2129 |
// alpha = one; |
| 2130 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 2131 |
n, m, one, a_fact, lda, x, lda); |
| 2132 |
for (int j = 0; j < m; j++) { |
| 2133 |
for (int i= 0; i < n; i++) { |
| 2134 |
x[i + j * lda] *= a_fact[i * (lda + 1)]; |
| 2135 |
} |
| 2136 |
x[(n - 1) + j * lda] += Teps; |
| 2137 |
} |
| 2138 |
// backward |
| 2139 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 2140 |
n, m, one, a_fact, lda, x, lda); |
| 2141 |
} |
| 2142 |
else { |
| 2143 |
const int n1 = n - dim_augkern; |
| 2144 |
ColumnMatrix<T> upper(dim_augkern, n1); |
| 2145 |
ColumnMatrix<T> lower(dim_augkern, n1); |
| 2146 |
ColumnMatrix<T> schur(n1, n1); |
| 2147 |
// factorization with perturbation should be shared with both sing and multi |
| 2148 |
for (int j = 0; j < n1; j++) { |
| 2149 |
for (int i = 0; i < dim_augkern; i++) { |
| 2150 |
upper(i, j) = a[i + (j + dim_augkern) * lda]; |
| 2151 |
} |
| 2152 |
for (int i = 0; i < n1; i++) { |
| 2153 |
schur(i, j) = a[i + dim_augkern + (j + dim_augkern) * lda]; |
| 2154 |
} |
| 2155 |
} |
| 2156 |
{ |
| 2157 |
// alpha = one; |
| 2158 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 2159 |
dim_augkern, n1, one, a_fact, lda, |
| 2160 |
upper.addrCoefs(), dim_augkern); |
| 2161 |
for (int i = 0; i < dim_augkern; i++) { |
| 2162 |
for (int j = 0; j < n1; j++) { |
| 2163 |
upper(i, j) *= a_fact[i * (lda + 1)]; |
| 2164 |
} |
| 2165 |
} |
| 2166 |
// alpha = one; |
| 2167 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 2168 |
dim_augkern, n1, one, a_fact, lda, |
| 2169 |
upper.addrCoefs(), dim_augkern); |
| 2170 |
for (int j = 0; j < n1; j++) { |
| 2171 |
upper((dim_augkern - 1), j) += Teps; |
| 2172 |
} |
| 2173 |
} |
| 2174 |
if (!flag_sym) { |
| 2175 |
for (int j = 0; j < n1; j++) { |
| 2176 |
for (int i = 0; i < dim_augkern; i++) { |
| 2177 |
lower(i, j) = a[(j + dim_augkern) + i * lda]; |
| 2178 |
} |
| 2179 |
} |
| 2180 |
// alpha = one; |
| 2181 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasTrans, CblasUnit, |
| 2182 |
dim_augkern, n1, one, a_fact, lda, |
| 2183 |
lower.addrCoefs(), dim_augkern); |
| 2184 |
for (int i = 0; i < dim_augkern; i++) { |
| 2185 |
for (int j = 0; j < n1; j++) { |
| 2186 |
lower(i, j) *= a_fact[i * (lda + 1)]; |
| 2187 |
} |
| 2188 |
} |
| 2189 |
// alpha = one; |
| 2190 |
blas_trsm<T>(CblasLeft, CblasLower, CblasTrans, CblasUnit, |
| 2191 |
dim_augkern, n1, one, a_fact, lda, |
| 2192 |
lower.addrCoefs(), dim_augkern); |
| 2193 |
for (int j = 0; j < n1; j++) { |
| 2194 |
lower((dim_augkern - 1), j) += Teps; |
| 2195 |
} |
| 2196 |
} |
| 2197 |
// alpha = none; |
| 2198 |
// beta = one; |
| 2199 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, n1, n1, dim_augkern, |
| 2200 |
none, &a[dim_augkern], lda, |
| 2201 |
upper.addrCoefs(), dim_augkern, |
| 2202 |
one, schur.addrCoefs(), n1); |
| 2203 |
if (flag_sym) { |
| 2204 |
full_ldlt<T>(n1, schur.addrCoefs(), n1); |
| 2205 |
} |
| 2206 |
else { |
| 2207 |
full_ldu<T>(n1, schur.addrCoefs(), n1); |
| 2208 |
} |
| 2209 |
// alpha = none; |
| 2210 |
// beta = one; |
| 2211 |
if (flag_sym) { |
| 2212 |
blas_gemm<T>(CblasTrans, CblasNoTrans, n1, m, dim_augkern, none, |
| 2213 |
upper.addrCoefs(), dim_augkern, |
| 2214 |
x, lda, one, &x[dim_augkern], lda); |
| 2215 |
} |
| 2216 |
else { |
| 2217 |
blas_gemm<T>(CblasTrans, CblasNoTrans, n1, m, dim_augkern, none, |
| 2218 |
lower.addrCoefs(), dim_augkern, |
| 2219 |
x, lda, one, &x[dim_augkern], lda); |
| 2220 |
} |
| 2221 |
// alpha = one; |
| 2222 |
// forward |
| 2223 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 2224 |
dim_augkern, m, one, a_fact, lda, x, lda); |
| 2225 |
// diagonal divide |
| 2226 |
for (int j = 0; j < m; j++) { |
| 2227 |
for (int i = 0; i < dim_augkern; i++) { |
| 2228 |
x[i + j * lda] *= a_fact[i * (lda + 1)]; |
| 2229 |
} |
| 2230 |
} |
| 2231 |
// backward |
| 2232 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 2233 |
dim_augkern, m, one, a_fact, lda, x, lda); |
| 2234 |
// forward |
| 2235 |
blas_trsm<T>(CblasLeft, CblasLower, CblasNoTrans, CblasUnit, |
| 2236 |
n1, m, one, schur.addrCoefs(), n1, &x[dim_augkern], lda); |
| 2237 |
for (int j = 0; j < m; j++) { |
| 2238 |
for (int i = 0; i < n1; i++) { |
| 2239 |
x[i + dim_augkern + j * lda] *= schur(i, i);// |
| 2240 |
} |
| 2241 |
} |
| 2242 |
// backward |
| 2243 |
blas_trsm<T>(CblasLeft, CblasUpper, CblasNoTrans, CblasUnit, |
| 2244 |
n1, m, one, schur.addrCoefs(), n1, &x[dim_augkern], lda); |
| 2245 |
// alpha = none; |
| 2246 |
// beta = one; |
| 2247 |
blas_gemm<T>(CblasNoTrans, CblasNoTrans, dim_augkern, m, n1, none, |
| 2248 |
upper.addrCoefs(), dim_augkern, |
| 2249 |
&x[dim_augkern], lda, one, x, lda); |
| 2250 |
} |
| 2251 |
} |
| 2252 |
|
| 2253 |
template |
| 2254 |
void full_fwbw_perturb_multi<quadruple, double>(const int n, |
| 2255 |
const int m, |
| 2256 |
quadruple *a, const int lda, |
| 2257 |
quadruple *a_fact, |
| 2258 |
quadruple *x, |
| 2259 |
const int dim_augkern, |
| 2260 |
const double &eps, |
| 2261 |
bool flag_sym); |
| 2262 |
template |
| 2263 |
void full_fwbw_perturb_multi<double, float>(const int n, |
| 2264 |
const int m, |
| 2265 |
double *a, const int lda, |
| 2266 |
double *a_fact, |
| 2267 |
double *x, |
| 2268 |
const int dim_augkern, |
| 2269 |
const float &eps, |
| 2270 |
bool flag_sym); |
| 2271 |
|
| 2272 |
#ifndef NO_OCTRUPLE |
| 2273 |
template |
| 2274 |
void full_fwbw_perturb_multi<octruple, quadruple>(const int n, |
| 2275 |
const int m, |
| 2276 |
octruple *a, const int lda, |
| 2277 |
octruple *a_fact, |
| 2278 |
octruple *x, |
| 2279 |
const int dim_augkern, |
| 2280 |
const quadruple &eps, |
| 2281 |
bool flag_sym); |
| 2282 |
#endif |
| 2283 |
template |
| 2284 |
void full_fwbw_perturb_multi<complex<quadruple>, |
| 2285 |
double>(const int n, |
| 2286 |
const int m, |
| 2287 |
complex<quadruple> *a, const int lda, |
| 2288 |
complex<quadruple> *a_fact, |
| 2289 |
complex<quadruple> *x, |
| 2290 |
const int dim_augkern, |
| 2291 |
const double &eps, |
| 2292 |
bool flag_sym); |
| 2293 |
|
| 2294 |
template |
| 2295 |
void full_fwbw_perturb_multi<complex<double>, |
| 2296 |
float>(const int n, |
| 2297 |
const int m, |
| 2298 |
complex<double> *a, const int lda, |
| 2299 |
complex<double> *a_fact, |
| 2300 |
complex<double> *x, |
| 2301 |
const int dim_augkern, |
| 2302 |
const float &eps, |
| 2303 |
bool flag_sym); |
| 2304 |
|
| 2305 |
#ifndef NO_OCTRUPLE |
| 2306 |
template |
| 2307 |
void full_fwbw_perturb_multi<complex<octruple>, |
| 2308 |
quadruple>(const int n, |
| 2309 |
const int m, |
| 2310 |
complex<octruple> *a, const int lda, |
| 2311 |
complex<octruple> *a_fact, |
| 2312 |
complex<octruple> *x, |
| 2313 |
const int dim_augkern, |
| 2314 |
const quadruple &eps, |
| 2315 |
bool flag_sym); |
| 2316 |
#endif |
| 2317 |
|
| 2318 |
|
| 2319 |
template<typename T> |
| 2320 |
void full_sym_2x2BK(int n, T *a, T *dd1, |
| 2321 |
int *pivot_width, int *permute) |
| 2322 |
{ |
| 2323 |
fprintf(stderr, "%s %d : general template is not implomented\n", |
| 2324 |
__FILE__, __LINE__); |
| 2325 |
} |
| 2326 |
|
| 2327 |
template |
| 2328 |
void full_sym_2x2BK<double>(int n, double *a, |
| 2329 |
double *dd1, |
| 2330 |
int *pivot_width, int *permute); |
| 2331 |
template |
| 2332 |
void full_sym_2x2BK<complex<double> >(int n, complex<double> *a, |
| 2333 |
complex<double> *dd1, |
| 2334 |
int *pivot_width, int *permute); |
| 2335 |
template |
| 2336 |
void full_sym_2x2BK<quadruple>(int n, quadruple *a, quadruple *dd1, |
| 2337 |
int *pivot_width, int *permute); |
| 2338 |
template |
| 2339 |
void full_sym_2x2BK<complex<quadruple> >(int n, complex<quadruple> *a, |
| 2340 |
complex<quadruple> *dd1, |
| 2341 |
int *pivot_width, int *permute); |
| 2342 |
|
| 2343 |
template |
| 2344 |
void full_sym_2x2BK<float>(int n, float *a, |
| 2345 |
float *dd1, |
| 2346 |
int *pivot_width, int *permute); |
| 2347 |
template |
| 2348 |
void full_sym_2x2BK<complex<float> >(int n, complex<float> *a, |
| 2349 |
complex<float> *dd1, |
| 2350 |
int *pivot_width, int *permute); |
| 2351 |
// |
| 2352 |
template<typename T> |
| 2353 |
void C_gemm_symm(const int ncol, const int nrow, const T &alpha, |
| 2354 |
const T *a, const int lda, |
| 2355 |
const T *b, const int ldb, |
| 2356 |
const T &beta, |
| 2357 |
T *c, const int ldc) |
| 2358 |
{ |
| 2359 |
// #define DGEMM_FOR_SYMM |
| 2360 |
#ifdef DGEMM_FOR_SYMM |
| 2361 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 2362 |
ncol, ncol, nrow, alpha, a, lda, b, ldb, |
| 2363 |
beta, c, ldc); |
| 2364 |
#else |
| 2365 |
int n1, n2, n11, n12, n21, n22, n3; |
| 2366 |
n1 = ncol / 2; |
| 2367 |
n2 = ncol - n1; |
| 2368 |
n11 = n1 / 2; |
| 2369 |
n12 = n1 - n11; |
| 2370 |
n21 = n2 / 2; |
| 2371 |
n22 = n2 - n21; |
| 2372 |
n3 = n1 + n21; |
| 2373 |
if (ncol < SIZE_DGEMM_SYMM_DTRSV) { |
| 2374 |
for (int j = 0; j < ncol; j++) { |
| 2375 |
blas_gemv<T>(CblasTrans, nrow, (j + 1), alpha, a, lda, |
| 2376 |
b + (ldb * j), 1, beta, c + (ldc * j), 1); |
| 2377 |
} |
| 2378 |
} |
| 2379 |
else { |
| 2380 |
C_gemm_symm<T>(n11, nrow, alpha, a, lda, b, ldb, beta, c, ldc); |
| 2381 |
C_gemm_symm<T>(n12, nrow, alpha, a + (lda * n11), lda, b + (ldb * n11), ldb, |
| 2382 |
beta, c + (ldc + 1) * n11, ldc); |
| 2383 |
C_gemm_symm<T>(n21, nrow, alpha, a + lda * n1, lda, b + ldb * n1, ldb, |
| 2384 |
beta, c + (ldc + 1) * n1, ldc); |
| 2385 |
C_gemm_symm<T>(n22, nrow, alpha, a + lda * n3, lda, b + ldb * n3, ldb, |
| 2386 |
beta, c + (ldc + 1) * n3, ldc); |
| 2387 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 2388 |
n11, n12, nrow, alpha, a, lda, b + (ldb * n11), ldb, |
| 2389 |
beta, c + (ldc * n11), ldc); |
| 2390 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 2391 |
n21, n22, nrow, alpha, a + (lda * n1), lda, b + (ldb * n3), ldb, |
| 2392 |
beta, c + (n1 + ldc * n3), ldc); |
| 2393 |
blas_gemm<T>(CblasTrans, CblasNoTrans, |
| 2394 |
n1, n2, nrow, alpha, a, lda, b + (ldb * n1), ldb, |
| 2395 |
beta, c + (ldc * n1), ldc); |
| 2396 |
} |
| 2397 |
#endif |
| 2398 |
} |
| 2399 |
|
| 2400 |
template |
| 2401 |
void C_gemm_symm<double>(const int ncol, const int nrow, const double &alpha, |
| 2402 |
const double *a, const int lda, |
| 2403 |
const double *b, const int ldb, |
| 2404 |
const double &beta, |
| 2405 |
double *c, const int ldc); |
| 2406 |
|
| 2407 |
template |
| 2408 |
void C_gemm_symm<complex<double> >(const int ncol, const int nrow, |
| 2409 |
const complex<double> &alpha, |
| 2410 |
const complex<double> *a, const int lda, |
| 2411 |
const complex<double> *b, const int ldb, |
| 2412 |
const complex<double> &beta, |
| 2413 |
complex<double> *c, const int ldc); |
| 2414 |
template |
| 2415 |
void C_gemm_symm<quadruple>(const int ncol, const int nrow, |
| 2416 |
const quadruple &alpha, |
| 2417 |
const quadruple *a, const int lda, |
| 2418 |
const quadruple *b, const int ldb, |
| 2419 |
const quadruple &beta, |
| 2420 |
quadruple *c, const int ldc); |
| 2421 |
|
| 2422 |
template |
| 2423 |
void C_gemm_symm<complex<quadruple> >(const int ncol, const int nrow, |
| 2424 |
const complex<quadruple> &alpha, |
| 2425 |
const complex<quadruple> *a, const int lda, |
| 2426 |
const complex<quadruple> *b, const int ldb, |
| 2427 |
const complex<quadruple> &beta, |
| 2428 |
complex<quadruple> *c, const int ldc); |
| 2429 |
|
| 2430 |
template |
| 2431 |
void C_gemm_symm<float>(const int ncol, const int nrow, const float &alpha, |
| 2432 |
const float *a, const int lda, |
| 2433 |
const float *b, const int ldb, |
| 2434 |
const float &beta, |
| 2435 |
float *c, const int ldc); |
| 2436 |
|
| 2437 |
template |
| 2438 |
void C_gemm_symm<complex<float> >(const int ncol, const int nrow, |
| 2439 |
const complex<float> &alpha, |
| 2440 |
const complex<float> *a, const int lda, |
| 2441 |
const complex<float> *b, const int ldb, |
| 2442 |
const complex<float> &beta, |
| 2443 |
complex<float> *c, const int ldc); |
| 2444 |
// |