Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
tannic::operation::Binary< Operation, Operand, Cooperand > Class Template Reference

Expression template for a binary tensor operation. More...

#include <operations.hpp>

Public Member Functions

constexpr Binary (Operation operation, Trait< Operand >::Reference operand, Trait< Cooperand >::Reference cooperand)
 Constructs a Binary expression.
 
constexpr type dtype () const
 Returns the promoted data type of the result.
 
constexpr Shape const & shape () const
 Returns the shape of the result.
 
constexpr Strides const & strides () const
 Returns the output strides for the result tensor.
 
std::ptrdiff_t offset () const
 Returns the offset of the expression.
 
Tensor forward () const
 

Public Attributes

Operation operation
 
Trait< Operand >::Reference operand
 
Trait< Cooperand >::Reference cooperand
 

Detailed Description

template<Operator Operation, Expression Operand, Expression Cooperand>
class tannic::operation::Binary< Operation, Operand, Cooperand >

Expression template for a binary tensor operation.

Represents a lazily evaluated binary operation between two expressions. The Binary class performs type promotion, shape broadcasting, and stride generation upon construction to prepare for efficient evaluation.

Template Parameters
OperationA stateless functor implementing void forward(Tensor const&, Tensor const&, Tensor&).
OperandLeft-hand-side expression satisfying the Expression concept.
CooperandRight-hand-side expression satisfying the Expression concept.

Constructor & Destructor Documentation

◆ Binary()

template<Operator Operation, Expression Operand, Expression Cooperand>
constexpr tannic::operation::Binary< Operation, Operand, Cooperand >::Binary ( Operation  operation,
Trait< Operand >::Reference  operand,
Trait< Cooperand >::Reference  cooperand 
)
inlineconstexpr

Constructs a Binary expression.

  • Computes dtype by promoting the operand and cooperand types.
  • Computes shape via NumPy-style broadcasting.
  • Computes strides based on the resulting shape.
Parameters
operationBinary operation functor (e.g., Addition).
operandLeft-hand-side expression.
cooperandRight-hand-side expression.

Member Function Documentation

◆ dtype()

template<Operator Operation, Expression Operand, Expression Cooperand>
constexpr type tannic::operation::Binary< Operation, Operand, Cooperand >::dtype ( ) const
inlineconstexpr

Returns the promoted data type of the result.

The data type is computed using a type promotion rule (based on the type enum), choosing the higher-precision or broader type between the two operands.

Returns
Promoted type of the two operands.

◆ forward()

template<Operator Operation, Expression Operand, Expression Cooperand>
Tensor tannic::operation::Binary< Operation, Operand, Cooperand >::forward

◆ offset()

template<Operator Operation, Expression Operand, Expression Cooperand>
std::ptrdiff_t tannic::operation::Binary< Operation, Operand, Cooperand >::offset ( ) const
inline

Returns the offset of the expression.

Binary expressions are assumed to have zero offset. Since the result is a new tensor.

Returns
Always returns 0.

◆ shape()

template<Operator Operation, Expression Operand, Expression Cooperand>
constexpr Shape const & tannic::operation::Binary< Operation, Operand, Cooperand >::shape ( ) const
inlineconstexpr

Returns the shape of the result.

The shape is computed via broadcasting rules, similar to NumPy or PyTorch. Dimensions are aligned from the right, and incompatible sizes throw.

Returns
Broadcasted shape between the two operands.

◆ strides()

template<Operator Operation, Expression Operand, Expression Cooperand>
constexpr Strides const & tannic::operation::Binary< Operation, Operand, Cooperand >::strides ( ) const
inlineconstexpr

Returns the output strides for the result tensor.

The strides are computed based on the broadcasted output shape and follow a standard row-major memory layout (like C arrays).

Returns
Computed strides for the broadcasted shape.

Member Data Documentation

◆ cooperand

template<Operator Operation, Expression Operand, Expression Cooperand>
Trait<Cooperand>::Reference tannic::operation::Binary< Operation, Operand, Cooperand >::cooperand

◆ operand

template<Operator Operation, Expression Operand, Expression Cooperand>
Trait<Operand>::Reference tannic::operation::Binary< Operation, Operand, Cooperand >::operand

◆ operation

template<Operator Operation, Expression Operand, Expression Cooperand>
Operation tannic::operation::Binary< Operation, Operand, Cooperand >::operation

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