Skip to content

Commit

Permalink
trying to get the same matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Sep 23, 2024
1 parent 5b7967e commit 0c1557f
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions test/unit/solver/test_linear_solver_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::size_t, std::size_t>> 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);
Expand All @@ -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;

Expand Down

0 comments on commit 0c1557f

Please sign in to comment.