// // Arguments : const double A[476] // double U[476] // double S[17] // double V[289] // Return Type : void // static void eml_xgesvd(const double A[476], double U[476], double S[17], double V[289]) { double b_A[476]; double s[17]; double e[17]; int kase; double work[28]; int q; int iter; boolean_T apply_transform; double ztest0; int qp1jj; int qs; int m; double rt; double ztest; double snorm; int32_T exitg3; boolean_T exitg2; double f; double varargin_1[5]; double mtmp; boolean_T exitg1; double sqds; memcpy(&b_A[0], &A[0], 476U * sizeof(double)); for (kase = 0; kase < 17; kase++) { s[kase] = 0.0; e[kase] = 0.0; } memset(&work[0], 0, 28U * sizeof(double)); memset(&U[0], 0, 476U * sizeof(double)); memset(&V[0], 0, 289U * sizeof(double)); for (q = 0; q < 17; q++) { iter = q + 28 * q; apply_transform = false; ztest0 = c_eml_xnrm2(28 - q, b_A, iter + 1); if (ztest0 > 0.0) { apply_transform = true; if (b_A[iter] < 0.0) { s[q] = -ztest0; } else { s[q] = ztest0; } if (fabs(s[q]) >= 1.0020841800044864E-292) { ztest0 = 1.0 / s[q]; kase = (iter - q) + 28; for (qp1jj = iter; qp1jj + 1 <= kase; qp1jj++) { b_A[qp1jj] *= ztest0; } } else { kase = (iter - q) + 28; for (qp1jj = iter; qp1jj + 1 <= kase; qp1jj++) { b_A[qp1jj] /= s[q]; } } b_A[iter]++; s[q] = -s[q]; } else { s[q] = 0.0; } for (qs = q + 1; qs + 1 < 18; qs++) { kase = q + 28 * qs; if (apply_transform) { eml_xaxpy(28 - q, -(eml_xdotc(28 - q, b_A, iter + 1, b_A, kase + 1) / b_A[q + 28 * q]), iter + 1, b_A, kase + 1); } e[qs] = b_A[kase]; } for (qp1jj = q; qp1jj + 1 < 29; qp1jj++) { U[qp1jj + 28 * q] = b_A[qp1jj + 28 * q]; } if (q + 1 <= 15) { ztest0 = d_eml_xnrm2(16 - q, e, q + 2); if (ztest0 == 0.0) { e[q] = 0.0; } else { if (e[q + 1] < 0.0) { e[q] = -ztest0; } else { e[q] = ztest0; } ztest0 = e[q]; if (fabs(e[q]) >= 1.0020841800044864E-292) { ztest0 = 1.0 / e[q]; for (qp1jj = q + 1; qp1jj + 1 < 18; qp1jj++) { e[qp1jj] *= ztest0; } } else { for (qp1jj = q + 1; qp1jj + 1 < 18; qp1jj++) { e[qp1jj] /= ztest0; } } e[q + 1]++; e[q] = -e[q]; for (qp1jj = q + 1; qp1jj + 1 < 29; qp1jj++) { work[qp1jj] = 0.0; } for (qs = q + 1; qs + 1 < 18; qs++) { b_eml_xaxpy(27 - q, e[qs], b_A, (q + 28 * qs) + 2, work, q + 2); } for (qs = q + 1; qs + 1 < 18; qs++) { c_eml_xaxpy(27 - q, -e[qs] / e[q + 1], work, q + 2, b_A, (q + 28 * qs) + 2); } } for (qp1jj = q + 1; qp1jj + 1 < 18; qp1jj++) { V[qp1jj + 17 * q] = e[qp1jj]; } } } m = 15; e[15] = b_A[463]; e[16] = 0.0; for (q = 16; q > -1; q += -1) { iter = q + 28 * q; if (s[q] != 0.0) { for (qs = q + 1; qs + 1 < 18; qs++) { kase = (q + 28 * qs) + 1; eml_xaxpy(28 - q, -(eml_xdotc(28 - q, U, iter + 1, U, kase) / U[iter]), iter + 1, U, kase); } for (qp1jj = q; qp1jj + 1 < 29; qp1jj++) { U[qp1jj + 28 * q] = -U[qp1jj + 28 * q]; } U[iter]++; for (qp1jj = 1; qp1jj <= q; qp1jj++) { U[(qp1jj + 28 * q) - 1] = 0.0; } } else { memset(&U[28 * q], 0, 28U * sizeof(double)); U[iter] = 1.0; } } for (q = 16; q > -1; q += -1) { if ((q + 1 <= 15) && (e[q] != 0.0)) { kase = (q + 17 * q) + 2; for (qs = q + 1; qs + 1 < 18; qs++) { qp1jj = (q + 17 * qs) + 2; d_eml_xaxpy(16 - q, -(b_eml_xdotc(16 - q, V, kase, V, qp1jj) / V[kase - 1]), kase, V, qp1jj); } } memset(&V[17 * q], 0, 17U * sizeof(double)); V[q + 17 * q] = 1.0; } for (q = 0; q < 17; q++) { ztest0 = e[q]; if (s[q] != 0.0) { rt = fabs(s[q]); ztest = s[q] / rt; s[q] = rt; if (q + 1 < 17) { ztest0 = e[q] / ztest; } b_eml_xscal(ztest, U, 1 + 28 * q); } if ((q + 1 < 17) && (ztest0 != 0.0)) { rt = fabs(ztest0); ztest = rt / ztest0; ztest0 = rt; s[q + 1] *= ztest; c_eml_xscal(ztest, V, 1 + 17 * (q + 1)); } e[q] = ztest0; } iter = 0; snorm = 0.0; for (qp1jj = 0; qp1jj < 17; qp1jj++) { ztest0 = fabs(s[qp1jj]); ztest = fabs(e[qp1jj]); if ((ztest0 >= ztest) || rtIsNaN(ztest)) { } else { ztest0 = ztest; } if ((snorm >= ztest0) || rtIsNaN(ztest0)) { } else { snorm = ztest0; } } while ((m + 2 > 0) && (!(iter >= 75))) { qp1jj = m; do { exitg3 = 0; q = qp1jj + 1; if (qp1jj + 1 == 0) { exitg3 = 1; } else { ztest0 = fabs(e[qp1jj]); if ((ztest0 <= 2.2204460492503131E-16 * (fabs(s[qp1jj]) + fabs(s[qp1jj + 1]))) || (ztest0 <= 1.0020841800044864E-292) || ((iter > 20) && (ztest0 <= 2.2204460492503131E-16 * snorm))) { e[qp1jj] = 0.0; exitg3 = 1; } else { qp1jj--; } } } while (exitg3 == 0); if (qp1jj + 1 == m + 1) { kase = 4; } else { qs = m + 2; kase = m + 2; exitg2 = false; while ((!exitg2) && (kase >= qp1jj + 1)) { qs = kase; if (kase == qp1jj + 1) { exitg2 = true; } else { ztest0 = 0.0; if (kase < m + 2) { ztest0 = fabs(e[kase - 1]); } if (kase > qp1jj + 2) { ztest0 += fabs(e[kase - 2]); } ztest = fabs(s[kase - 1]); if ((ztest <= 2.2204460492503131E-16 * ztest0) || (ztest <= 1.0020841800044864E-292)) { s[kase - 1] = 0.0; exitg2 = true; } else { kase--; } } } if (qs == qp1jj + 1) { kase = 3; } else if (qs == m + 2) { kase = 1; } else { kase = 2; q = qs; } } switch (kase) { case 1: f = e[m]; e[m] = 0.0; for (qp1jj = m; qp1jj + 1 >= q + 1; qp1jj--) { ztest0 = s[qp1jj]; eml_xrotg(&ztest0, &f, &ztest, &rt); s[qp1jj] = ztest0; if (qp1jj + 1 > q + 1) { f = -rt * e[qp1jj - 1]; e[qp1jj - 1] *= ztest; } eml_xrot(V, 1 + 17 * qp1jj, 1 + 17 * (m + 1), ztest, rt); } break; case 2: f = e[q - 1]; e[q - 1] = 0.0; for (qp1jj = q; qp1jj + 1 <= m + 2; qp1jj++) { eml_xrotg(&s[qp1jj], &f, &ztest, &rt); f = -rt * e[qp1jj]; e[qp1jj] *= ztest; b_eml_xrot(U, 1 + 28 * qp1jj, 1 + 28 * (q - 1), ztest, rt); } break; case 3: varargin_1[0] = fabs(s[m + 1]); varargin_1[1] = fabs(s[m]); varargin_1[2] = fabs(e[m]); varargin_1[3] = fabs(s[q]); varargin_1[4] = fabs(e[q]); kase = 1; mtmp = varargin_1[0]; if (rtIsNaN(varargin_1[0])) { qp1jj = 2; exitg1 = false; while ((!exitg1) && (qp1jj < 6)) { kase = qp1jj; if (!rtIsNaN(varargin_1[qp1jj - 1])) { mtmp = varargin_1[qp1jj - 1]; exitg1 = true; } else { qp1jj++; } } } if (kase < 5) { while (kase + 1 < 6) { if (varargin_1[kase] > mtmp) { mtmp = varargin_1[kase]; } kase++; } } f = s[m + 1] / mtmp; ztest0 = s[m] / mtmp; ztest = e[m] / mtmp; sqds = s[q] / mtmp; rt = ((ztest0 + f) * (ztest0 - f) + ztest * ztest) / 2.0; ztest0 = f * ztest; ztest0 *= ztest0; if ((rt != 0.0) || (ztest0 != 0.0)) { ztest = sqrt(rt * rt + ztest0); if (rt < 0.0) { ztest = -ztest; } ztest = ztest0 / (rt + ztest); } else { ztest = 0.0; } f = (sqds + f) * (sqds - f) + ztest; ztest0 = sqds * (e[q] / mtmp); for (qp1jj = q + 1; qp1jj <= m + 1; qp1jj++) { eml_xrotg(&f, &ztest0, &ztest, &rt); if (qp1jj > q + 1) { e[qp1jj - 2] = f; } f = ztest * s[qp1jj - 1] + rt * e[qp1jj - 1]; e[qp1jj - 1] = ztest * e[qp1jj - 1] - rt * s[qp1jj - 1]; ztest0 = rt * s[qp1jj]; s[qp1jj] *= ztest; eml_xrot(V, 1 + 17 * (qp1jj - 1), 1 + 17 * qp1jj, ztest, rt); s[qp1jj - 1] = f; eml_xrotg(&s[qp1jj - 1], &ztest0, &ztest, &rt); f = ztest * e[qp1jj - 1] + rt * s[qp1jj]; s[qp1jj] = -rt * e[qp1jj - 1] + ztest * s[qp1jj]; ztest0 = rt * e[qp1jj]; e[qp1jj] *= ztest; b_eml_xrot(U, 1 + 28 * (qp1jj - 1), 1 + 28 * qp1jj, ztest, rt); } e[m] = f; iter++; break; default: if (s[q] < 0.0) { s[q] = -s[q]; c_eml_xscal(-1.0, V, 1 + 17 * q); } kase = q + 1; while ((q + 1 < 17) && (s[q] < s[kase])) { rt = s[q]; s[q] = s[kase]; s[kase] = rt; b_eml_xswap(V, 1 + 17 * q, 1 + 17 * (q + 1)); c_eml_xswap(U, 1 + 28 * q, 1 + 28 * (q + 1)); q = kase; kase++; } iter = 0; m--; break; } } memcpy(&S[0], &s[0], 17U * sizeof(double)); }
static void b_eml_xgesvd(const real32_T A[16], real32_T U[16], real32_T S[4], real32_T V[16]) { real32_T b_A[16]; real32_T s[4]; real32_T e[4]; real32_T work[4]; int32_T i; real32_T Vf[16]; int32_T q; int32_T qs; real32_T ztest0; int32_T ii; int32_T m; real32_T rt; real32_T ztest; int32_T iter; real32_T tiny; real32_T snorm; int32_T exitg3; boolean_T exitg2; real32_T sn; real32_T varargin_1[5]; boolean_T exitg1; real32_T sqds; real32_T b; memcpy(&b_A[0], &A[0], sizeof(real32_T) << 4); for (i = 0; i < 4; i++) { s[i] = 0.0F; e[i] = 0.0F; work[i] = 0.0F; } for (i = 0; i < 16; i++) { U[i] = 0.0F; Vf[i] = 0.0F; } for (q = 0; q < 3; q++) { qs = q + (q << 2); ztest0 = c_eml_xnrm2(4 - q, b_A, qs + 1); if (ztest0 > 0.0F) { if (b_A[qs] < 0.0F) { s[q] = -ztest0; } else { s[q] = ztest0; } c_eml_xscal(4 - q, b_eml_div(1.0, s[q]), b_A, qs + 1); b_A[qs]++; s[q] = -s[q]; } else { s[q] = 0.0F; } for (ii = q + 1; ii + 1 < 5; ii++) { i = q + (ii << 2); if (s[q] != 0.0F) { ztest0 = -eml_div(b_eml_xdotc(4 - q, b_A, qs + 1, b_A, i + 1), b_A[q + (q << 2)]); d_eml_xaxpy(4 - q, ztest0, qs + 1, b_A, i + 1); } e[ii] = b_A[i]; } for (ii = q; ii + 1 < 5; ii++) { U[ii + (q << 2)] = b_A[ii + (q << 2)]; } if (q + 1 <= 2) { ztest0 = d_eml_xnrm2(3 - q, e, q + 2); if (ztest0 == 0.0F) { e[q] = 0.0F; } else { if (e[q + 1] < 0.0F) { e[q] = -ztest0; } else { e[q] = ztest0; } ztest0 = b_eml_div(1.0, e[q]); d_eml_xscal(3 - q, ztest0, e, q + 2); e[q + 1]++; } e[q] = -e[q]; if (e[q] != 0.0F) { for (ii = q + 1; ii + 1 < 5; ii++) { work[ii] = 0.0F; } for (ii = q + 1; ii + 1 < 5; ii++) { e_eml_xaxpy(3 - q, e[ii], b_A, (q + (ii << 2)) + 2, work, q + 2); } for (ii = q + 1; ii + 1 < 5; ii++) { f_eml_xaxpy(3 - q, eml_div(-e[ii], e[q + 1]), work, q + 2, b_A, (q + (ii << 2)) + 2); } } for (ii = q + 1; ii + 1 < 5; ii++) { Vf[ii + (q << 2)] = e[ii]; } } } m = 2; s[3] = b_A[15]; e[2] = b_A[14]; e[3] = 0.0F; for (ii = 0; ii < 4; ii++) { U[12 + ii] = 0.0F; } U[15] = 1.0F; for (q = 2; q > -1; q += -1) { qs = q + (q << 2); if (s[q] != 0.0F) { for (ii = q + 1; ii + 1 < 5; ii++) { i = (q + (ii << 2)) + 1; ztest0 = -eml_div(b_eml_xdotc(4 - q, U, qs + 1, U, i), U[qs]); d_eml_xaxpy(4 - q, ztest0, qs + 1, U, i); } for (ii = q; ii + 1 < 5; ii++) { U[ii + (q << 2)] = -U[ii + (q << 2)]; } U[qs]++; for (ii = 1; ii <= q; ii++) { U[(ii + (q << 2)) - 1] = 0.0F; } } else { for (ii = 0; ii < 4; ii++) { U[ii + (q << 2)] = 0.0F; } U[qs] = 1.0F; } } for (q = 3; q > -1; q += -1) { if ((q + 1 <= 2) && (e[q] != 0.0F)) { i = (q + (q << 2)) + 2; for (ii = q + 1; ii + 1 < 5; ii++) { qs = (q + (ii << 2)) + 2; ztest0 = -eml_div(b_eml_xdotc(3 - q, Vf, i, Vf, qs), Vf[i - 1]); d_eml_xaxpy(3 - q, ztest0, i, Vf, qs); } } for (ii = 0; ii < 4; ii++) { Vf[ii + (q << 2)] = 0.0F; } Vf[q + (q << 2)] = 1.0F; } for (q = 0; q < 4; q++) { ztest0 = e[q]; if (s[q] != 0.0F) { rt = (real32_T)fabs(s[q]); ztest = eml_div(s[q], rt); s[q] = rt; if (q + 1 < 4) { ztest0 = eml_div(e[q], ztest); } c_eml_xscal(4, ztest, U, (q << 2) + 1); } if ((q + 1 < 4) && (ztest0 != 0.0F)) { rt = (real32_T)fabs(ztest0); ztest = eml_div(rt, ztest0); ztest0 = rt; s[q + 1] *= ztest; c_eml_xscal(4, ztest, Vf, ((q + 1) << 2) + 1); } e[q] = ztest0; } iter = 0; tiny = eml_div(1.17549435E-38F, 1.1920929E-7F); snorm = 0.0F; for (ii = 0; ii < 4; ii++) { ztest0 = (real32_T)fabs(s[ii]); ztest = (real32_T)fabs(e[ii]); if ((ztest0 >= ztest) || rtIsNaNF(ztest)) { } else { ztest0 = ztest; } if ((snorm >= ztest0) || rtIsNaNF(ztest0)) { } else { snorm = ztest0; } } while ((m + 2 > 0) && (!(iter >= 75))) { ii = m; do { exitg3 = 0; q = ii + 1; if (ii + 1 == 0) { exitg3 = 1; } else { ztest0 = (real32_T)fabs(e[ii]); if ((ztest0 <= 1.1920929E-7F * ((real32_T)fabs(s[ii]) + (real32_T)fabs (s[ii + 1]))) || (ztest0 <= tiny) || ((iter > 20) && (ztest0 <= 1.1920929E-7F * snorm))) { e[ii] = 0.0F; exitg3 = 1; } else { ii--; } } } while (exitg3 == 0); if (ii + 1 == m + 1) { i = 4; } else { qs = m + 2; i = m + 2; exitg2 = FALSE; while ((exitg2 == FALSE) && (i >= ii + 1)) { qs = i; if (i == ii + 1) { exitg2 = TRUE; } else { ztest0 = 0.0F; if (i < m + 2) { ztest0 = (real32_T)fabs(e[i - 1]); } if (i > ii + 2) { ztest0 += (real32_T)fabs(e[i - 2]); } ztest = (real32_T)fabs(s[i - 1]); if ((ztest <= 1.1920929E-7F * ztest0) || (ztest <= tiny)) { s[i - 1] = 0.0F; exitg2 = TRUE; } else { i--; } } } if (qs == ii + 1) { i = 3; } else if (qs == m + 2) { i = 1; } else { i = 2; q = qs; } } switch (i) { case 1: ztest = e[m]; e[m] = 0.0F; for (qs = m; qs + 1 >= q + 1; qs--) { ztest0 = s[qs]; eml_xrotg(&ztest0, &ztest, &rt, &sn); s[qs] = ztest0; if (qs + 1 > q + 1) { ztest = -sn * e[qs - 1]; e[qs - 1] *= rt; } b_eml_xrot(Vf, (qs << 2) + 1, ((m + 1) << 2) + 1, rt, sn); } break; case 2: ztest = e[q - 1]; e[q - 1] = 0.0F; for (qs = q; qs + 1 <= m + 2; qs++) { eml_xrotg(&s[qs], &ztest, &rt, &sn); ztest = -sn * e[qs]; e[qs] *= rt; b_eml_xrot(U, (qs << 2) + 1, ((q - 1) << 2) + 1, rt, sn); } break; case 3: varargin_1[0] = (real32_T)fabs(s[m + 1]); varargin_1[1] = (real32_T)fabs(s[m]); varargin_1[2] = (real32_T)fabs(e[m]); varargin_1[3] = (real32_T)fabs(s[q]); varargin_1[4] = (real32_T)fabs(e[q]); i = 1; sn = varargin_1[0]; if (rtIsNaNF(varargin_1[0])) { qs = 2; exitg1 = FALSE; while ((exitg1 == FALSE) && (qs < 6)) { i = qs; if (!rtIsNaNF(varargin_1[qs - 1])) { sn = varargin_1[qs - 1]; exitg1 = TRUE; } else { qs++; } } } if (i < 5) { while (i + 1 < 6) { if (varargin_1[i] > sn) { sn = varargin_1[i]; } i++; } } rt = eml_div(s[m + 1], sn); ztest0 = eml_div(s[m], sn); ztest = eml_div(e[m], sn); sqds = eml_div(s[q], sn); b = c_eml_div((ztest0 + rt) * (ztest0 - rt) + ztest * ztest, 2.0); ztest0 = rt * ztest; ztest0 *= ztest0; ztest = 0.0F; if ((b != 0.0F) || (ztest0 != 0.0F)) { ztest = (real32_T)sqrt(b * b + ztest0); if (b < 0.0F) { ztest = -ztest; } ztest = eml_div(ztest0, b + ztest); } ztest += (sqds + rt) * (sqds - rt); ztest0 = sqds * eml_div(e[q], sn); for (qs = q + 1; qs <= m + 1; qs++) { eml_xrotg(&ztest, &ztest0, &rt, &sn); if (qs > q + 1) { e[qs - 2] = ztest; } ztest0 = rt * s[qs - 1]; ztest = sn * e[qs - 1]; e[qs - 1] = rt * e[qs - 1] - sn * s[qs - 1]; b = s[qs]; s[qs] *= rt; b_eml_xrot(Vf, ((qs - 1) << 2) + 1, (qs << 2) + 1, rt, sn); s[qs - 1] = ztest0 + ztest; ztest0 = sn * b; eml_xrotg(&s[qs - 1], &ztest0, &rt, &sn); ztest = rt * e[qs - 1] + sn * s[qs]; s[qs] = -sn * e[qs - 1] + rt * s[qs]; ztest0 = sn * e[qs]; e[qs] *= rt; b_eml_xrot(U, ((qs - 1) << 2) + 1, (qs << 2) + 1, rt, sn); } e[m] = ztest; iter++; break; default: if (s[q] < 0.0F) { s[q] = -s[q]; c_eml_xscal(4, -1.0F, Vf, (q << 2) + 1); } i = q + 1; while ((q + 1 < 4) && (s[q] < s[i])) { rt = s[q]; s[q] = s[i]; s[i] = rt; b_eml_xswap(Vf, (q << 2) + 1, ((q + 1) << 2) + 1); b_eml_xswap(U, (q << 2) + 1, ((q + 1) << 2) + 1); q = i; i++; } iter = 0; m--; break; } } for (qs = 0; qs < 4; qs++) { S[qs] = s[qs]; for (i = 0; i < 4; i++) { V[i + (qs << 2)] = Vf[i + (qs << 2)]; } } }