Skip to content

Commit c448bbb

Browse files
committed
BMat8::one(size_t)
1 parent 93e91f1 commit c448bbb

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

include/bmat8.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,19 @@ class BMat8 {
291291
//! Returns the identity BMat8
292292
//!
293293
//! This method returns the 8 x 8 BMat8 with 1s on the main diagonal.
294-
static BMat8 one() { return BMat8(0x8040201008040201); }
294+
static BMat8 one(size_t dim = 8) {
295+
HPCOMBI_ASSERT(dim <= 8);
296+
static std::array<uint64_t, 9> const ones = {0x0000000000000000,
297+
0x8000000000000000,
298+
0x8040000000000000,
299+
0x8040200000000000,
300+
0x8040201000000000,
301+
0x8040201008000000,
302+
0x8040201008040000,
303+
0x8040201008040200,
304+
0x8040201008040201};
305+
return BMat8(ones[dim]);
306+
}
295307

296308
//! Returns a random BMat8
297309
//!

tests/test_bmat8.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ struct Fix {
101101
//****************************************************************************//
102102
BOOST_AUTO_TEST_SUITE(BMat8_test)
103103
//****************************************************************************//
104+
BOOST_FIXTURE_TEST_CASE(BMat8_one, Fix) {
105+
BOOST_TEST(BMat8::one(0) == zero);
106+
BOOST_TEST(BMat8::one(2) == BMat8(
107+
{{1, 0, 0, 0, 0, 0, 0, 0},
108+
{0, 1, 0, 0, 0, 0, 0, 0},
109+
{0, 0, 0, 0, 0, 0, 0, 0},
110+
{0, 0, 0, 0, 0, 0, 0, 0},
111+
{0, 0, 0, 0, 0, 0, 0, 0},
112+
{0, 0, 0, 0, 0, 0, 0, 0},
113+
{0, 0, 0, 0, 0, 0, 0, 0},
114+
{0, 0, 0, 0, 0, 0, 0, 0}}));
115+
BOOST_TEST(BMat8::one(5) == BMat8(
116+
{{1, 0, 0, 0, 0, 0, 0, 0},
117+
{0, 1, 0, 0, 0, 0, 0, 0},
118+
{0, 0, 1, 0, 0, 0, 0, 0},
119+
{0, 0, 0, 1, 0, 0, 0, 0},
120+
{0, 0, 0, 0, 1, 0, 0, 0},
121+
{0, 0, 0, 0, 0, 0, 0, 0},
122+
{0, 0, 0, 0, 0, 0, 0, 0},
123+
{0, 0, 0, 0, 0, 0, 0, 0}}));
124+
BOOST_TEST(BMat8::one(8) == BMat8::one());
125+
}
126+
104127
BOOST_FIXTURE_TEST_CASE(BMat8_transpose, Fix) {
105128
BOOST_TEST(zero.transpose() == zero);
106129
BOOST_TEST(bm2.transpose() == bm2t);

0 commit comments

Comments
 (0)