Fix matrix multiplication

This commit is contained in:
Maarten L. Hekkelman
2026-03-04 20:28:04 +01:00
parent fdc3972ec0
commit 6eb8857877
2 changed files with 15 additions and 3 deletions

View File

@@ -536,7 +536,7 @@ class matrix_matrix_multiplication : public matrix_expression<matrix_matrix_mult
: m_m1(m1)
, m_m2(m2)
{
assert(m1.dim_m() == m2.dim_n());
assert(m1.dim_n() == m2.dim_m());
}
[[nodiscard]] constexpr std::size_t dim_m() const { return m_m1.dim_m(); } ///< Return dimension m
@@ -549,7 +549,7 @@ class matrix_matrix_multiplication : public matrix_expression<matrix_matrix_mult
value_type result = {};
for (std::size_t k = 0; k < m_m1.dim_m(); ++k)
for (std::size_t k = 0; k < m_m1.dim_n(); ++k)
result += m_m1(i, k) * m_m2(k, j);
return result;

View File

@@ -85,7 +85,7 @@ TEST_CASE("m4")
}
};
// std::cout << m << "\n\n";
std::cout << m << "\n\n";
// std::cout << cif::matrix3x3<int>(cif::sub_matrix<decltype(m)>(m, 0, 0)) << "\n\n";
// std::cout << cif::matrix3x3<int>(cif::sub_matrix<decltype(m)>(m, 0, 1)) << "\n\n";
@@ -100,4 +100,16 @@ TEST_CASE("m4")
CHECK(cif::determinant(m) == 332);
}
// --------------------------------------------------------------------
TEST_CASE("m5")
{
cif::matrix4x4<float> m = cif::identity_matrix<float>(4);
cif::matrix_fixed<float, 1, 4> v({ 0, 0.5f, 0, 1.0f });
auto mv = v * m;
CHECK(mv == v);
}