class
SushiBLAS::ReductionOps
Records reductions of a tensor into a scalar result tensor or along an axis.
- Declared in
include/SushiBLAS/engine/math/reductions.hpp
Note
A whole-tensor reduction needs a contiguous operand with storage. The axis reductions honour strides. Var, std, logsumexp, argmax and argmin reject an empty tensor.
Public member functions
explicit ReductionOps(TaskRecorder &recorder) noexceptBuilds a view that records through recorder, which must outlive the view.
explicit ReductionOps(Engine &engine) noexceptBuilds a view that records on engine's own graph.
ReductionOps(const ReductionOps &)=defaultReductionOps & operator=(const ReductionOps &)=deleteReductionOps(ReductionOps &&)=defaultReductionOps & operator=(ReductionOps &&)=delete~ReductionOps()=defaultTaskHandle sum(const Tensor &t, Tensor &result)Sum of all elements.
Computes result = sum(t_i).
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle mean(const Tensor &t, Tensor &result)Mean of all elements.
Computes result = sum(t_i) / num_elements.
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle max(const Tensor &t, Tensor &result)Maximum value in the tensor.
Finds result = max(t_i). Any NaN element makes the result NaN; an empty tensor gives std::numeric_limits<T>::lowest().
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle min(const Tensor &t, Tensor &result)Minimum value in the tensor.
Finds result = min(t_i). Any NaN element makes the result NaN; an empty tensor gives std::numeric_limits<T>::max().
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle argmax(const Tensor &t, Tensor &result)Index of the maximum value.
Parameters
tInput tensor.
resultScalar INT64 tensor; receives the lowest index of the maximum.
Exceptions
std::invalid_argumentif t is empty.
Returns
The handle of the recorded task.
TaskHandle argmin(const Tensor &t, Tensor &result)Index of the minimum value.
Parameters
tInput tensor.
resultScalar INT64 tensor; receives the lowest index of the minimum.
Exceptions
std::invalid_argumentif t is empty.
Returns
The handle of the recorded task.
TaskHandle var(const Tensor &t, Tensor &result)Variance of all elements.
Parameters
tInput tensor.
resultScalar output tensor.
Exceptions
std::invalid_argumentif t is empty.
Returns
The handle of the recorded task.
TaskHandle std(const Tensor &t, Tensor &result)Standard Deviation of all elements.
Parameters
tInput tensor.
resultScalar output tensor.
Exceptions
std::invalid_argumentif t is empty.
Returns
The handle of the recorded task.
TaskHandle prod(const Tensor &t, Tensor &result)Product of all elements.
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle logsumexp(const Tensor &t, Tensor &result)Log-Sum-Exp reduction.
Computes result = log(sum(exp(t_i - max(t)))). Used for numerical stability in softmax calculations.
Parameters
tInput tensor.
resultScalar output tensor.
Exceptions
std::invalid_argumentif t is empty.
Returns
The handle of the recorded task.
TaskHandle max_along(const Tensor &t, int axis, Tensor &result)Computes the maximum along one axis of a rank-2 tensor.
Parameters
axis0 for a per-column maximum, 1 for a per-row maximum.
resultRank-1 tensor of the surviving length, sharing t's dtype.
Exceptions
std::runtime_erroron a rank, axis, length or dtype mismatch.
See also
include/SushiBLAS/engine/math/README.md
TaskHandle sum_along(const Tensor &t, int axis, Tensor &result)Computes the Neumaier-compensated sum along one axis of a rank-2 tensor.
Parameters
axis0 for column sums, 1 for row sums.
resultRank-1 tensor of the surviving length, sharing t's dtype.
Exceptions
std::runtime_erroron a rank, axis, length or dtype mismatch.
See also
include/SushiBLAS/engine/math/README.md
TaskHandle mean_spatial(const Tensor &t, Tensor &result)Computes the mean over the two spatial axes of an NHWC tensor: [N, H, W, C] -> [N, C].
Parameters
tMust be rank 4, NHWC, with rows contiguous with one another.
resultRank-2
[N, C]tensor sharing t's dtype.
Exceptions
std::runtime_erroron a rank, shape, stride or dtype mismatch.
See also
include/SushiBLAS/engine/math/README.md
TaskHandle asum(const Tensor &t, Tensor &result)L1 Norm (Sum of absolute values).
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle nrm2(const Tensor &t, Tensor &result)L2 Norm (Euclidean norm).
Parameters
tInput tensor.
resultScalar output tensor.
Returns
The handle of the recorded task.
TaskHandle count_nonfinite(const Tensor &t, Tensor &result)Counts the elements of t that are infinite or NaN into an INT64 scalar.
Parameters
tMust be HALF, FLOAT32 or FLOAT64.
resultMust hold exactly one element of dtype INT64.
Exceptions
std::runtime_errorif result is not an INT64 scalar or t's dtype is not real.
See also
include/SushiBLAS/engine/math/README.md

