diff --git a/include/Peanut/impl/binary_expr/matrix_div_scalar.h b/include/Peanut/impl/binary_expr/matrix_div_scalar.h index 87ec1e4..c802339 100644 --- a/include/Peanut/impl/binary_expr/matrix_div_scalar.h +++ b/include/Peanut/impl/binary_expr/matrix_div_scalar.h @@ -51,14 +51,14 @@ namespace Peanut::Impl { } // Static polymorphism implementation of MatrixExpr - inline Float elem(Index r, Index c) const { + INLINE Float elem(Index r, Index c) const { return static_cast(x.elem(r, c)) / static_cast(y); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline auto eval() const { + INLINE auto eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/binary_expr/matrix_emult.h b/include/Peanut/impl/binary_expr/matrix_emult.h index 7bf90ae..853c0aa 100644 --- a/include/Peanut/impl/binary_expr/matrix_emult.h +++ b/include/Peanut/impl/binary_expr/matrix_emult.h @@ -46,14 +46,14 @@ namespace Peanut::Impl { MatrixEMult(const E1 &x, const E2 &y) : x{x}, y{y} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return x.elem(r, c) * y.elem(r, c); } static constexpr Index Row = E1::Row; static constexpr Index Col = E1::Col; - inline auto eval() const { + INLINE auto eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/binary_expr/matrix_mult.h b/include/Peanut/impl/binary_expr/matrix_mult.h index 5e0a0f9..dd44e91 100644 --- a/include/Peanut/impl/binary_expr/matrix_mult.h +++ b/include/Peanut/impl/binary_expr/matrix_mult.h @@ -47,7 +47,7 @@ namespace Peanut::Impl { MatrixMult(const E1 &_x, const E2 &_y) : x_eval{_x}, y_eval{_y} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + 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); @@ -58,7 +58,7 @@ namespace Peanut::Impl { static constexpr Index Row = E1::Row; static constexpr Index Col = E2::Col; - inline auto eval() const { + INLINE auto eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/binary_expr/matrix_mult_scalar.h b/include/Peanut/impl/binary_expr/matrix_mult_scalar.h index 665817f..86e1dab 100644 --- a/include/Peanut/impl/binary_expr/matrix_mult_scalar.h +++ b/include/Peanut/impl/binary_expr/matrix_mult_scalar.h @@ -47,14 +47,14 @@ namespace Peanut::Impl { MatrixMultScalar(const E &x, T y) : x{x}, y{y} {} // Static polymorphism implementation of MatrixExpr - inline Type elem(Index r, Index c) const { + INLINE Type elem(Index r, Index c) const { return static_cast(x.elem(r, c)) * static_cast(y); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline auto eval() const { + INLINE auto eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/binary_expr/matrix_subtract.h b/include/Peanut/impl/binary_expr/matrix_subtract.h index 81946f3..d23d83d 100644 --- a/include/Peanut/impl/binary_expr/matrix_subtract.h +++ b/include/Peanut/impl/binary_expr/matrix_subtract.h @@ -45,14 +45,14 @@ namespace Peanut::Impl { MatrixSubtract(const E1 &x, const E2 &y) : x{x}, y{y} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return x.elem(r, c) - y.elem(r, c); } static constexpr Index Row = E1::Row; static constexpr Index Col = E1::Col; - inline auto eval() const { + INLINE auto eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/binary_expr/matrix_sum.h b/include/Peanut/impl/binary_expr/matrix_sum.h index a8a12f2..d1b4625 100644 --- a/include/Peanut/impl/binary_expr/matrix_sum.h +++ b/include/Peanut/impl/binary_expr/matrix_sum.h @@ -45,14 +45,14 @@ namespace Peanut::Impl { MatrixSum(const E1 &x, const E2 &y) : x{x}, y{y} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return x.elem(r, c) + y.elem(r, c); } static constexpr Index Row = E1::Row; static constexpr Index Col = E1::Col; - inline auto eval() const { + INLINE auto eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/common.h b/include/Peanut/impl/common.h index d8f4615..4542fa2 100644 --- a/include/Peanut/impl/common.h +++ b/include/Peanut/impl/common.h @@ -34,6 +34,8 @@ // Dependencies headers +#define INLINE __attribute__((always_inline)) inline + namespace Peanut { using Index = unsigned int; using Float = float; diff --git a/include/Peanut/impl/matrix.h b/include/Peanut/impl/matrix.h index 44b88a7..571d210 100644 --- a/include/Peanut/impl/matrix.h +++ b/include/Peanut/impl/matrix.h @@ -66,7 +66,7 @@ namespace Peanut { * @param c C index. * @return Rvalue of an element in \p r 'th Row and \p c 'th column. */ - inline auto elem(Index r, Index c) const{ + INLINE auto elem(Index r, Index c) const{ return static_cast(*this).elem(r, c); } }; @@ -228,7 +228,7 @@ namespace Peanut { * @param c Column index. * @return Rvalue of an element in \p r 'th Row and \p c 'th column. */ - inline T elem(Index r, Index c) const{ + INLINE T elem(Index r, Index c) const{ return m_data.d2[r][c]; } @@ -240,7 +240,7 @@ namespace Peanut { * @param c Column index. * @return Reference of an element in \p r 'th Row and \p c 'th column. */ - inline T& elem(Index r, Index c) { + INLINE T& elem(Index r, Index c) { return m_data.d2[r][c]; } @@ -294,7 +294,7 @@ namespace Peanut { * method even though it is not a method of `MatrixExpr`. * @return Evaluated matrix */ - inline Matrix eval() const{ + INLINE Matrix eval() const{ return Matrix(*this); } @@ -306,7 +306,7 @@ namespace Peanut { * @param i Index * @return \p T type i'th element data. */ - inline T operator[](Index i) const + INLINE T operator[](Index i) const requires (Row==1) || (Col==1){ return m_data.d1[i]; } @@ -317,7 +317,7 @@ namespace Peanut { * @param i Index * @return Reference of i'th element. */ - inline T& operator[](Index i) + INLINE T& operator[](Index i) requires (Row==1) || (Col==1){ return m_data.d1[i]; } @@ -328,7 +328,7 @@ namespace Peanut { * @param vec Equal-type matrix(vector). * @return T type dot product result. */ - inline T dot(const Matrix &vec) const requires (Row==1) || (Col==1){ + T dot(const Matrix &vec) const requires (Row==1) || (Col==1){ T ret = t_0; for(int i=0;i normalize() const requires (Row==1) || (Col==1){ + Matrix normalize() const requires (Row==1) || (Col==1){ Matrix ret; const Float len = length(); for(int i=0;i eval() const { + INLINE Matrix eval() const { return mat_eval; } diff --git a/include/Peanut/impl/unary_expr/block.h b/include/Peanut/impl/unary_expr/block.h index e876cff..756bb7b 100644 --- a/include/Peanut/impl/unary_expr/block.h +++ b/include/Peanut/impl/unary_expr/block.h @@ -48,14 +48,14 @@ namespace Peanut::Impl { MatrixBlock(const E &x) : x{x} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return x.elem(row_start + r, col_start + c); } static constexpr Index Row = row_size; static constexpr Index Col = col_size; - inline Matrix eval() const { + INLINE Matrix eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/unary_expr/cast.h b/include/Peanut/impl/unary_expr/cast.h index cab41cc..3177d2d 100644 --- a/include/Peanut/impl/unary_expr/cast.h +++ b/include/Peanut/impl/unary_expr/cast.h @@ -44,14 +44,14 @@ namespace Peanut::Impl { MatrixCastType(const E &x) : x{x} {} // Static polymorphism implementation of MatrixExpr - inline T elem(Index r, Index c) const { + INLINE T elem(Index r, Index c) const { return static_cast(x.elem(r, c)); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline Matrix eval() const { + INLINE Matrix eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/unary_expr/cofactor.h b/include/Peanut/impl/unary_expr/cofactor.h index 09efa0c..77f93e4 100644 --- a/include/Peanut/impl/unary_expr/cofactor.h +++ b/include/Peanut/impl/unary_expr/cofactor.h @@ -59,14 +59,14 @@ namespace Peanut::Impl { } // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return mat_eval.elem(r, c); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline Matrix eval() const { + INLINE Matrix eval() const { return mat_eval; } diff --git a/include/Peanut/impl/unary_expr/inverse.h b/include/Peanut/impl/unary_expr/inverse.h index 3557dc5..ddf6ccb 100644 --- a/include/Peanut/impl/unary_expr/inverse.h +++ b/include/Peanut/impl/unary_expr/inverse.h @@ -52,14 +52,14 @@ namespace Peanut::Impl { } // Static polymorphism implementation of MatrixExpr - inline Float elem(Index r, Index c) const { + INLINE Float elem(Index r, Index c) const { return invdet * cofactor_eval.elem(c, r); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline Matrix eval() const { + INLINE Matrix eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/unary_expr/minor.h b/include/Peanut/impl/unary_expr/minor.h index 42afdb0..233ff5a 100644 --- a/include/Peanut/impl/unary_expr/minor.h +++ b/include/Peanut/impl/unary_expr/minor.h @@ -51,14 +51,14 @@ namespace Peanut::Impl { } // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return mat_eval.elem(r, c); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline Matrix eval() const { + INLINE Matrix eval() const { return mat_eval; } diff --git a/include/Peanut/impl/unary_expr/negation.h b/include/Peanut/impl/unary_expr/negation.h index 18acd74..b7e721f 100644 --- a/include/Peanut/impl/unary_expr/negation.h +++ b/include/Peanut/impl/unary_expr/negation.h @@ -44,14 +44,14 @@ namespace Peanut::Impl { MatrixNegation(const E &x) : x{x} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return -x.elem(r, c); } static constexpr Index Row = E::Row; static constexpr Index Col = E::Col; - inline Matrix eval() const { + INLINE Matrix eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/unary_expr/submatrix.h b/include/Peanut/impl/unary_expr/submatrix.h index 8cb25a6..031a3c3 100644 --- a/include/Peanut/impl/unary_expr/submatrix.h +++ b/include/Peanut/impl/unary_expr/submatrix.h @@ -47,14 +47,14 @@ namespace Peanut::Impl { MatrixSub(const E &x) : x{x} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return x.elem(r < row_ex ? r : r + 1, c < col_ex ? c : c + 1); } static constexpr Index Row = E::Row - 1; static constexpr Index Col = E::Col - 1; - inline Matrix eval() const { + INLINE Matrix eval() const { return Matrix(*this); } diff --git a/include/Peanut/impl/unary_expr/transpose.h b/include/Peanut/impl/unary_expr/transpose.h index a9ffc23..f993f8b 100644 --- a/include/Peanut/impl/unary_expr/transpose.h +++ b/include/Peanut/impl/unary_expr/transpose.h @@ -44,14 +44,14 @@ namespace Peanut::Impl { MatrixTranspose(const E &x) : x{x} {} // Static polymorphism implementation of MatrixExpr - inline auto elem(Index r, Index c) const { + INLINE auto elem(Index r, Index c) const { return x.elem(c, r); } static constexpr Index Row = E::Col; static constexpr Index Col = E::Row; - inline Matrix eval() const { + INLINE Matrix eval() const { return Matrix(*this); }