docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
reduce_node.h File Reference

Tensor reduction operation nodes. More...

Go to the source code of this file.

Classes

class  sdfg::math::tensor::ReduceNode
 Base class for tensor reduction operations. More...
class  sdfg::math::tensor::ReduceNodeSerializer< T >

Namespaces

namespace  sdfg
namespace  sdfg::math
namespace  sdfg::math::tensor

Detailed Description

Tensor reduction operation nodes.

This file defines the base class for tensor reduction operations. Reductions are operations that aggregate values along one or more tensor dimensions.

Tensor Library Nodes

ReduceNode expects scalars or flat pointers of scalars as inputs. The tensor operation is performed with linearized indices.

Reduction Operations

Reduction operations include:

  • Sum, mean, std: Statistical reductions
  • Min, max: Value reductions
  • Softmax: Exponential normalization

Reductions can operate on:

  • Specific axes (e.g., reduce along dimension 1)
  • Multiple axes (e.g., reduce along dimensions 0 and 2)
  • All axes (full reduction to scalar)

The keepdims parameter controls whether reduced dimensions are kept with size 1 or removed from the output shape.

Example

Creating a sum reduction:

// Reduce along last axis of shape [32, 64, 128]
std::vector<symbolic::Expression> shape = {
symbolic::integer(32), symbolic::integer(64), symbolic::integer(128)
};
std::vector<int64_t> axes = {-1}; // Last axis
bool keepdims = false;
auto& sum_node = builder.add_library_node<math::tensor::SumNode>(
block, debug_info, shape, axes, keepdims
);
// Output shape will be [32, 64] since last axis is reduced
See also
math::tensor::ElementWiseUnaryNode for elementwise operations
math::MathNode for expansion interface