Commit 228bd310 authored by Michael Goette's avatar Michael Goette

fixed bug with extra dimensions

parent 1f230933
Pipeline #1030 passed with stages
in 10 minutes and 14 seconds
......@@ -268,3 +268,42 @@ static misc::UnitTest tensor_solve_matrix("Tensor", "solve_matrix", [](){
MTEST(frob_norm(residual) < 1e-10, frob_norm(residual));
}
});
static misc::UnitTest tensor_solve_w_extra_degree("Tensor", "solve with extra degrees", [](){
Index ii,jj,kk,ll,mm,nn;
Tensor A = xerus::Tensor::random({2,2});
Tensor B = xerus::Tensor::random({2,2});
Tensor X({2,2});
Tensor tmp({2,2});
//non symmetric
xerus::solve(X, A, B,1);
tmp(ii,kk) = A(ii,jj)*X(jj,kk);
TEST((tmp - B).frob_norm() < 1e-13);
//symmetric
A(ii,jj) = A(ii,jj) + A(jj,ii);
xerus::solve(X, A, B,1);
tmp(ii,kk) = A(ii,jj)*X(jj,kk);
TEST((tmp - B).frob_norm() < 1e-13);
//higher order
Tensor A2 = xerus::Tensor::random({5,5,5,5});
Tensor B2 = xerus::Tensor::random({5,5,5,5});
Tensor X2({5,5,5,5});
Tensor tmp2({5,5,5,5});
xerus::solve(X2, A2, B2,2);
tmp2(ii^2,kk^2) = A2(ii^2,jj^2)*X2(jj^2,kk^2);
TEST((tmp2 - B2).frob_norm() < 1e-13);
Tensor A3 = xerus::Tensor::random({5,5,5,5});
Tensor B3 = xerus::Tensor::random({5,5,5});
Tensor X3({5,5,5});
Tensor tmp3({5,5,5});
xerus::solve(X3, A3, B3,1);
tmp3(ii^2,kk) = A3(ii^2,jj^2)*X3(jj^2,kk);
TEST((tmp3 - B3).frob_norm() < 1e-13);
});
......@@ -565,7 +565,7 @@ namespace xerus {
std::unique_ptr<int[]> pivot(new int[_n]);
misc::copy(_x, _b, _n);
misc::copy(_x, _b, _n*_nrhs);
IF_CHECK( int lapackAnswer = ) LAPACKE_dgesv(
LAPACK_ROW_MAJOR,
......@@ -605,7 +605,7 @@ namespace xerus {
LOG(debug, "cholesky");
XERUS_PA_START;
misc::copy(_x, _b, _n);
misc::copy(_x, _b, _n*_nrhs);
lapackAnswer = LAPACKE_dpotrs(
LAPACK_ROW_MAJOR,
......@@ -632,7 +632,7 @@ namespace xerus {
// non-definite diagonal or choleksy failed -> fallback to LDL^T decomposition
XERUS_PA_START;
misc::copy(_x, _b, _n);
misc::copy(_x, _b, _n*_nrhs);
std::unique_ptr<int[]> pivot(new int[_n]);
LAPACKE_dsysv(
......
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