iVS3D v2.0.0
Loading...
Searching...
No Matches
ReduceOps.h
Go to the documentation of this file.
1#pragma once
2
12#include <limits>
13#include <cstddef>
14#include <utility>
15
16namespace NN {
17
37struct ReduceSum {
38 template<typename T>
39 T initial() const { return T(0); }
40
41 template<typename T>
42 void operator()(T& acc, const T& value) const {
43 acc += value;
44 }
45};
46
57struct ReduceMin {
58 template<typename T>
59 T initial() const { return std::numeric_limits<T>::max(); }
60
61 template<typename T>
62 void operator()(T& acc, const T& value) const {
63 if (value < acc) acc = value;
64 }
65};
66
77struct ReduceMax {
78 template<typename T>
79 T initial() const { return std::numeric_limits<T>::lowest(); }
80
81 template<typename T>
82 void operator()(T& acc, const T& value) const {
83 if (value > acc) acc = value;
84 }
85};
86
99 template<typename T>
100 std::pair<int64_t, T> initial() const {
101 return {0, std::numeric_limits<T>::max()};
102 }
103
104 template<typename T>
105 void operator()(std::pair<int64_t, T>& acc, const T& value, int64_t idx) const {
106 if (value < acc.second) {
107 acc = {idx, value};
108 }
109 }
110};
111
124 template<typename T>
125 std::pair<int64_t, T> initial() const {
126 return {0, std::numeric_limits<T>::lowest()};
127 }
128
129 template<typename T>
130 void operator()(std::pair<int64_t, T>& acc, const T& value, int64_t idx) const {
131 if (value > acc.second) {
132 acc = {idx, value};
133 }
134 }
135};
136}
NN Neural Network Library containing Tensor and NeuralNet classes for inference.
Definition NeuralError.h:13
Reduces a Tensor by finding the index of the maximum value along a specified axis.
Definition ReduceOps.h:123
Reduces a Tensor by finding the index of the minimum value along a specified axis.
Definition ReduceOps.h:98
Reduces a Tensor by computing the maximum value along a specified axis.
Definition ReduceOps.h:77
Reduces a Tensor by computing the minimum value along a specified axis.
Definition ReduceOps.h:57
Reduces a Tensor by summing its elements along a specified axis.
Definition ReduceOps.h:37