Replace broadcasted dimensions with size 1, and set the stride to the previous stride
| 2043 | |
| 2044 | // Replace broadcasted dimensions with size 1, and set the stride to the previous stride |
| 2045 | static shape unbroadcast(const shape& s) |
| 2046 | { |
| 2047 | std::vector<std::size_t> lens = s.lens(); |
| 2048 | std::vector<std::size_t> strides = s.strides(); |
| 2049 | auto stride_it = std::find_if( |
| 2050 | s.strides().begin(), s.strides().end(), [](auto stride) { return stride != 0; }); |
| 2051 | std::size_t prev_stride = stride_it == s.strides().end() ? 1 : *stride_it; |
| 2052 | for(std::size_t i = 0; i < lens.size(); ++i) |
| 2053 | { |
| 2054 | if(strides[i] == 0) |
| 2055 | { |
| 2056 | lens[i] = 1; |
| 2057 | strides[i] = prev_stride; |
| 2058 | } |
| 2059 | else |
| 2060 | { |
| 2061 | prev_stride = strides[i]; |
| 2062 | } |
| 2063 | } |
| 2064 | return {s.type(), lens, strides}; |
| 2065 | } |
| 2066 | |
| 2067 | static std::size_t adjust_strided_shape(shape& s, std::size_t n) |
| 2068 | { |