Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
pjessesco committed Dec 31, 2024
1 parent e071211 commit 30c5da7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions include/Peanut/impl/binary_expr/matrix_mult.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,23 @@ namespace Peanut::Impl {
requires(E1::Col == E2::Row)
struct MatrixMult : public MatrixExpr<MatrixMult<E1, E2>> {
using Type = typename E1::Type;
MatrixMult(const E1 &_x, const E2 &_y) : x_eval{_x}, y_eval{_y} {}
MatrixMult(const E1 &_x, const E2 &_y) {
const Matrix<Type, E1::Row, E1::Col> x_eval = _x;
const Matrix<Type, E2::Row, E2::Col> y_eval = _y;
evalVal = Matrix<Type, E1::Row, E2::Col>::zeros();

for (int i = 0; i < E1::Row; i++) {
for (int j = 0; j < E2::Col; j++) {
for (int k = 0; k < E1::Col; k++) {
evalVal.elem(i, j) += x_eval.elem(i, k) * y_eval.elem(k, j);
}
}
}
}

// Static polymorphism implementation of MatrixExpr
INLINE auto elem(Index r, Index c) const {
auto ret = x_eval.elem(r, 0) * y_eval.elem(0, c);
for (Index i = 1; i < E1::Col; i++) {
ret += x_eval.elem(r, i) * y_eval.elem(i, c);
}
return ret;
return evalVal.elem(r, c);
}

static constexpr Index Row = E1::Row;
Expand All @@ -62,9 +70,7 @@ namespace Peanut::Impl {
return Matrix<Type, Row, Col>(*this);
}

// Specify member type as Matrix for evaluation
const Matrix<Type, E1::Row, E1::Col> x_eval;
const Matrix<Type, E2::Row, E2::Col> y_eval;
Matrix<Type, E1::Row, E2::Col> evalVal;
};

}
Expand Down
1 change: 1 addition & 0 deletions include/Peanut/impl/binary_expr/matrix_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Peanut::Impl {
requires is_equal_size_mat_v<E1, E2>
struct MatrixSum : public MatrixExpr<MatrixSum<E1, E2>> {
using Type = typename E1::Type;

MatrixSum(const E1 &x, const E2 &y) : x{x}, y{y} {}

// Static polymorphism implementation of MatrixExpr
Expand Down

0 comments on commit 30c5da7

Please sign in to comment.