Commit f0708368 authored by Davis King's avatar Davis King

Added some tests to exercise the column major code paths.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403842
parent f542d67d
...@@ -635,6 +635,50 @@ namespace ...@@ -635,6 +635,50 @@ namespace
} }
{
srand(423452);
const long M = 3;
const long N = 3;
typedef matrix<double,0,0> mat;
matrix<double,0,0,memory_manager<char>::kernel_1a, column_major_layout> a(M,N);
for (long r = 0; r < a.nr(); ++r)
{
for (long c = 0; c < a.nc(); ++c)
{
a(r,c) = 10*((double)::rand())/RAND_MAX;
}
}
matrix<double,M,M,memory_manager<char>::kernel_1a, column_major_layout> u, u2;
matrix<double,0,0,memory_manager<char>::kernel_1a, column_major_layout> q, q2;
matrix<double,N,N,memory_manager<char>::kernel_1a, column_major_layout> v, v2;
matrix<double,M,N,MM, column_major_layout> a2;
a2 = tmp(a/2);
svd2(true,true,a2+a2,u,q,v);
double err = max(abs(a - subm(u,get_rect(a2+a2))*diagm(q)*trans(v)));
DLIB_TEST_MSG( err < 1e-11,"err: " << err);
using dlib::equal;
DLIB_TEST((equal(trans(u)*u , identity_matrix<double,M>(), 1e-10)));
DLIB_TEST((equal(trans(v)*v , identity_matrix<double,N>(), 1e-10)));
svd2(false,true,a2+a2,u,q,v2);
svd2(true,false,a2+a2,u2,q,v);
svd2(false,false,a2+a2,u,q2,v);
err = max(abs(a - subm(u2,get_rect(a2+a2))*diagm(q2)*trans(v2)));
DLIB_TEST_MSG( err < 1e-11,"err: " << err);
DLIB_TEST((equal(trans(u2)*u2 , identity_matrix<double,M>(), 1e-10)));
DLIB_TEST((equal(trans(v2)*v2 , identity_matrix<double,N>(), 1e-10)));
}
{ {
srand(423452); srand(423452);
...@@ -826,6 +870,30 @@ namespace ...@@ -826,6 +870,30 @@ namespace
DLIB_TEST( sum(round(1e10*(a - u*w*trans(v)))) == 0); DLIB_TEST( sum(round(1e10*(a - u*w*trans(v)))) == 0);
} }
{
srand(53234);
const long M = 9;
const long N = 40;
typedef matrix<double,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
mat a(M,N);
for (long r = 0; r < a.nr(); ++r)
{
for (long c = 0; c < a.nc(); ++c)
{
a(r,c) = 10*((double)::rand())/RAND_MAX;
}
}
mat u;
mat w;
mat v;
svd(a,u,w,v);
DLIB_TEST( sum(round(1e10*(a - u*w*trans(v)))) == 0);
}
{ {
matrix<double> a(3,3); matrix<double> a(3,3);
......
...@@ -129,6 +129,8 @@ namespace ...@@ -129,6 +129,8 @@ namespace
test_cholesky(uniform_matrix<double>(15,15,1) + 10*symm(randmat<double>(15,15))); test_cholesky(uniform_matrix<double>(15,15,1) + 10*symm(randmat<double>(15,15)));
test_cholesky(uniform_matrix<double>(101,101,1) + 10*symm(randmat<double>(101,101))); test_cholesky(uniform_matrix<double>(101,101,1) + 10*symm(randmat<double>(101,101)));
typedef matrix<double,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
test_cholesky(mat(uniform_matrix<double>(101,101,1) + 10*symm(randmat<double>(101,101))));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -140,6 +142,8 @@ namespace ...@@ -140,6 +142,8 @@ namespace
test_cholesky(uniform_matrix<float>(2,2,1) + 2*symm(randmat<float>(2,2))); test_cholesky(uniform_matrix<float>(2,2,1) + 2*symm(randmat<float>(2,2)));
test_cholesky(uniform_matrix<float>(3,3,1) + 2*symm(randmat<float>(3,3))); test_cholesky(uniform_matrix<float>(3,3,1) + 2*symm(randmat<float>(3,3)));
typedef matrix<float,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
test_cholesky(mat(uniform_matrix<float>(3,3,1) + 2*symm(randmat<float>(3,3))));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -137,11 +137,26 @@ namespace ...@@ -137,11 +137,26 @@ namespace
template <typename matrix_type> template <typename matrix_type>
void test_eigenvalue ( const matrix_type& m ) void test_eigenvalue ( const matrix_type& m )
{ {
eigenvalue_decomposition<matrix_type> test(m); typedef typename matrix_type::type type;
test_eigenvalue_impl(m, test); typedef typename matrix_type::mem_manager_type MM;
matrix<type,matrix_type::NR, matrix_type::NC, MM, row_major_layout> mr(m);
matrix<type,matrix_type::NR, matrix_type::NC, MM, column_major_layout> mc(m);
{
eigenvalue_decomposition<matrix_type> test(mr);
test_eigenvalue_impl(mr, test);
eigenvalue_decomposition<matrix_type> test_symm(make_symmetric(mr));
test_eigenvalue_impl(make_symmetric(mr), test_symm);
}
{
eigenvalue_decomposition<matrix_type> test(mc);
test_eigenvalue_impl(mc, test);
eigenvalue_decomposition<matrix_type> test_symm(make_symmetric(m)); eigenvalue_decomposition<matrix_type> test_symm(make_symmetric(mc));
test_eigenvalue_impl(make_symmetric(m), test_symm); test_eigenvalue_impl(make_symmetric(mc), test_symm);
}
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -156,6 +156,10 @@ namespace ...@@ -156,6 +156,10 @@ namespace
test_lu(10*randmat<double,137,200>()); test_lu(10*randmat<double,137,200>());
test_lu(10*randmat<double,200,101>()); test_lu(10*randmat<double,200,101>());
typedef matrix<double,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
test_lu(mat(3*randmat<double>(4,4)));
test_lu(mat(3*randmat<double>(9,4)));
test_lu(mat(3*randmat<double>(3,8)));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -182,6 +186,10 @@ namespace ...@@ -182,6 +186,10 @@ namespace
test_lu(3*randmat<float,137,200>()); test_lu(3*randmat<float,137,200>());
test_lu(3*randmat<float,200,101>()); test_lu(3*randmat<float,200,101>());
typedef matrix<float,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
test_lu(mat(3*randmat<float>(4,4)));
test_lu(mat(3*randmat<float>(9,4)));
test_lu(mat(3*randmat<float>(3,8)));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -149,6 +149,9 @@ namespace ...@@ -149,6 +149,9 @@ namespace
test_qr(10*randmat<double,15,15>()); test_qr(10*randmat<double,15,15>());
test_qr(10*randmat<double,100,100>()); test_qr(10*randmat<double,100,100>());
typedef matrix<double,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
test_qr(mat(3*randmat<double>(9,4)));
test_qr(mat(3*randmat<double>(9,9)));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -169,6 +172,9 @@ namespace ...@@ -169,6 +172,9 @@ namespace
test_qr(3*randmat<float,4,4>()); test_qr(3*randmat<float,4,4>());
test_qr(3*randmat<float,9,4>()); test_qr(3*randmat<float,9,4>());
typedef matrix<float,0,0,memory_manager<char>::kernel_1a, column_major_layout> mat;
test_qr(mat(3*randmat<float>(9,4)));
test_qr(mat(3*randmat<float>(9,9)));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
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