| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <limits> | ||
| 6 | #include <string> | ||
| 7 | #include <tuple> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "task/include/task.hpp" | ||
| 11 | |||
| 12 | namespace kondakov_v_reduce { | ||
| 13 | |||
| 14 | enum class ReduceOp : std::uint8_t { kSum, kProd, kMin, kMax }; | ||
| 15 | |||
| 16 |
1/3✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
40 | struct ReduceInput { |
| 17 | std::vector<int> values; | ||
| 18 | ReduceOp op{ReduceOp::kSum}; | ||
| 19 | }; | ||
| 20 | |||
| 21 | using InType = ReduceInput; | ||
| 22 | using OutType = int64_t; | ||
| 23 | using TestType = std::tuple<std::vector<int>, std::string>; | ||
| 24 | |||
| 25 | using BaseTask = ppc::task::Task<InType, OutType>; | ||
| 26 | |||
| 27 | inline OutType ApplyReduceOp(OutType a, OutType b, ReduceOp op) { | ||
| 28 |
8/10✓ Branch 0 taken 53 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 35 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
180 | switch (op) { |
| 29 | 54 | case ReduceOp::kSum: | |
| 30 | 54 | return a + b; | |
| 31 | 36 | case ReduceOp::kProd: | |
| 32 | 36 | return a * b; | |
| 33 | case ReduceOp::kMin: | ||
| 34 | return std::min(a, b); | ||
| 35 | case ReduceOp::kMax: | ||
| 36 | return std::max(a, b); | ||
| 37 | default: | ||
| 38 | return a; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | inline OutType GetNeutralElement(ReduceOp op) { | ||
| 43 | switch (op) { | ||
| 44 | case ReduceOp::kSum: | ||
| 45 | return 0; | ||
| 46 | case ReduceOp::kProd: | ||
| 47 | return 1; | ||
| 48 | case ReduceOp::kMin: | ||
| 49 | return std::numeric_limits<int>::max(); | ||
| 50 | case ReduceOp::kMax: | ||
| 51 | return std::numeric_limits<int>::min(); | ||
| 52 | default: | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | } // namespace kondakov_v_reduce | ||
| 58 |