19 template <
typename Expr>
26 static bool is([[maybe_unused]]
const Expr& expr) {
35 static bool is_deep([[maybe_unused]]
const Expr& expr) {
45 template <
typename T,
typename Expr,
typename UnaryOp>
49 return std::is_same_v<UnaryOp, plus_unary_op<T>>;
63 template <
typename T,
typename BinaryOp>
97 template <
typename T,
typename BinaryOp,
typename RightExpr>
131 template <
typename T,
typename LeftExpr,
typename BinaryOp>
169 template <
typename T,
typename LeftExpr,
typename BinaryOp,
typename RightExpr>
187 template <
typename Expr>
197 template <
typename Expr>
205 template <
typename Expr>
212 template <
typename Builder>
213 static void transform([[maybe_unused]] Builder builder, [[maybe_unused]]
const Expr& expr) {
214 std::cout <<
"Arrived in parent, should not happen" << std::endl;
223 template <
typename T,
typename Expr,
typename UnaryOp>
230 template <
typename Builder>
233 parent_builder(expr.value);
243 template <
typename T,
typename BinaryOp>
250 template <
typename Builder>
269 template <
typename T,
typename BinaryOp,
typename RightExpr>
276 template <
typename Builder>
279 if (expr.lhs.value == 1.0) {
280 parent_builder(expr.rhs);
281 }
else if (expr.lhs.value == 0.0) {
282 parent_builder(expr.lhs);
285 if (expr.lhs.value == 0.0) {
286 parent_builder(expr.rhs);
289 if (expr.lhs.value == 0.0) {
290 parent_builder(expr.lhs);
301 template <
typename T,
typename LeftExpr,
typename BinaryOp>
308 template <
typename Builder>
311 if (expr.rhs.value == 1.0) {
312 parent_builder(expr.lhs);
313 }
else if (expr.rhs.value == 0.0) {
314 parent_builder(expr.rhs);
317 if (expr.rhs.value == 0.0) {
318 parent_builder(expr.lhs);
321 if (expr.rhs.value == 0.0) {
322 parent_builder(expr.lhs);
325 if (expr.rhs.value == 1.0) {
326 parent_builder(expr.lhs);
337 template <
typename Builder,
typename Expr>
338 void transform(Builder parent_builder,
const Expr& expr) {
345 template <
typename Expr>
352 template <
typename Builder>
353 static void apply([[maybe_unused]] Builder parent_builder, [[maybe_unused]]
const Expr& expr) {
354 std::cout <<
"Leaf node" << std::endl;
361 template <
typename T,
typename Expr,
typename UnaryOp>
368 template <
typename Builder>
373 auto value_builder = [&](
auto&& new_value) {
377 optimize(value_builder, expr.value);
379 parent_builder(expr);
387 template <
typename T,
typename LeftExpr,
typename BinaryOp,
typename RightExpr>
394 template <
typename Builder>
399 auto lhs_builder = [&](
auto&& new_lhs) {
405 auto rhs_builder = [&](
auto&& new_rhs) {
411 parent_builder(expr);
422 template <
typename Builder,
typename Expr>
423 void optimize(Builder parent_builder, Expr& expr) {
433 template <
typename Expr,
typename Result>
Unary operation computing the plus operation.
Definition: plus.hpp:17
bool is_optimizable_deep(const Expr &expr)
Function to test if expr or sub parts of expr are optimizable.
Definition: optimizer.hpp:198
static constexpr bool is(const etl::binary_expr< T, etl::scalar< T >, BinaryOp, etl::scalar< T >> &)
Indicates if the given expression is optimizable or not.
Definition: optimizer.hpp:66
void optimized_forward(Expr &expr, Result result)
Optimize an expression and pass the optimized expression to the given functor.
Definition: optimizer.hpp:434
static bool is(const etl::binary_expr< T, etl::scalar< T >, BinaryOp, RightExpr > &expr)
Indicates if the given expression is optimizable or not.
Definition: optimizer.hpp:100
Binary operator for scalar subtraction.
Definition: minus.hpp:16
static void apply(Builder parent_builder, const etl::binary_expr< T, LeftExpr, BinaryOp, RightExpr > &expr)
Optimize the expression using the given builder.
Definition: optimizer.hpp:395
static bool is_deep(const etl::binary_expr< T, LeftExpr, BinaryOp, RightExpr > &expr)
Indicates if the given expression or one of its sub expressions is optimizable or not...
Definition: optimizer.hpp:177
static bool is_deep(const etl::unary_expr< T, Expr, UnaryOp > &expr)
Indicates if the given expression or one of its sub expressions is optimizable or not...
Definition: optimizer.hpp:53
static bool is(const etl::binary_expr< T, LeftExpr, BinaryOp, RightExpr > &)
Indicates if the given expression is optimizable or not.
Definition: optimizer.hpp:172
Binary operator for scalar division.
Definition: div.hpp:349
static bool is_deep([[maybe_unused]] const Expr &expr)
Indicates if the given expression or one of its sub expressions is optimizable or not...
Definition: optimizer.hpp:35
An unary expression.
Definition: unary_expr.hpp:126
An optimizer for the given expression type.
Definition: expr_fwd.hpp:16
A binary expression.
Definition: binary_expr.hpp:18
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr bool is(const etl::unary_expr< T, Expr, UnaryOp > &)
Indicates if the given expression is optimizable or not.
Definition: optimizer.hpp:48
static void apply([[maybe_unused]] Builder parent_builder, [[maybe_unused]] const Expr &expr)
Optimize the expression using the given builder.
Definition: optimizer.hpp:353
std::conditional_t< is_etl_value< T >, const std::decay_t< T > &, std::decay_t< T > > build_type
Helper to build the type for a sub expression.
Definition: expression_helpers.hpp:24
static bool is([[maybe_unused]] const Expr &expr)
Indicates if the given expression is optimizable or not.
Definition: optimizer.hpp:26
Represents a scalar value.
Definition: concepts_base.hpp:19
bool is_optimizable(const Expr &expr)
Function to test if expr is optimizable.
Definition: optimizer.hpp:188
Binary operator for scalar multiplication.
Definition: div.hpp:13
Simple traits to test if an expression is optimizable.
Definition: expr_fwd.hpp:13
void transform(Builder parent_builder, const Expr &expr)
Function to transform the expression into its optimized form.
Definition: optimizer.hpp:338
static bool is_deep(const etl::binary_expr< T, etl::scalar< T >, BinaryOp, etl::scalar< T >> &expr)
Indicates if the given expression or one of its sub expressions is optimizable or not...
Definition: optimizer.hpp:87
static void apply(Builder parent_builder, const etl::unary_expr< T, Expr, UnaryOp > &expr)
Optimize the expression using the given builder.
Definition: optimizer.hpp:369
static bool is(const etl::binary_expr< T, LeftExpr, BinaryOp, etl::scalar< T >> &expr)
Indicates if the given expression is optimizable or not.
Definition: optimizer.hpp:134
static bool is_deep(const etl::binary_expr< T, LeftExpr, BinaryOp, etl::scalar< T >> &expr)
Indicates if the given expression or one of its sub expressions is optimizable or not...
Definition: optimizer.hpp:159
static bool is_deep(const etl::binary_expr< T, etl::scalar< T >, BinaryOp, RightExpr > &expr)
Indicates if the given expression or one of its sub expressions is optimizable or not...
Definition: optimizer.hpp:121
Binary operator for scalar addition.
Definition: plus.hpp:154
void optimize(Builder parent_builder, Expr &expr)
Optimize an expression and reconstruct the parent from the optimized expression.
Definition: optimizer.hpp:423