common: add qmat::transpose()
This commit is contained in:
parent
f03fc2183c
commit
aa74b76815
|
|
@ -984,6 +984,17 @@ public:
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr qmat<T, NCol, NRow> transpose() const
|
||||||
|
{
|
||||||
|
qmat<T, NCol, NRow> res;
|
||||||
|
for (size_t i = 0; i < NRow; i++) {
|
||||||
|
for (size_t j = 0; j < NCol; j++) {
|
||||||
|
res.at(j, i) = at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fmt support
|
// Fmt support
|
||||||
|
|
|
||||||
|
|
@ -294,3 +294,21 @@ TEST_SUITE("common")
|
||||||
CHECK(texture->height_scale == 1);
|
CHECK(texture->height_scale == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_SUITE("qmat")
|
||||||
|
{
|
||||||
|
TEST_CASE("transpose")
|
||||||
|
{
|
||||||
|
// clang-format off
|
||||||
|
auto in = qmat<float, 2, 3>::row_major(
|
||||||
|
{1.0, 2.0, 3.0,
|
||||||
|
4.0, 5.0, 6.0});
|
||||||
|
auto exp = qmat<float, 3, 2>::row_major(
|
||||||
|
{1.0, 4.0,
|
||||||
|
2.0, 5.0,
|
||||||
|
3.0, 6.0});
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
CHECK(in.transpose() == exp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue