Skip to content

tenzr::ReduceNode

More...

#include <node.h>

Inherits from tenzr::Node, std::enable_shared_from_this< Node >

Public Functions

Name
ReduceNode(std::shared_ptr< Node > input, ReduceOp Reduction, std::vector< int64_t > dimensions, bool keepdims)
virtual std::string OpName() const override
const std::shared_ptr< Node > & Input() const
ReduceOp Reduction() const
The reduction applied.
const std::vector< int64_t > & Dimensions() const
The requested reduction dimensions.
const std::vector< int64_t > & CanonicalDimensions() const
The reduction dimensions normalized to non-negative form.
bool Keepdims() const
Whether reduced dimensions are retained with extent 1.
const Shape & NonKeepdimsShape() const
The result shape when keepdims is false.
Shape ExpandedShape() const
The input shape with reduced dimensions expanded to extent 1.

Additional inherited members

Public Functions inherited from tenzr::Node

Name
Node(NodeKind kind, Shape shape, DType dtype, ShardingSpec sharding =ShardingSpec::Replicated())
virtual ~Node() =default
NodeKind Kind() const
The node's operation kind.
const Shape & shape() const
The node's output shape.
DType Dtype() const
The node's output dtype.
const ShardingSpec & Sharding() const
The node's sharding spec.
void SetSharding(ShardingSpec spec)
Replace the sharding spec.
const StridedLayout & Layout() const
The node's strided layout.
void SetLayout(StridedLayout layout)
Replace the layout.
const std::vector< std::shared_ptr< Node > > & Inputs() const
The node's input operands.
uint64_t Id() const
The node's unique id.

Protected Functions inherited from tenzr::Node

Name
uint64_t NextId()

Protected Attributes inherited from tenzr::Node

Name
NodeKind kind_
Shape shape_
DType dtype_
ShardingSpec sharding_
StridedLayout layout_
std::vector< std::shared_ptr< Node > > inputs_
uint64_t id_

Detailed Description

class tenzr::ReduceNode;

Reduce an operand over selected dimensions using sum, product, max, or min.

Public Functions Documentation

function ReduceNode

ReduceNode(
    std::shared_ptr< Node > input,
    ReduceOp Reduction,
    std::vector< int64_t > dimensions,
    bool keepdims
)

Parameters:

  • input Input node.
  • Reduction Reduction operator.
  • dimensions Axes to reduce; all when empty.
  • keepdims Whether reduced axes are retained.

Create a reduction node, canonicalizing dimensions and inferring the output shape.

function OpName

virtual std::string OpName() const override

Return: The reduction name.

Reimplements: tenzr::Node::OpName

Human-readable name of the reduction, e.g. "ReduceSum".

function Input

inline const std::shared_ptr< Node > & Input() const

function Reduction

inline ReduceOp Reduction() const

The reduction applied.

function Dimensions

inline const std::vector< int64_t > & Dimensions() const

The requested reduction dimensions.

function CanonicalDimensions

inline const std::vector< int64_t > & CanonicalDimensions() const

The reduction dimensions normalized to non-negative form.

function Keepdims

inline bool Keepdims() const

Whether reduced dimensions are retained with extent 1.

function NonKeepdimsShape

inline const Shape & NonKeepdimsShape() const

The result shape when keepdims is false.

function ExpandedShape

Shape ExpandedShape() const

The input shape with reduced dimensions expanded to extent 1.

Return: The keepdims-style shape.

Shape with reduced axes set to size 1, used to broadcast an adjoint back.