--- /dev/null
+#ifndef _NNC_CORE_BACKEND_INTERPRETER_REDUCE_IMPL_
+#define _NNC_CORE_BACKEND_INTERPRETER_REDUCE_IMPL_
+
+#include <functional>
+
+#include "nncc/core/ADT/tensor/Shape.h"
+#include "nnc/core/linalg/Tensor.h"
+
+#include "interpreter/ops/OperationImpl.h"
+#include "interpreter/ops/Fill.h"
+
+
+namespace nncc
+{
+namespace contrib
+{
+namespace backend
+{
+namespace interpreter
+{
+namespace impl
+{
+
+template <typename T> class Reduce : public OperationImpl<T>
+{
+public:
+ Reduce(const Shape &inputShape, const Shape &outputShape, const TensorVariant &input, uint32_t axis,
+ std::function<T(const T &, const T &)> reduceFunc)
+ : _inShape(inputShape), _outputShape(outputShape), _input(input), _axis(axis),
+ _reduceFunc(reduceFunc)
+ {
+ assert(outputShape.dim(axis) == 1);
+ }
+
+ std::vector<TensorVariant> operator()() override
+ {
+ return Fill<T>(_outputShape, [this](const Index &id) {
+ T element = T();
+ Index inputId = id;
+ uint32_t end = _inShape.dim(_axis);
+ for (uint32_t i = 0; i < end; ++i)
+ {
+ inputId.at(_axis) = i;
+ element = _reduceFunc(element, _input.at(inputId));
+ }
+ return element;
+ })();
+ }
+
+private:
+ const Shape &_inShape;
+ const Shape &_outputShape;
+ const Tensor<T> _input;
+ const uint32_t _axis;
+ const std::function<T(T, T)> _reduceFunc;
+};
+
+} // namespace impl
+} // namespace interpreter
+} // namespace backend
+} // namespace contrib
+} // namespace nncc
+
+#endif //_NNC_CORE_BACKEND_INTERPRETER_REDUCE_IMPL_