| 43 | */ |
| 44 | template <class Message> |
| 45 | static auto tune_attribute(const std::vector<int64_t>& vec, |
| 46 | const std::vector<int64_t>& axes, |
| 47 | const value& val, |
| 48 | const shape& input_shape, |
| 49 | Message m) |
| 50 | { |
| 51 | std::vector<int64_t> result(vec); |
| 52 | if(result.empty()) |
| 53 | { |
| 54 | return result; |
| 55 | }; |
| 56 | int64_t n_rank = input_shape.ndim(); |
| 57 | std::vector<op::normalize_attribute> vec_attrs = val.to_vector<op::normalize_attribute>(); |
| 58 | if(contains(vec_attrs, op::normalize_attribute::use_output)) |
| 59 | { |
| 60 | n_rank = n_rank + vec.size(); |
| 61 | } |
| 62 | |
| 63 | std::vector<int64_t> max_vals(vec.size(), n_rank); |
| 64 | |
| 65 | if(contains(vec_attrs, op::normalize_attribute::use_len)) |
| 66 | { |
| 67 | if(input_shape.dynamic()) |
| 68 | { |
| 69 | // return the unchanged `vec` if the dynamic_dimensions at `axes` are not fixed |
| 70 | if(std::any_of(axes.begin(), axes.end(), [&](auto ax) { |
| 71 | return not input_shape.dyn_dims().at(ax).is_fixed(); |
| 72 | })) |
| 73 | { |
| 74 | return vec; |
| 75 | } |
| 76 | std::transform(axes.begin(), axes.end(), max_vals.begin(), [&](auto i) { |
| 77 | return input_shape.dyn_dims().at(i).max; |
| 78 | }); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | std::transform(axes.begin(), axes.end(), max_vals.begin(), [&](auto i) { |
| 83 | return input_shape.lens().at(i); |
| 84 | }); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if(contains(vec_attrs, op::normalize_attribute::clip_max)) |
| 89 | { |
| 90 | if(contains(vec_attrs, op::normalize_attribute::include_max)) |
| 91 | { |
| 92 | std::transform(result.begin(), |
| 93 | result.end(), |
| 94 | max_vals.begin(), |
| 95 | result.begin(), |
| 96 | [](auto v, auto mv) { return v > mv ? mv : v; }); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | std::transform(result.begin(), |
| 101 | result.end(), |
| 102 | max_vals.begin(), |
no test coverage detected