17 template <
typename T, expr_or_scalar<T> LeftExpr,
typename BinaryOp, expr_or_scalar<T> RightExpr>
20 iterable<binary_expr<T, LeftExpr, BinaryOp, RightExpr>> {
46 template <
typename V = default_vec>
50 binary_expr() =
delete;
57 binary_expr(LeftExpr l, RightExpr r) : lhs(std::forward<LeftExpr>(l)), rhs(std::forward<RightExpr>(r)) {
65 binary_expr(
const binary_expr& e) =
default;
71 binary_expr(binary_expr&& e) noexcept =
default;
74 binary_expr& operator=(
const binary_expr& e) =
delete;
75 binary_expr& operator=(binary_expr&& e) =
delete;
83 bool alias(
const E& other)
const noexcept {
84 return lhs.alias(other) || rhs.alias(other);
95 return BinaryOp::apply(lhs[i], rhs[i]);
105 return BinaryOp::apply(lhs.read_flat(i), rhs.read_flat(i));
114 template <
typename V = default_vec>
117 return BinaryOp::template load<V>(lhs.template load<V>(i), rhs.template load<V>(i));
126 template <
typename V = default_vec>
129 return BinaryOp::template load<V>(lhs.template loadu<V>(i), rhs.template loadu<V>(i));
137 template <size_c... S>
139 return BinaryOp::apply(lhs(args...), rhs(args...));
148 return sub(*
this, i);
157 return sub(*
this, i);
166 auto slice(
size_t first,
size_t last) noexcept {
176 auto slice(
size_t first,
size_t last)
const noexcept {
184 template <
typename Y>
193 template <
typename Y>
194 decltype(
auto) gpu_compute(Y& y)
const {
195 return BinaryOp::gpu_compute(lhs, rhs, y);
204 template <
typename L>
213 template <
typename L>
222 template <
typename L>
231 template <
typename L>
240 template <
typename L>
249 template <
typename L>
271 lhs.ensure_cpu_up_to_date();
272 rhs.ensure_cpu_up_to_date();
281 lhs.ensure_gpu_up_to_date();
282 rhs.ensure_gpu_up_to_date();
289 const LeftExpr& get_lhs()
const {
297 const RightExpr& get_rhs()
const {
308 if constexpr (BinaryOp::desc_func) {
309 return os << BinaryOp::desc() <<
"(" << expr.lhs <<
", " << expr.rhs <<
")";
311 return os <<
"(" << expr.lhs <<
' ' << BinaryOp::desc() <<
' ' << expr.rhs <<
")";
319 template <
typename T,
typename LE,
typename BinaryOp,
typename RE>
326 static constexpr
bool left_directed =
329 using sub_expr_t = std::conditional_t<left_directed, left_expr_t, right_expr_t>;
335 static constexpr
bool is_etl =
true;
339 static constexpr
bool is_fast = sub_traits::is_fast;
340 static constexpr
bool is_linear = left_traits::is_linear && right_traits::is_linear && BinaryOp::linear;
342 left_traits::is_thread_safe && right_traits::is_thread_safe && BinaryOp::thread_safe;
343 static constexpr
bool is_value =
false;
344 static constexpr
bool is_direct =
false;
345 static constexpr
bool is_generator = left_traits::is_generator && right_traits::is_generator;
346 static constexpr
bool is_temporary = left_traits::is_temporary || right_traits::is_temporary;
347 static constexpr
bool is_padded = is_linear && left_traits::is_padded && right_traits::is_padded;
348 static constexpr
bool is_aligned = is_linear && left_traits::is_aligned && right_traits::is_aligned;
349 static constexpr
order storage_order =
350 left_traits::is_generator ? right_traits::storage_order : left_traits::storage_order;
355 static constexpr
bool gpu_computable = all_gpu_computable<LE, RE> && BinaryOp::template gpu_computable<LE, RE> && all_homogeneous<LE, RE>;
357 template <vector_mode_t V>
358 static constexpr
bool vectorizable =
359 all_homogeneous<LE, RE>&& left_traits::template vectorizable<V>&& right_traits::template vectorizable<V>&& BinaryOp::template vectorizable<V>;
366 static constexpr
auto&
get(
const expr_t& v) {
367 if constexpr (left_directed) {
380 return sub_traits::size(
get(v));
397 static constexpr
size_t size() {
398 return sub_traits::size();
407 static constexpr
size_t dim() {
408 return sub_traits::template dim<D>();
416 return sub_traits::dimensions();
424 return BinaryOp::complexity() + left_traits::complexity() + right_traits::complexity();
CRTP class to inject iterators functions.
Definition: iterable.hpp:23
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:217
load(size_t i) const
Perform several operations at once.
Definition: binary_expr.hpp:116
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: binary_expr.hpp:423
std::decay_t< RightExpr > right_type
The RHS side type.
Definition: binary_expr.hpp:41
binary_expr(LeftExpr l, RightExpr r)
Construct a new binary expression.
Definition: binary_expr.hpp:57
static size_t size(const expr_t &v)
Returns the size of the given expression.
Definition: binary_expr.hpp:379
auto slice(E &&value, size_t first, size_t last) -> slice_view< detail::build_identity_type< E >>
Returns view representing a slice view of the given expression.
Definition: view_expression_builder.hpp:112
void std_assign_evaluate(Expr &&expr, Result &&result)
Evaluation of the expr into result.
Definition: evaluator.hpp:1176
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:244
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:235
constexpr bool is_magic_view
Traits indicating if the given ETL type is a magic view expression.
Definition: traits.hpp:311
std::decay_t< LE > left_expr_t
The type of the left expression.
Definition: binary_expr.hpp:322
T value_type
The Value type.
Definition: binary_expr.hpp:33
value_type operator[](size_t i) const
Returns the element at the given index.
Definition: binary_expr.hpp:94
void memory_type
The memory type.
Definition: binary_expr.hpp:34
void assign_to(L &&lhs) const
Assign to the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:208
void const_memory_type
The const memory type.
Definition: binary_expr.hpp:35
order
Storage order of a matrix.
Definition: order.hpp:15
CRTP class to inject functions testing values of the expressions.
Definition: value_testable.hpp:26
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
An optimizer for the given expression type.
Definition: expr_fwd.hpp:16
A binary expression.
Definition: binary_expr.hpp:18
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
auto dim(E &&value, size_t i) -> detail::identity_helper< E, dim_view< detail::build_identity_type< E >, D >>
Return a view representing the ith Dth dimension.
Definition: view_expression_builder.hpp:25
static constexpr size_t dim()
Returns the Dth dimension of an expression of this type.
Definition: binary_expr.hpp:407
typename V::template vec_type< T > vec_type
The vectorization type for V.
Definition: binary_expr.hpp:47
std::ostream & operator<<(std::ostream &os, const etl::complex< T > &c)
Outputs a textual representation of the complex number in the given stream.
Definition: complex.hpp:576
void ensure_cpu_up_to_date() const
Ensures that the GPU memory is allocated and that the GPU memory is up to date (to undefined value)...
Definition: dyn_matrix_view.hpp:271
std::decay_t< LeftExpr > left_type
The LHS side type.
Definition: binary_expr.hpp:40
static constexpr size_t size()
Returns the size of an expression of this fast type.
Definition: binary_expr.hpp:397
std::conditional_t< left_directed, left_expr_t, right_expr_t > sub_expr_t
The type of sub expression.
Definition: binary_expr.hpp:329
static size_t dim(const expr_t &v, size_t d)
Returns the dth dimension of the given expression.
Definition: binary_expr.hpp:389
Visitor to perform local evaluation when necessary.
Definition: eval_visitors.hpp:23
value_type read_flat(size_t i) const
Returns the value at the given index This function never alters the state of the container.
Definition: binary_expr.hpp:104
Configurable iterator for ETL expressions.
Definition: iterator.hpp:24
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
const_return_type operator()(size_t j) const
Access to the element at the given position.
Definition: dyn_matrix_view.hpp:89
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
void visit(detail::evaluator_visitor &visitor) const
Apply the given visitor to this expression and its descendants.
Definition: dyn_matrix_view.hpp:263
bool alias(const E &other) const noexcept
Test if this expression aliases with the given expression.
Definition: binary_expr.hpp:83
requires(D > 0) struct dyn_base
Matrix with run-time fixed dimensions.
Definition: dyn_base.hpp:113
T value_type
The value type.
Definition: binary_expr.hpp:324
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
void ensure_gpu_up_to_date() const
Copy back from the GPU to the expression memory if necessary.
Definition: dyn_matrix_view.hpp:280
Simple traits to test if an expression is optimizable.
Definition: expr_fwd.hpp:13
static constexpr size_t dimensions()
Returns the number of expressions for this type.
Definition: binary_expr.hpp:415
std::decay_t< RE > right_expr_t
The type of the right expression.
Definition: binary_expr.hpp:323
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:253
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
const auto & gpu_compute_hint([[maybe_unused]] Y &y) const
Return a GPU computed version of this expression.
Definition: sub_view.hpp:653
void std_div_evaluate(Expr &&expr, Result &&result)
Compound divide evaluation of the expr into result.
Definition: evaluator.hpp:1252
BinaryOp operator_type
The binary operator type.
Definition: binary_expr.hpp:38
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195
CRTP class to inject functions testing the dimensions.
Definition: dim_testable.hpp:45
loadu(size_t i) const
Perform several operations at once.
Definition: binary_expr.hpp:128
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:226