Commit 8a962d34 authored by Andrey Kamaev's avatar Andrey Kamaev

Merge pull request #676 from vpisarev/svd_stuff

added test for bug #1448 and hopefully fixes the bug #2898
parents 172b4554 9a862452
......@@ -531,12 +531,12 @@ template<> inline int VBLAS<double>::givensx(double* a, double* b, int n, double
#endif
template<typename _Tp> void
JacobiSVDImpl_(_Tp* At, size_t astep, _Tp* _W, _Tp* Vt, size_t vstep, int m, int n, int n1, double minval)
JacobiSVDImpl_(_Tp* At, size_t astep, _Tp* _W, _Tp* Vt, size_t vstep,
int m, int n, int n1, double minval, _Tp eps)
{
VBLAS<_Tp> vblas;
AutoBuffer<double> Wbuf(n);
double* W = Wbuf;
_Tp eps = DBL_EPSILON*10;
int i, j, k, iter, max_iter = std::max(m, 30);
_Tp c, s;
double sd;
......@@ -729,12 +729,12 @@ JacobiSVDImpl_(_Tp* At, size_t astep, _Tp* _W, _Tp* Vt, size_t vstep, int m, int
static void JacobiSVD(float* At, size_t astep, float* W, float* Vt, size_t vstep, int m, int n, int n1=-1)
{
JacobiSVDImpl_(At, astep, W, Vt, vstep, m, n, !Vt ? 0 : n1 < 0 ? n : n1, FLT_MIN);
JacobiSVDImpl_(At, astep, W, Vt, vstep, m, n, !Vt ? 0 : n1 < 0 ? n : n1, FLT_MIN, FLT_EPSILON*2);
}
static void JacobiSVD(double* At, size_t astep, double* W, double* Vt, size_t vstep, int m, int n, int n1=-1)
{
JacobiSVDImpl_(At, astep, W, Vt, vstep, m, n, !Vt ? 0 : n1 < 0 ? n : n1, DBL_MIN);
JacobiSVDImpl_(At, astep, W, Vt, vstep, m, n, !Vt ? 0 : n1 < 0 ? n : n1, DBL_MIN, DBL_EPSILON*10);
}
/* y[0:m,0:n] += diag(a[0:1,0:m]) * x[0:m,0:n] */
......
......@@ -2487,6 +2487,35 @@ TEST(Core_SVBkSb, accuracy) { Core_SVBkSbTest test; test.safe_run(); }
TEST(Core_Trace, accuracy) { Core_TraceTest test; test.safe_run(); }
TEST(Core_SolvePoly, accuracy) { Core_SolvePolyTest test; test.safe_run(); }
TEST(Core_SVD, flt)
{
float a[] = {
1.23377746e+011f, -7.05490125e+010f, -4.18380882e+010f, -11693456.f,
-39091328.f, 77492224.f, -7.05490125e+010f, 2.36211143e+011f,
-3.51093473e+010f, 70773408.f, -4.83386156e+005f, -129560368.f,
-4.18380882e+010f, -3.51093473e+010f, 9.25311222e+010f, -49052424.f,
43922752.f, 12176842.f, -11693456.f, 70773408.f, -49052424.f, 8.40836094e+004f,
5.17475293e+003f, -1.16122949e+004f, -39091328.f, -4.83386156e+005f,
43922752.f, 5.17475293e+003f, 5.16047969e+004f, 5.68887842e+003f, 77492224.f,
-129560368.f, 12176842.f, -1.16122949e+004f, 5.68887842e+003f,
1.28060578e+005f
};
float b[] = {
283751232.f, 2.61604198e+009f, -745033216.f, 2.31125625e+005f,
-4.52429188e+005f, -1.37596525e+006f
};
Mat A(6, 6, CV_32F, a);
Mat B(6, 1, CV_32F, b);
Mat X, B1;
solve(A, B, X, DECOMP_SVD);
B1 = A*X;
EXPECT_LE(norm(B1, B, NORM_L2 + NORM_RELATIVE), FLT_EPSILON*10);
}
// TODO: eigenvv, invsqrt, cbrt, fastarctan, (round, floor, ceil(?)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment