Skip to content

Commit c7cd267

Browse files
committed
moved generation correctness tests to reference
1 parent 2ad6948 commit c7cd267

2 files changed

Lines changed: 67 additions & 76 deletions

File tree

core/test/reorder/multicolor.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <ginkgo/core/reorder/multicolor.hpp>
1111

1212
#include "core/test/utils.hpp"
13-
#include "core/test/utils/matrix_generator.hpp"
14-
#include "core/test/utils/reordering.hpp"
1513

1614

1715
template <typename IndexType>
@@ -37,64 +35,3 @@ TYPED_TEST(Multicolor, MulticolorFactoryKnowsItsExecutor)
3735
{
3836
ASSERT_EQ(this->mc_factory->get_executor(), this->exec);
3937
}
40-
41-
TYPED_TEST(Multicolor, GeneratesCorrectOrderingWithCsrInput)
42-
{
43-
using v_type = typename TestFixture::v_type;
44-
using i_type = typename TestFixture::i_type;
45-
const gko::dim<2> grid{5, 5};
46-
auto expected =
47-
gko::test::compute_multicolor_ordering_regular_star<i_type>(grid);
48-
const auto size = 25u;
49-
auto mdata =
50-
gko::test::generate_laplacian_2d_5point_matrix_data<v_type, i_type>(
51-
grid);
52-
auto mat = gko::share(gko::matrix::Csr<v_type, i_type>::create(this->exec));
53-
mat->read(mdata);
54-
55-
auto mc = this->mc_factory->generate(mat);
56-
57-
auto color_ptrs_arr = mc->get_color_pointers();
58-
auto perm = mc->get_permutation()->get_const_permutation();
59-
auto iperm = mc->get_inverse_permutation()->get_const_permutation();
60-
const auto permv = std::vector<i_type>(perm, perm + size);
61-
const auto ipermv = std::vector<i_type>(iperm, iperm + size);
62-
const auto color_ptrs = std::vector<i_type>(
63-
color_ptrs_arr.get_const_data(),
64-
color_ptrs_arr.get_const_data() + color_ptrs_arr.get_size());
65-
EXPECT_EQ(color_ptrs, expected.color_ptrs);
66-
EXPECT_EQ(permv, expected.old_to_new);
67-
EXPECT_EQ(ipermv, expected.new_to_old);
68-
}
69-
70-
TYPED_TEST(Multicolor, GeneratesCorrectOrderingWithSparsityCsrInput)
71-
{
72-
using v_type = typename TestFixture::v_type;
73-
using i_type = typename TestFixture::i_type;
74-
const gko::dim<2> grid{5, 5};
75-
auto expected =
76-
gko::test::compute_multicolor_ordering_regular_star<i_type>(grid);
77-
const auto size = 25u;
78-
auto mdata =
79-
gko::test::generate_laplacian_2d_5point_matrix_data<v_type, i_type>(
80-
grid);
81-
auto mat = gko::matrix::Csr<v_type, i_type>::create(this->exec);
82-
mat->read(mdata);
83-
auto smat = gko::share(
84-
gko::matrix::SparsityCsr<v_type, i_type>::create(this->exec));
85-
mat->convert_to(smat.get());
86-
87-
auto mc = this->mc_factory->generate(smat);
88-
89-
auto color_ptrs_arr = mc->get_color_pointers();
90-
auto perm = mc->get_permutation()->get_const_permutation();
91-
auto iperm = mc->get_inverse_permutation()->get_const_permutation();
92-
const auto permv = std::vector<i_type>(perm, perm + size);
93-
const auto ipermv = std::vector<i_type>(iperm, iperm + size);
94-
const auto color_ptrs = std::vector<i_type>(
95-
color_ptrs_arr.get_const_data(),
96-
color_ptrs_arr.get_const_data() + color_ptrs_arr.get_size());
97-
EXPECT_EQ(color_ptrs, expected.color_ptrs);
98-
EXPECT_EQ(permv, expected.old_to_new);
99-
EXPECT_EQ(ipermv, expected.new_to_old);
100-
}

reference/test/reorder/multicolor_kernels.cpp

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ class Multicolor : public ::testing::Test {
4444
std::shared_ptr<const gko::ReferenceExecutor> exec;
4545
std::shared_ptr<CsrMtx> laplace2d5;
4646
std::shared_ptr<CsrMtx> laplace3d27;
47-
48-
static bool is_permutation(const perm_type* input_perm)
49-
{
50-
const auto perm_size = input_perm->get_size()[0];
51-
auto perm_sorted = std::vector<i_type>(perm_size);
52-
std::copy_n(input_perm->get_const_permutation(), perm_size,
53-
perm_sorted.begin());
54-
std::sort(perm_sorted.begin(), perm_sorted.end());
55-
auto identity = std::vector<i_type>(perm_size);
56-
std::iota(identity.begin(), identity.end(), 0);
57-
return identity == perm_sorted;
58-
}
5947
};
6048

