From 0c1557f99aaaa2ff2fef07a81d52890bb35b40b4 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Mon, 23 Sep 2024 13:15:36 -0500 Subject: [PATCH] trying to get the same matrix --- .../unit/solver/test_linear_solver_policy.hpp | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/test/unit/solver/test_linear_solver_policy.hpp b/test/unit/solver/test_linear_solver_policy.hpp index 6e301f188..f8d4d0cac 100644 --- a/test/unit/solver/test_linear_solver_policy.hpp +++ b/test/unit/solver/test_linear_solver_policy.hpp @@ -209,19 +209,35 @@ void testExtremeInitialValue(std::size_t number_of_blocks, double initial_value) { using FloatingPointType = typename MatrixPolicy::value_type; - uint8_t seed = (uint8_t)345; - std::mt19937 generator(seed); + // uint8_t seed = (uint8_t)345; + // std::mt19937 generator(seed); // std::default_random_engine generator(seed); - auto gen_bool = std::bind(std::uniform_int_distribution<>(0, 1), generator); - auto get_double = std::bind(std::lognormal_distribution(-2.0, 2.0), generator); + // auto gen_bool = std::bind(std::uniform_int_distribution<>(0, 1), generator); + // auto get_double = std::bind(std::lognormal_distribution(-2.0, 2.0), generator); const size_t size = 5; + std::vector> non_zeros = { + {0, 0}, + {0, 4}, + + {1, 1}, + + {2, 2}, + + {3, 3}, + + {4, 4}, + {4, 0}, + }; + auto builder = SparseMatrixPolicy::Create(size).SetNumberOfBlocks(number_of_blocks).InitialValue(1e-30); - for (std::size_t i = 0; i < size; ++i) - for (std::size_t j = 0; j < size; ++j) - if (i == j || gen_bool()) - builder = builder.WithElement(i, j); + for (const auto& [i, j] : non_zeros) { + builder = builder.WithElement(i, j); + } + // for (std::size_t i = 0; i < size; ++i) + // for (std::size_t j = 0; j < size; ++j) + // if (i == j || gen_bool()) SparseMatrixPolicy A(builder); MatrixPolicy b(number_of_blocks, size, 0.0); @@ -231,11 +247,11 @@ void testExtremeInitialValue(std::size_t number_of_blocks, double initial_value) for (std::size_t j = 0; j < size; ++j) if (!A.IsZero(i, j)) for (std::size_t i_block = 0; i_block < number_of_blocks; ++i_block) - A[i_block][i][j] = get_double(); + A[i_block][i][j] = (i+1) * (j+1); for (std::size_t i = 0; i < size; ++i) for (std::size_t i_block = 0; i_block < number_of_blocks; ++i_block) - b[i_block][i] = get_double(); + b[i_block][i] = (i+1) * i_block; x = b;