@@ -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-
120107TEST_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