-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels