MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / unbroadcast

Function unbroadcast

src/shape_transform_descriptor.cpp:2045–2065  ·  view source on GitHub ↗

Replace broadcasted dimensions with size 1, and set the stride to the previous stride

Source from the content-addressed store, hash-verified

2043
2044// Replace broadcasted dimensions with size 1, and set the stride to the previous stride
2045static 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
2067static std::size_t adjust_strided_shape(shape& s, std::size_t n)
2068{

Callers 1

Calls 6

lensMethod · 0.80
find_ifFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected