diff --git a/include/common/qvec.hh b/include/common/qvec.hh index b073463a..207be1b4 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -984,6 +984,17 @@ public: } return res; } + + [[nodiscard]] constexpr qmat transpose() const + { + qmat 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 diff --git a/tests/test_common.cc b/tests/test_common.cc index f5c8ab09..bfefe840 100644 --- a/tests/test_common.cc +++ b/tests/test_common.cc @@ -294,3 +294,21 @@ TEST_SUITE("common") CHECK(texture->height_scale == 1); } } + +TEST_SUITE("qmat") +{ + TEST_CASE("transpose") + { + // clang-format off + auto in = qmat::row_major( + {1.0, 2.0, 3.0, + 4.0, 5.0, 6.0}); + auto exp = qmat::row_major( + {1.0, 4.0, + 2.0, 5.0, + 3.0, 6.0}); + // clang-format on + + CHECK(in.transpose() == exp); + } +}