Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add INLINE define to force inline function #1

Merged
merged 3 commits into from
Feb 27, 2024
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
4 changes: 2 additions & 2 deletions include/Peanut/impl/binary_expr/matrix_div_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>(x.elem(r, c)) / static_cast<Float>(y);
}

static constexpr Index Row = E::Row;
static constexpr Index Col = E::Col;

inline auto eval() const {
INLINE auto eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/binary_expr/matrix_emult.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/binary_expr/matrix_mult.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/binary_expr/matrix_mult_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>(x.elem(r, c)) * static_cast<Type>(y);
}

static constexpr Index Row = E::Row;
static constexpr Index Col = E::Col;

inline auto eval() const {
INLINE auto eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/binary_expr/matrix_subtract.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/binary_expr/matrix_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col>(*this);
}

Expand Down
2 changes: 2 additions & 0 deletions include/Peanut/impl/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

// Dependencies headers

#define INLINE __attribute__((always_inline)) inline

namespace Peanut {
using Index = unsigned int;
using Float = float;
Expand Down
22 changes: 11 additions & 11 deletions include/Peanut/impl/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const E&>(*this).elem(r, c);
}
};
Expand Down Expand Up @@ -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];
}

Expand All @@ -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];
}

Expand Down Expand Up @@ -294,7 +294,7 @@ namespace Peanut {
* method even though it is not a method of `MatrixExpr`.
* @return Evaluated matrix
*/
inline Matrix<Type, Row, Col> eval() const{
INLINE Matrix<Type, Row, Col> eval() const{
return Matrix<Type, Row, Col>(*this);
}

Expand All @@ -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];
}
Expand All @@ -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];
}
Expand All @@ -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<Row*Col;i++){
ret += (vec.m_data.d1[i] * m_data.d1[i]);
Expand All @@ -341,7 +341,7 @@ namespace Peanut {
* (i.e., Row==1 or Col==1)
* @return Float l2 distance of the vector.
*/
inline Float length() const requires (Row==1) || (Col==1){
Float length() const requires (Row==1) || (Col==1){
T ret = t_0;
for(int i=0;i<Row*Col;i++){
ret += (m_data.d1[i] * m_data.d1[i]);
Expand All @@ -354,7 +354,7 @@ namespace Peanut {
* (i.e., Row==1 or Col==1)
* @return Normalized Float matrix(vector).
*/
inline Matrix<Float, Row, Col> normalize() const requires (Row==1) || (Col==1){
Matrix<Float, Row, Col> normalize() const requires (Row==1) || (Col==1){
Matrix<Float, Row, Col> ret;
const Float len = length();
for(int i=0;i<Row*Col;i++){
Expand All @@ -368,7 +368,7 @@ namespace Peanut {
* (i.e., Row==1 or Col==1)
* @return Max element in the vector.
*/
inline T max() const requires (Row==1) || (Col==1){
T max() const requires (Row==1) || (Col==1){
return *std::max_element(m_data.d1.begin(), m_data.d1.end());
}

Expand All @@ -377,7 +377,7 @@ namespace Peanut {
* (i.e., Row==1 or Col==1)
* @return Min element in the vector.
*/
inline T min() const requires (Row==1) || (Col==1){
T min() const requires (Row==1) || (Col==1){
return *std::min_element(m_data.d1.begin(), m_data.d1.end());
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/adjugate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return mat_eval;
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(x.elem(r, c));
}

static constexpr Index Row = E::Row;
static constexpr Index Col = E::Col;

inline Matrix<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/cofactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return mat_eval;
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/inverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/minor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return mat_eval;
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/negation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/submatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
4 changes: 2 additions & 2 deletions include/Peanut/impl/unary_expr/transpose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Row, Col> eval() const {
INLINE Matrix<Type, Row, Col> eval() const {
return Matrix<Type, Row, Col>(*this);
}

Expand Down
Loading