dpbsvx function
void
dpbsvx(
- String FACT,
- String UPLO,
- int N,
- int KD,
- int NRHS,
- Matrix<
double> AB_, - int LDAB,
- Matrix<
double> AFB_, - int LDAFB,
- Box<
String> EQUED, - Array<
double> S_, - Matrix<
double> B_, - int LDB,
- Matrix<
double> X_, - int LDX,
- Box<
double> RCOND, - Array<
double> FERR_, - Array<
double> BERR_, - Array<
double> WORK_, - Array<
int> IWORK_, - Box<
int> INFO,
Implementation
void dpbsvx(
final String FACT,
final String UPLO,
final int N,
final int KD,
final int NRHS,
final Matrix<double> AB_,
final int LDAB,
final Matrix<double> AFB_,
final int LDAFB,
final Box<String> EQUED,
final Array<double> S_,
final Matrix<double> B_,
final int LDB,
final Matrix<double> X_,
final int LDX,
final Box<double> RCOND,
final Array<double> FERR_,
final Array<double> BERR_,
final Array<double> WORK_,
final Array<int> IWORK_,
final Box<int> INFO,
) {
final AB = AB_.having(ld: LDAB);
final AFB = AFB_.having(ld: LDAFB);
final B = B_.having(ld: LDB);
final X = X_.having(ld: LDX);
final S = S_.having();
final FERR = FERR_.having();
final BERR = BERR_.having();
final WORK = WORK_.having();
final IWORK = IWORK_.having();
const ZERO = 0.0, ONE = 1.0;
bool EQUIL, NOFACT, RCEQU, UPPER;
int I, J, J1, J2;
double ANORM, BIGNUM = 0, SMAX, SMIN, SMLNUM = 0;
final INFEQU = Box(0);
final SCOND = Box(0.0), AMAX = Box(0.0);
INFO.value = 0;
NOFACT = lsame(FACT, 'N');
EQUIL = lsame(FACT, 'E');
UPPER = lsame(UPLO, 'U');
if (NOFACT || EQUIL) {
EQUED.value = 'N';
RCEQU = false;
} else {
RCEQU = lsame(EQUED.value, 'Y');
SMLNUM = dlamch('Safe minimum');
BIGNUM = ONE / SMLNUM;
}
// Test the input parameters.
if (!NOFACT && !EQUIL && !lsame(FACT, 'F')) {
INFO.value = -1;
} else if (!UPPER && !lsame(UPLO, 'L')) {
INFO.value = -2;
} else if (N < 0) {
INFO.value = -3;
} else if (KD < 0) {
INFO.value = -4;
} else if (NRHS < 0) {
INFO.value = -5;
} else if (LDAB < KD + 1) {
INFO.value = -7;
} else if (LDAFB < KD + 1) {
INFO.value = -9;
} else if (lsame(FACT, 'F') && !(RCEQU || lsame(EQUED.value, 'N'))) {
INFO.value = -10;
} else {
if (RCEQU) {
SMIN = BIGNUM;
SMAX = ZERO;
for (J = 1; J <= N; J++) {
SMIN = min(SMIN, S[J]);
SMAX = max(SMAX, S[J]);
}
if (SMIN <= ZERO) {
INFO.value = -11;
} else if (N > 0) {
SCOND.value = max(SMIN, SMLNUM) / min(SMAX, BIGNUM);
} else {
SCOND.value = ONE;
}
}
if (INFO.value == 0) {
if (LDB < max(1, N)) {
INFO.value = -13;
} else if (LDX < max(1, N)) {
INFO.value = -15;
}
}
}
if (INFO.value != 0) {
xerbla('DPBSVX', -INFO.value);
return;
}
if (EQUIL) {
// Compute row and column scalings to equilibrate the matrix A.
dpbequ(UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, INFEQU);
if (INFEQU.value == 0) {
// Equilibrate the matrix.
dlaqsb(UPLO, N, KD, AB, LDAB, S, SCOND.value, AMAX.value, EQUED);
RCEQU = lsame(EQUED.value, 'Y');
}
}
// Scale the right-hand side.
if (RCEQU) {
for (J = 1; J <= NRHS; J++) {
for (I = 1; I <= N; I++) {
B[I][J] = S[I] * B[I][J];
}
}
}
if (NOFACT || EQUIL) {
// Compute the Cholesky factorization A = U**T *U or A = L*L**T.
if (UPPER) {
for (J = 1; J <= N; J++) {
J1 = max(J - KD, 1);
dcopy(J - J1 + 1, AB(KD + 1 - J + J1, J).asArray(), 1,
AFB(KD + 1 - J + J1, J).asArray(), 1);
}
} else {
for (J = 1; J <= N; J++) {
J2 = min(J + KD, N);
dcopy(J2 - J + 1, AB(1, J).asArray(), 1, AFB(1, J).asArray(), 1);
}
}
dpbtrf(UPLO, N, KD, AFB, LDAFB, INFO);
// Return if INFO is non-zero.
if (INFO.value > 0) {
RCOND.value = ZERO;
return;
}
}
// Compute the norm of the matrix A.
ANORM = dlansb('1', UPLO, N, KD, AB, LDAB, WORK);
// Compute the reciprocal of the condition number of A.
dpbcon(UPLO, N, KD, AFB, LDAFB, ANORM, RCOND, WORK, IWORK, INFO);
// Compute the solution matrix X.
dlacpy('Full', N, NRHS, B, LDB, X, LDX);
dpbtrs(UPLO, N, KD, NRHS, AFB, LDAFB, X, LDX, INFO);
// Use iterative refinement to improve the computed solution and
// compute error bounds and backward error estimates for it.
dpbrfs(UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B, LDB, X, LDX, FERR, BERR,
WORK, IWORK, INFO);
// Transform the solution matrix X to a solution of the original
// system.
if (RCEQU) {
for (J = 1; J <= NRHS; J++) {
for (I = 1; I <= N; I++) {
X[I][J] = S[I] * X[I][J];
}
}
for (J = 1; J <= NRHS; J++) {
FERR[J] /= SCOND.value;
}
}
// Set INFO = N+1 if the matrix is singular to working precision.
if (RCOND.value < dlamch('Epsilon')) INFO.value = N + 1;
}