Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions include/LinearLib/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,15 @@ namespace LinearLib {
}

/**
* Matrix dot product
* Element-wise multiplication
*/
template<std::size_t I>
Matrix<R, I, T> operator*(const Matrix<C, I, T>& other) const {
Matrix operator*(const Matrix& other) const {

Matrix<R, I, T> res;
Matrix res;

for (std::size_t i = 0; i < R; i++) {
for (std::size_t j = 0; j < I; j++) {
T sum = T{};
for (std::size_t k = 0; k < C; k++) {
sum += data[i][k] * other[k][j];
}
res[i][j] = sum;
for (std::size_t j = 0; j < C; j++) {
res.data[i][j] = data[i][j] * other[i][j];
}
}

Expand Down
27 changes: 0 additions & 27 deletions tests/MatrixTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,6 @@ TEST_CASE("Matrix operations", "[vector]") {
REQUIRE(result[1][1] == 2);
}

SECTION("Matrix dot product") {
const Matrix<2, 2, int> m1 {{1, 2},{3,4}};
const Matrix<2, 2, int> m2 {{5, 6},{7,8}};

const Matrix<2, 2, int> result1 = m1 * m2;

REQUIRE(result1[0][0] == 19);
REQUIRE(result1[0][1] == 22);
REQUIRE(result1[1][0] == 43);
REQUIRE(result1[1][1] == 50);

const Matrix<3, 3, int> m3 {{1, 1, 3},
{-1, 4, 1},
{0, 2, -2}};
const Matrix<3, 1, int> m4 {{1},
{0},
{-1}};

const Matrix<3, 1, int> result2 = m3 * m4;

REQUIRE(result2[0][0] == -2);
REQUIRE(result2[1][0] == -2);
REQUIRE(result2[2][0] == 2);


}

SECTION("Matrix multiplication") {
const Matrix<2, 4, int> m1 {{5, 3, 3, 4},
{2, 4, 4, 3}};
Expand Down