refactor(math): improve expressions
Improve expressions by passing index, lhs and rhs.
This commit is contained in:
@@ -24,7 +24,7 @@ struct unary_expression : expression_tag {
|
|||||||
|
|
||||||
constexpr auto shape() const { return expr.shape(); }
|
constexpr auto shape() const { return expr.shape(); }
|
||||||
|
|
||||||
auto coeff(std::size_t index) const { return Op{}(expr.coeff(index)); }
|
auto coeff(std::size_t index) const { return Op{}(index, std::as_const(expr)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename L, typename R, typename Op>
|
template <typename L, typename R, typename Op>
|
||||||
@@ -39,16 +39,7 @@ struct binary_expression : expression_tag {
|
|||||||
|
|
||||||
constexpr auto shape() const { return Op::shape(lhs, rhs); }
|
constexpr auto shape() const { return Op::shape(lhs, rhs); }
|
||||||
|
|
||||||
auto coeff(std::size_t index) const { return Op{}(index, lhs.coeff(index), as_operand(rhs)); }
|
auto coeff(std::size_t index) const { return Op{}(index, std::as_const(lhs), std::as_const(rhs)); }
|
||||||
private:
|
|
||||||
template <typename T>
|
|
||||||
static decltype(auto) as_operand(T&& value) {
|
|
||||||
if constexpr (is_tensor_v<T>) {
|
|
||||||
return std::as_const(value).view();
|
|
||||||
} else {
|
|
||||||
return std::forward<T>(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ struct generic_binary_op {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename LT, typename R>
|
template <typename L, typename R>
|
||||||
constexpr auto operator()(std::size_t index, LT lhs, const R& rhs) const {
|
constexpr auto operator()(std::size_t index, const L& lhs, const R& rhs) const {
|
||||||
return Op{}(lhs, rhs.coeff(index));
|
return Op{}(lhs.coeff(index), rhs.coeff(index));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user