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

Expression templates #1

Open
gf712 opened this issue Nov 12, 2019 · 0 comments
Open

Expression templates #1

gf712 opened this issue Nov 12, 2019 · 0 comments

Comments

@gf712
Copy link
Member

gf712 commented Nov 12, 2019

Like in Eigen, we should have an optimisation with expression templates. Right now the library creates temporary matrices/vectors for each operation. The paper says that we are allowed to return what we think is best from the four overloaded operators (+,- (negation and subtraction) and *) defined in arithmetic_operators.hpp. My idea is to return an expression template, eigen style, for example addition:

template<class OT, class ET1, class OT1, class ET2, class OT2>
struct matrix_addition_traits<OT, matrix<ET1, OT1>, matrix<ET2, OT2>>
{
    // not sure yet how these lines would have to change
    using engine_type = matrix_addition_engine_t<OT, ET1, ET2>;
    using op_traits   = OT;
    using result_type = matrix<engine_type, op_traits>;

    matrix_addition_traits(matrix<ET1, OT1> const& m1, matrix<ET2, OT2> const& m2): lhs(m1), rhs(m2) {}
    
    // do the actual calculation
    auto     operator ()(typename result_type::index_type i, typename result_type::index_type j)
    {
         return lhs(i, j) + rhs(i, j);
    }

    // hold reference to lhs and rhs matrices
    const matrix<ET1, OT1>& lhs;
    const matrix<ET2, OT2>& rhs; 
    
    // syntatic sugar that calls the constructor (rather than calculate the value explicitly with allocation)
    static auto  add(matrix<ET1, OT1> const& m1, matrix<ET2, OT2> const& m2);
};

would be good to discuss a bit how we could achieve this and remain compliant with P1385. It seems like they used Eigen quite a bit as a design inspiration, so this should be doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant