reduce

Contents

reduce#

Reduces the input using a generic reduction operator and optionally store the indices of the reduction

template<typename OutType, typename TensorIndexType, typename InType, typename ReduceOp, std::enable_if_t<is_matx_reduction_v<ReduceOp>, bool> = true>
void __MATX_INLINE__ matx::reduce(OutType dest, TensorIndexType idest, const InType &in, ReduceOp op, cudaStream_t stream = 0, bool init = true)#

Perform a reduction and preserves indices

Performs a reduction from tensor “in” into values tensor “dest” and index tensor idest using reduction operation ReduceOp. The output tensor rank dictates which elements the reduction is performed over. In general, the reductions are performed over the innermost dimensions, where the number of dimensions is the difference between the input and output tensor ranks. For example, for a 0D (scalar) output tensor, the reduction is performed over the entire tensor. For anything higher, the reduction is performed across the number of ranks below the input tensor that the output tensor is. For example, if the input tensor is a 4D tensor and the output is a 1D tensor, the reduction is performed across the innermost dimension of the input. If the output is a 2D tensor, the reduction is performed across the two innermost dimensions of the input, and so on.

Template Parameters:
  • OutType – Output data type

  • TensorIndexType – Output index type

  • InType – Input data type

  • ReduceOp – Reduction operator to apply

Parameters:
  • dest – Destination view of values reduced

  • idest – Destination view of indices

  • in – Input data to reduce

  • op – Reduction operator

  • stream – CUDA stream

  • init – if true dest will be initialized with ReduceOp::Init() otherwise the values in the destination will be included in the reduction.

Examples#

// Reduce "in" into "dest" using a product operation as the reduction type
reduce(dest, in, detail::reduceOpProd<typename OutType::value_type>(), stream, true);