6149

@@ -116,7 +104,6 @@ TEST_F(Multicolor, CreatesCorrectColorPtrs3d27p)
116104
}
117105
}
118106

119-
120107
TEST_F(Multicolor, CreatesCorrectPermutations3d27p)
121108
{
122109
const auto nrows = static_cast<i_type>(dims3[0] * dims3[1] * dims3[2]);
@@ -134,3 +121,70 @@ TEST_F(Multicolor, CreatesCorrectPermutations3d27p)
134121
EXPECT_EQ(expected_ordering.old_to_new, perm);
135122
EXPECT_EQ(expected_ordering.new_to_old, invperm);
136123
}
124+
125+
126+
class MulticolorGenerate : public ::testing::Test {
127+
protected:
128+
using v_type = float;
129+
using i_type = int;
130+
using CsrMtx = gko::matrix::Csr<v_type, i_type>;
131+
using reorder_type = gko::reorder::Multicolor<v_type, i_type>;
132+
133+
MulticolorGenerate()
134+
: exec(gko::ReferenceExecutor::create()),
135+
mc_factory(reorder_type::build().on(exec))
136+
{
137+
auto mdata5 =
138+
gko::test::generate_laplacian_2d_5point_matrix_data<v_type, i_type>(
139+
dims2);
140+
laplace2d5 = gko::share(CsrMtx::create(exec));
141+
laplace2d5->read(mdata5);
142+
expected =
143+
gko::test::compute_multicolor_ordering_regular_star<i_type>(dims2);
144+
}
145+
146+
const gko::dim<2> dims2{5, 5};
147+
const gko::size_type size = 25;
148+
std::shared_ptr<const gko::ReferenceExecutor> exec;
149+
gko::test::MulticolorOrdering<i_type> expected;
150+
std::shared_ptr<CsrMtx> laplace2d5;
151+
std::unique_ptr<typename reorder_type::Factory> mc_factory;
152+
};
153+
154+
TEST_F(MulticolorGenerate, GeneratesCorrectOrderingWithCsrInput)
155+
{
156+
auto mc = this->mc_factory->generate(laplace2d5);
157+
158+
auto color_ptrs_arr = mc->get_color_pointers();
159+
auto perm = mc->get_permutation()->get_const_permutation();
160+
auto iperm = mc->get_inverse_permutation()->get_const_permutation();
161+
const auto permv = std::vector<i_type>(perm, perm + size);
162+
const auto ipermv = std::vector<i_type>(iperm, iperm + size);
163+
const auto color_ptrs = std::vector<i_type>(
164+
color_ptrs_arr.get_const_data(),
165+
color_ptrs_arr.get_const_data() + color_ptrs_arr.get_size());
166+
EXPECT_EQ(color_ptrs, expected.color_ptrs);
167+
EXPECT_EQ(permv, expected.old_to_new);
168+
EXPECT_EQ(ipermv, expected.new_to_old);
169+
}
170+
171+
TEST_F(MulticolorGenerate, GeneratesCorrectOrderingWithSparsityCsrInput)
172+
{
173+
auto smat = gko::share(
174+
gko::matrix::SparsityCsr<v_type, i_type>::create(this->exec));
175+
laplace2d5->convert_to(smat.get());
176+
177+
auto mc = this->mc_factory->generate(smat);
178+
179+
auto color_ptrs_arr = mc->get_color_pointers();
180+
auto perm = mc->get_permutation()->get_const_permutation();
181+
auto iperm = mc->get_inverse_permutation()->get_const_permutation();
182+
const auto permv = std::vector<i_type>(perm, perm + size);
183+
const auto ipermv = std::vector<i_type>(iperm, iperm + size);
184+
const auto color_ptrs = std::vector<i_type>(
185+
color_ptrs_arr.get_const_data(),
186+
color_ptrs_arr.get_const_data() + color_ptrs_arr.get_size());
187+
EXPECT_EQ(color_ptrs, expected.color_ptrs);
188+
EXPECT_EQ(permv, expected.old_to_new);
189+
EXPECT_EQ(ipermv, expected.new_to_old);
190+
}

0 commit comments

Comments
 (0)