diff --git a/include/xerus/arpackWrapper.h b/include/xerus/arpackWrapper.h index ec8cb6ec763035bc642853c54321b1a4d63c87fa..82d66a7b7ca77eca2f923ce550ed102f87ac5123 100644 --- a/include/xerus/arpackWrapper.h +++ b/include/xerus/arpackWrapper.h @@ -29,6 +29,7 @@ #include // fix for non standard-conform complex implementation #undef I +#define J _Complex_I #ifdef __has_include #if __has_include("arpack.hpp") diff --git a/src/unitTests/fullTensor_add_sub.cxx b/src/unitTests/fullTensor_add_sub.cxx index 7a8fe68c36f15526e73fc851eceba8c4cda09286..0ed6740f65c0723a9863867da03e1c253d8b5068 100644 --- a/src/unitTests/fullTensor_add_sub.cxx +++ b/src/unitTests/fullTensor_add_sub.cxx @@ -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; diff --git a/src/unitTests/fullTensor_assignment.cxx b/src/unitTests/fullTensor_assignment.cxx index 371eb11cd5dafeb5595dd804ea04e94a09eb79a0..dc4b2494d3610fd23eca7da0f407a9ec540a0773 100644 --- a/src/unitTests/fullTensor_assignment.cxx +++ b/src/unitTests/fullTensor_assignment.cxx @@ -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 + diff --git a/src/unitTests/fullTensor_product.cxx b/src/unitTests/fullTensor_product.cxx index 3f64c785f56996d0ec6c531160d3fe94846a6cff..a1f1ad6a509ff9c7971c956b1f9bae323e409707 100644 --- a/src/unitTests/fullTensor_product.cxx +++ b/src/unitTests/fullTensor_product.cxx @@ -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 &_idx) { return double(_idx[0] + _idx[1]); }); Tensor B({1000,1000}, [] (const std::vector &_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); }); diff --git a/src/unitTests/sparseTensor_add_sub_cpy.cxx b/src/unitTests/sparseTensor_add_sub_cpy.cxx index 17f2ef86744ac29b378fcfc3ac781b6614010d82..a79a8644bd17a302afa5a8adc8dd19cb750866bc 100644 --- a/src/unitTests/sparseTensor_add_sub_cpy.cxx +++ b/src/unitTests/sparseTensor_add_sub_cpy.cxx @@ -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; diff --git a/src/unitTests/sparseTensor_assignment_cpy.cxx b/src/unitTests/sparseTensor_assignment_cpy.cxx index b864980bfbf9133955bb933995505d703d8e4966..78ad58e60676399d6d5cb341d1322e7634f653ae 100644 --- a/src/unitTests/sparseTensor_assignment_cpy.cxx +++ b/src/unitTests/sparseTensor_assignment_cpy.cxx @@ -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 + diff --git a/src/unitTests/sparseTensor_product_cpy.cxx b/src/unitTests/sparseTensor_product_cpy.cxx index 8735dfda4043b53b2c27a35def6f08167cca03e8..ba9230aebe18fde00c5c87e7a7f5a1f201fbad2e 100644 --- a/src/unitTests/sparseTensor_product_cpy.cxx +++ b/src/unitTests/sparseTensor_product_cpy.cxx @@ -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})); }); diff --git a/src/xerus/python/blocktt.cpp b/src/xerus/python/blocktt.cpp index 56a7bf594d0f705e9865542ceb8b2c7c921147e8..d9b59a309202ecdc9f64d65cf9f037c9415fe715 100644 --- a/src/xerus/python/blocktt.cpp +++ b/src/xerus/python/blocktt.cpp @@ -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(&frob_norm)); diff --git a/src/xerus/ttNetwork.cpp b/src/xerus/ttNetwork.cpp index 48da0c1b1c40375a06dc4d592b1504de18c69ba1..93819cab703385599b97559ca8314126d3d911b7 100644 --- a/src/xerus/ttNetwork.cpp +++ b/src/xerus/ttNetwork.cpp @@ -660,7 +660,11 @@ namespace xerus { void TTNetwork::round(const std::vector& _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.");