Commit 6bbc5152 authored by Sebastian Wolf's avatar Sebastian Wolf

Merge branch 'development' of git:xerus/xerus into development

parents cf1400f7 9e997ad9
Pipeline #1978 failed with stages
in 12 minutes and 52 seconds
......@@ -29,6 +29,7 @@
#include <complex.h>
// fix for non standard-conform complex implementation
#undef I
#define J _Complex_I
#ifdef __has_include
#if __has_include("arpack.hpp")
......
......@@ -31,7 +31,7 @@ static misc::UnitTest tensor_sum_mat2("Tensor", "sum_matrix_2x2", [](){
Tensor B({2,2});
Tensor C({2,2});
Index i, J;
Index i, j;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -43,9 +43,9 @@ static misc::UnitTest tensor_sum_mat2("Tensor", "sum_matrix_2x2", [](){
C[{1,0}]=7;
C[{1,1}]=8;
res(i,J) = B(i,J) + C(i,J);
res(i,j) = B(i,j) + C(i,j);
TEST(approx_entrywise_equal(res, {6,8,10,12}));
res(i,J) = B(i,J) + C(J,i);
res(i,j) = B(i,j) + C(j,i);
TEST(approx_entrywise_equal(res, {6,9,9,12}));
});
......@@ -53,7 +53,7 @@ static misc::UnitTest tensor_sum_eq("Tensor", "sum_lhs_equals_rhs", []() {
Tensor B({2,2});
Tensor C({2,2});
Index i, J;
Index i, j;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -65,9 +65,9 @@ static misc::UnitTest tensor_sum_eq("Tensor", "sum_lhs_equals_rhs", []() {
C[{1,0}]=7;
C[{1,1}]=8;
B(i,J) = B(i,J) + C(i,J);
B(i,j) = B(i,j) + C(i,j);
TEST(approx_entrywise_equal(B, {6,8,10,12}));
B(i,J) = B(i,J) + B(J,i);
B(i,j) = B(i,j) + B(j,i);
TEST(approx_entrywise_equal(B, {12,18,18,24}));
});
......@@ -83,11 +83,11 @@ static misc::UnitTest tensor_sum_mat1000("Tensor", "sum_matrix_1000x1000", [](){
return double(_idx[0] + _idx[1] + _idx[0] * _idx[1]);
});
Index i, J;
Index i, j;
res(i,J) = A(i,J) + B(i,J);
res(i,j) = A(i,j) + B(i,j);
TEST(approx_entrywise_equal(res, C, 1e-14));
res(J,i) = A(J,i) + B(i,J);
res(j,i) = A(j,i) + B(i,j);
TEST(approx_entrywise_equal(res, C, 1e-14));
});
......@@ -96,7 +96,7 @@ static misc::UnitTest tensor_dyadic("Tensor", "sum_dyadic", [](){
Tensor B({2});
Tensor C({2});
Index i, J, K;
Index i, j, k;
B[0]=1;
B[1]=2;
......@@ -104,7 +104,7 @@ static misc::UnitTest tensor_dyadic("Tensor", "sum_dyadic", [](){
C[0]=5;
C[1]=9;
FAILTEST(res(i,J) = B(i) + C(J));
FAILTEST(res(i,j) = B(i) + C(j));
// TEST(approx_entrywise_equal(res, {6,10,7,11}));
});
......@@ -114,7 +114,7 @@ static misc::UnitTest tensor_sum_threefold("Tensor", "sum_threefold_sum", [](){
Tensor C({2});
Tensor D({2});
Index i, J, K;
Index i, j, k;
B[0]=1;
B[1]=2;
......
......@@ -207,7 +207,7 @@ static misc::UnitTest tensor_assign_eq("Tensor", "Assignment_LHS_Equals_RHS", []
Tensor B({2,2});
Tensor C({2,2});
Index i, J, K;
Index i, j, k;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -219,9 +219,9 @@ static misc::UnitTest tensor_assign_eq("Tensor", "Assignment_LHS_Equals_RHS", []
C[{1,0}]=7;
C[{1,1}]=8;
B(i,J) = B(i,J);
B(i,j) = B(i,j);
TEST(approx_entrywise_equal(B, {1,2,3,4}));
B(i,J) = B(J,i);
B(i,j) = B(j,i);
TEST(approx_entrywise_equal(B, {1,3,2,4}));
});
......@@ -320,4 +320,4 @@ static misc::UnitTest tensor_assign_neg("Tensor", "Assignment_Negatives", [](){
});
\ No newline at end of file
......@@ -318,7 +318,7 @@ static misc::UnitTest tensor_prod_three("Tensor", "Product_Threefold", [](){
Tensor C({2,2});
Tensor D({2,2});
Index i, J, K, L;
Index i, j, k, l;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -335,13 +335,13 @@ static misc::UnitTest tensor_prod_three("Tensor", "Product_Threefold", [](){
D[{1,0}]=11;
D[{1,1}]=12;
res(i,L) = B(i,J) * C(J,K) * D(K,L);
res(i,l) = B(i,j) * C(j,k) * D(k,l);
TEST(approx_entrywise_equal(res, {413, 454, 937, 1030}));
res(i,L) = B(i,J) * C(K,L) * D(J,K);
res(i,l) = B(i,j) * C(k,l) * D(j,k);
TEST(approx_entrywise_equal(res, {393, 458, 901, 1050}));
res(i,L) = B(K,L) * C(i,J) * D(J,K);
res(i,l) = B(k,l) * C(i,j) * D(j,k);
TEST(approx_entrywise_equal(res, {477, 710, 649, 966}));
res(i,L) = B(J,K) * C(K,L) * D(i,J);
res(i,l) = B(j,k) * C(k,l) * D(i,j);
TEST(approx_entrywise_equal(res, {601, 698, 725, 842}));
});
......@@ -402,18 +402,18 @@ static misc::UnitTest tensor_prod1000("Tensor", "Product_1000x1000", [](){
Tensor A({1000,1000}, [] (const std::vector<size_t> &_idx) { return double(_idx[0] + _idx[1]); });
Tensor B({1000,1000}, [] (const std::vector<size_t> &_idx) { return double((1000-_idx[0]) * (1000-_idx[1])); });
Tensor C({1000,1000}, Tensor::Representation::Dense);
Index i, J, K;
Index i, j, k;
blasWrapper::matrix_matrix_product(C.get_dense_data(), 1000, 1000, 1.0, A.get_dense_data(), false, 1000, B.get_dense_data(), false);
res(i,K) = A(i,J) * B(J,K);
res(i,k) = A(i,j) * B(j,k);
MTEST(memcmp(res.get_dense_data(), C.get_dense_data(), sizeof(value_t)*1000*1000)==0, "Error: " << frob_norm(res-C));
blasWrapper::matrix_matrix_product(C.get_dense_data(), 1000, 1000, 1.0, A.get_dense_data(), false, 1000, B.get_dense_data(), true);
res(i,K) = A(i,J) * B(K,J);
res(i,k) = A(i,j) * B(k,j);
TEST(memcmp(res.get_dense_data(), C.get_dense_data(), sizeof(value_t)*1000*1000)==0);
blasWrapper::matrix_matrix_product(C.get_dense_data(), 1000, 1000, 1.0, A.get_dense_data(), true, 1000, B.get_dense_data(), true);
res(i,K) = A(J,i) * B(K,J);
res(i,k) = A(j,i) * B(k,j);
TEST(memcmp(res.get_dense_data(), C.get_dense_data(), sizeof(value_t)*1000*1000)==0);
});
......
......@@ -28,7 +28,7 @@ static misc::UnitTest sparse_sum2("SparseTensor", "sum_matrix_2x2", [](){
Tensor B({2,2}, Tensor::Representation::Sparse);
Tensor C({2,2}, Tensor::Representation::Sparse);
Index i, J;
Index i, j;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -43,9 +43,9 @@ static misc::UnitTest sparse_sum2("SparseTensor", "sum_matrix_2x2", [](){
B.use_sparse_representation();
C.use_sparse_representation();
res(i,J) = B(i,J) + C(i,J);
res(i,j) = B(i,j) + C(i,j);
TEST(approx_entrywise_equal(res, {6,8,10,12}));
res(i,J) = B(i,J) + C(J,i);
res(i,j) = B(i,j) + C(j,i);
TEST(approx_entrywise_equal(res, {6,9,9,12}));
});
......@@ -53,7 +53,7 @@ static misc::UnitTest sparse_sum_eq("SparseTensor", "sum_lhs_equals_rhs", [](){
Tensor B({2,2}, Tensor::Representation::Sparse);
Tensor C({2,2}, Tensor::Representation::Sparse);
Index i, J;
Index i, j;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -67,9 +67,9 @@ static misc::UnitTest sparse_sum_eq("SparseTensor", "sum_lhs_equals_rhs", [](){
B.use_sparse_representation();
C.use_sparse_representation();
B(i,J) = B(i,J) + C(i,J);
B(i,j) = B(i,j) + C(i,j);
TEST(approx_entrywise_equal(B, {6,8,10,12}));
B(i,J) = B(i,J) + B(J,i);
B(i,j) = B(i,j) + B(j,i);
TEST(approx_entrywise_equal(B, {12,18,18,24}));
});
......@@ -79,9 +79,9 @@ static misc::UnitTest sparse_dyadicsum("SparseTensor", "sum_dyadic", [](){
Tensor B({2}, Tensor::Representation::Sparse);
Tensor C({2}, Tensor::Representation::Sparse);
Index i, J, K;
Index i, j, k;
FAILTEST(res(i,J) = B(i) + C(J));
FAILTEST(res(i,j) = B(i) + C(j));
});
static misc::UnitTest sparse_sum_three("SparseTensor", "sum_threefold", [](){
......@@ -90,7 +90,7 @@ static misc::UnitTest sparse_sum_three("SparseTensor", "sum_threefold", [](){
Tensor C({2}, Tensor::Representation::Sparse);
Tensor D({2}, Tensor::Representation::Sparse);
Index i, J, K;
Index i, j, k;
B[0]=1;
B[1]=2;
......
......@@ -215,7 +215,7 @@ static misc::UnitTest sparse_assign_eq("SparseTensor", "Assignment_LHS_Equals_RH
Tensor B({2,2}, Tensor::Representation::Sparse);
Tensor C({2,2}, Tensor::Representation::Sparse);
Index i, J, K;
Index i, j, k;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -227,9 +227,9 @@ static misc::UnitTest sparse_assign_eq("SparseTensor", "Assignment_LHS_Equals_RH
C[{1,0}]=7;
C[{1,1}]=8;
B(i,J) = B(i,J);
B(i,j) = B(i,j);
TEST(approx_entrywise_equal(B, {1,2,3,4}));
B(i,J) = B(J,i);
B(i,j) = B(j,i);
TEST(approx_entrywise_equal(B, {1,3,2,4}));
});
......@@ -329,4 +329,4 @@ static misc::UnitTest sparse_assign_neg("SparseTensor", "Assignment_Negatives",
});
\ No newline at end of file
......@@ -325,7 +325,7 @@ static misc::UnitTest sparse_prod_three("SparseTensor", "Product_Threefold", [](
Tensor C({2,2}, Tensor::Representation::Sparse);
Tensor D({2,2}, Tensor::Representation::Sparse);
Index i, J, K, L;
Index i, j, k, l;
B[{0,0}]=1;
B[{0,1}]=2;
......@@ -346,13 +346,13 @@ static misc::UnitTest sparse_prod_three("SparseTensor", "Product_Threefold", [](
B.use_sparse_representation();
C.use_sparse_representation();
res(i,L) = B(i,J) * C(J,K) * D(K,L);
res(i,l) = B(i,j) * C(j,k) * D(k,l);
TEST(approx_entrywise_equal(res, {413, 454, 937, 1030}));
res(i,L) = B(i,J) * C(K,L) * D(J,K);
res(i,l) = B(i,j) * C(k,l) * D(j,k);
TEST(approx_entrywise_equal(res, {393, 458, 901, 1050}));
res(i,L) = B(K,L) * C(i,J) * D(J,K);
res(i,l) = B(k,l) * C(i,j) * D(j,k);
TEST(approx_entrywise_equal(res, {477, 710, 649, 966}));
res(i,L) = B(J,K) * C(K,L) * D(i,J);
res(i,l) = B(j,k) * C(k,l) * D(i,j);
TEST(approx_entrywise_equal(res, {601, 698, 725, 842}));
});
......
......@@ -52,7 +52,7 @@ void expose_blocktt() {
.def("dofs", &BlockTT::dofs)
.def("move_core_left", &BlockTT::move_core_left)
.def("move_core_right", &BlockTT::move_core_left)
.def("move_core_right", &BlockTT::move_core_right)
;
def("frob_norm", static_cast<value_t (*)(const BlockTT&)>(&frob_norm));
......
......@@ -660,7 +660,11 @@ namespace xerus {
void TTNetwork<isOperator>::round(const std::vector<size_t>& _maxRanks, const double _eps) {
require_correct_format();
const size_t numComponents = order()/N;
REQUIRE(_eps < 1, "_eps must be smaller than one. " << _eps << " was given.");
if (numComponents <= 1){
REQUIRE(_eps < 1, "_eps must be smaller than one. " << _eps << " was given.");
} else {
REQUIRE(_eps / std::sqrt(double(numComponents-1)) < 1, "_eps/sqrt(numComponents -1) must be smaller than one. " << (_eps/std::sqrt(double(numComponents-1))) << " was given.");
}
REQUIRE(_maxRanks.size()+1 == numComponents || (_maxRanks.empty() && numComponents == 0), "There must be exactly order/N-1 maxRanks. Here " << _maxRanks.size() << " instead of " << numComponents-1 << " are given.");
REQUIRE(!misc::contains(_maxRanks, size_t(0)), "Trying to round a TTTensor to rank 0 is not possible.");
......
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