63template<
class Operation, Expression Operand>
143template<Operator Operation, Expression Operand, Expression Cooperand>
239static constexpr inline type promote(type first, type second) {
240 return static_cast<int>(first) >
static_cast<int>(second) ? first : second;
264static constexpr Shape broadcast(Shape
const& first, Shape
const& second) {
265 auto first_rank = first.
rank();
266 auto second_rank = second.rank();
267 auto rank = std::max(first_rank, second_rank);
269 for (
auto dimension = 0; dimension < rank; ++dimension) {
270 auto first_dimension = (dimension < rank - first_rank) ? 1 : first[dimension - (rank - first_rank)];
271 auto second_dimension = (dimension < rank - second_rank) ? 1 : second[dimension - (rank - second_rank)];
273 if (!(first_dimension == second_dimension || first_dimension == 1 || second_dimension == 1)) {
274 throw Exception(
"Shapes are not broadcast-compatible.");
276 shape.expand(std::max(first_dimension, second_dimension));
336 constexpr static type
promote(type first, type second) {
337 return operation::promote(first, second);
341 return operation::broadcast(first, second);
372 constexpr static type
promote(type first, type second) {
373 return operation::promote(first, second);
377 return operation::broadcast(first, second);
408 constexpr static type
promote(type first, type second) {
409 return operation::promote(first, second);
413 return operation::broadcast(first, second);
446 constexpr static type
promote(type first, type second) {
447 return operation::promote(first, second);
451 return operation::broadcast(first, second);
466template<Expression Operand>
487template<Expression Augend, Expression Addend>
488constexpr auto operator+(Augend&& augend, Addend&& addend) {
508template<Expression Subtrahend, Expression Minuend>
509constexpr auto operator-(Subtrahend&& subtrahend, Minuend&& minuend) {
529template<Expression Multiplicand, Expression Multiplier>
530constexpr auto operator*(Multiplicand&& multiplicand, Multiplier&& multiplier) {
553template<Expression Base, Expression Exponent>
554constexpr auto operator^(Base&& base, Exponent&& exponent) {
560using operation::operator-;
561using operation::operator+;
562using operation::operator*;
563using operation::operator^;
Represents the shape (dimensions) of an tensor-like expression.
Definition: shape.hpp:79
constexpr rank_type rank() const noexcept
Returns the number of dimensions (rank).
Definition: shape.hpp:207
Represents the memory strides associated with a tensor shape.
Definition: strides.hpp:87
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:99
Expression template for a binary tensor operation.
Definition: operations.hpp:144
Trait< Operand >::Reference operand
Definition: operations.hpp:147
constexpr Strides const & strides() const
Returns the output strides for the result tensor.
Definition: operations.hpp:203
constexpr Shape const & shape() const
Returns the shape of the result.
Definition: operations.hpp:191
Operation operation
Definition: operations.hpp:146
Trait< Cooperand >::Reference cooperand
Definition: operations.hpp:148
constexpr Binary(Operation operation, Trait< Operand >::Reference operand, Trait< Cooperand >::Reference cooperand)
Constructs a Binary expression.
Definition: operations.hpp:161
std::ptrdiff_t offset() const
Returns the offset of the expression.
Definition: operations.hpp:215
Tensor forward() const
Definition: tensor.hpp:1158
constexpr type dtype() const
Returns the promoted data type of the result.
Definition: operations.hpp:179
Expression template for a unary tensor aritmetic operation.
Definition: operations.hpp:64
Trait< Operand >::Reference operand
Definition: operations.hpp:67
constexpr type dtype() const
Returns the data type of the result.
Definition: operations.hpp:87
constexpr Strides const & strides() const
Returns the strides of the result.
Definition: operations.hpp:111
Tensor forward() const
Evaluates the unary expression and returns a Tensor.
Definition: tensor.hpp:1151
std::ptrdiff_t offset() const
Returns the offset of the expression.
Definition: operations.hpp:121
Operation operation
Definition: operations.hpp:66
constexpr Unary(Operation operation, Trait< Operand >::Reference operand)
Constructs a Unary expression.
Definition: operations.hpp:74
constexpr Shape const & shape() const
Returns the shape of the result.
Definition: operations.hpp:98
Definition: operations.hpp:52
constexpr auto operator^(Base &&base, Exponent &&exponent)
Element-wise exponentiation of two tensor expressions.
Definition: operations.hpp:554
constexpr auto operator*(Multiplicand &&multiplicand, Multiplier &&multiplier)
Element-wise multiplication of two tensor expressions.
Definition: operations.hpp:530
constexpr auto operator+(Augend &&augend, Addend &&addend)
Element-wise addition of two tensor expressions.
Definition: operations.hpp:488
constexpr auto operator-(Operand &&operand)
Element-wise negation of a tensor expression.
Definition: operations.hpp:467
Definition: buffer.hpp:41
std::decay_t< T > Reference
Definition: traits.hpp:28
Binary element-wise addition of two tensor expressions.
Definition: operations.hpp:333
static constexpr Shape broadcast(Shape const &first, Shape const &second)
Definition: operations.hpp:340
static constexpr type promote(type first, type second)
Definition: operations.hpp:336
void forward(Tensor const &, Tensor const &, Tensor &) const
Binary element-wise exponentiation of two tensor expressions.
Definition: operations.hpp:443
void forward(Tensor const &, Tensor const &, Tensor &) const
static constexpr Shape broadcast(Shape const &first, Shape const &second)
Definition: operations.hpp:450
static constexpr type promote(type first, type second)
Definition: operations.hpp:446
Binary element-wise multiplication of two tensor expressions.
Definition: operations.hpp:369
static constexpr type promote(type first, type second)
Definition: operations.hpp:372
static constexpr Shape broadcast(Shape const &first, Shape const &second)
Definition: operations.hpp:376
void forward(Tensor const &, Tensor const &, Tensor &) const
Unary element-wise negation of a tensor expression.
Definition: operations.hpp:305
void forward(Tensor const &, Tensor &) const
Binary element-wise subtraction of two tensor expressions.
Definition: operations.hpp:405
static constexpr type promote(type first, type second)
Definition: operations.hpp:408
static constexpr Shape broadcast(Shape const &first, Shape const &second)
Definition: operations.hpp:412
void forward(Tensor const &, Tensor const &, Tensor &) const