| 807 | } |
| 808 | |
| 809 | bool shape_transform_descriptor::apply(const std::vector<operation>& ops) |
| 810 | { |
| 811 | std::vector<std::size_t> dims; |
| 812 | std::transform(dimensions.begin(), |
| 813 | dimensions.end(), |
| 814 | std::back_inserter(dims), |
| 815 | [](const dimension& d) { return d.len(); }); |
| 816 | for(const auto& op : ops) |
| 817 | { |
| 818 | auto v = op.to_value(); |
| 819 | if(contains({"reshape", "squeeze", "unsqueeze", "flatten"}, op.name())) |
| 820 | { |
| 821 | dims = compute_dims(op, dims); |
| 822 | if(not apply_reshape(dims)) |
| 823 | return false; |
| 824 | } |
| 825 | else if(op.name() == "transpose") |
| 826 | { |
| 827 | dims = compute_dims(op, dims); |
| 828 | if(not apply_transpose(v["permutation"].to_vector<std::int64_t>())) |
| 829 | return false; |
| 830 | } |
| 831 | else if(op.name() == "multibroadcast") |
| 832 | { |
| 833 | dims = compute_dims(op, dims); |
| 834 | // cppcheck-suppress knownConditionTrueFalse |
| 835 | if(not apply_broadcast(dims)) |
| 836 | return false; |
| 837 | } |
| 838 | else if(op.name() == "broadcast") |
| 839 | { |
| 840 | dims = compute_dims(op, dims); |
| 841 | // cppcheck-suppress knownConditionTrueFalse |
| 842 | if(not apply_broadcast(dims, v["axis"].to<std::size_t>())) |
| 843 | return false; |
| 844 | } |
| 845 | else if(op.name() != "contiguous") |
| 846 | { |
| 847 | return false; |
| 848 | } |
| 849 | } |
| 850 | return true; |
| 851 | } |
| 852 | bool shape_transform_descriptor::apply_reshape(const std::vector<std::size_t>& rdims) |
| 853 | { |
| 854 | std::vector<std::size_t> idims; |