MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::array::broadcast_expr< LHS, RHS, Op, N > Class Template Reference

Lazy expression for element-wise binary operations with broadcasting. More...

#include <broadcast.hpp>

Public Types

using value_type
using size_type = std::size_t

Public Member Functions

template<typename L, typename R>
 broadcast_expr (L &&lhs, R &&rhs, Op op)
const ::mtl::array::shape< N > & get_shape () const
size_type size () const
value_type operator[] (const std::array< size_type, N > &idx) const
 Evaluate at a multi-index.
ndarray< value_type, N > eval () const
 Materialize the expression into a new ndarray: one walk over the result, with the three arrays' offsets advanced together (#856: two offset computations and a checked write per element before).
 operator ndarray< value_type, N > () const
 Allow implicit conversion to ndarray (materialization).

Static Public Attributes

static constexpr size_type rank = N

Detailed Description

template<typename LHS, typename RHS, typename Op, std::size_t N>
class mtl::array::broadcast_expr< LHS, RHS, Op, N >

Lazy expression for element-wise binary operations with broadcasting.

LHS and RHS are the operand types as stored: const A& for an lvalue operand, A itself for an rvalue one, so make_arr() + b and auto e = a.transpose() + b keep their temporaries alive (#856: both were held by const reference and dangled). An ndarray view is cheap to copy; an owning temporary is moved in.

Member Typedef Documentation

◆ size_type

template<typename LHS, typename RHS, typename Op, std::size_t N>
using mtl::array::broadcast_expr< LHS, RHS, Op, N >::size_type = std::size_t

◆ value_type

template<typename LHS, typename RHS, typename Op, std::size_t N>
using mtl::array::broadcast_expr< LHS, RHS, Op, N >::value_type
Initial value:
std::remove_cv_t<decltype(std::declval<Op>()(
std::declval<typename lhs_array::value_type>(),
std::declval<typename rhs_array::value_type>()))>

Constructor & Destructor Documentation

◆ broadcast_expr()

template<typename LHS, typename RHS, typename Op, std::size_t N>
template<typename L, typename R>
mtl::array::broadcast_expr< LHS, RHS, Op, N >::broadcast_expr ( L && lhs,
R && rhs,
Op op )
inline

Member Function Documentation

◆ eval()

template<typename LHS, typename RHS, typename Op, std::size_t N>
ndarray< value_type, N > mtl::array::broadcast_expr< LHS, RHS, Op, N >::eval ( ) const
inline

Materialize the expression into a new ndarray: one walk over the result, with the three arrays' offsets advanced together (#856: two offset computations and a checked write per element before).

◆ get_shape()

template<typename LHS, typename RHS, typename Op, std::size_t N>
const ::mtl::array::shape< N > & mtl::array::broadcast_expr< LHS, RHS, Op, N >::get_shape ( ) const
inline

◆ operator ndarray< value_type, N >()

template<typename LHS, typename RHS, typename Op, std::size_t N>
mtl::array::broadcast_expr< LHS, RHS, Op, N >::operator ndarray< value_type, N > ( ) const
inline

Allow implicit conversion to ndarray (materialization).

◆ operator[]()

template<typename LHS, typename RHS, typename Op, std::size_t N>
value_type mtl::array::broadcast_expr< LHS, RHS, Op, N >::operator[] ( const std::array< size_type, N > & idx) const
inline

Evaluate at a multi-index.

Checked against the result's shape when bounds_checking is on, as ndarray's operator[] is (#856).

◆ size()

template<typename LHS, typename RHS, typename Op, std::size_t N>
size_type mtl::array::broadcast_expr< LHS, RHS, Op, N >::size ( ) const
inline

Member Data Documentation

◆ rank

template<typename LHS, typename RHS, typename Op, std::size_t N>
size_type mtl::array::broadcast_expr< LHS, RHS, Op, N >::rank = N
staticconstexpr

The documentation for this class was generated from the following file: