Created
March 6, 2019 14:42
-
-
Save maartenvd/87ad06525c60dbe8dbdedcc244aba850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filterdimstrides(dims,strides) | |
i = findfirst(isequal(1), dims) | |
if !(i isa Nothing) | |
newdims = TupleTools.deleteat(dims, i) | |
newstrides = broadcast(TupleTools.deleteat, strides, (i,)) | |
return filterdimstrides(newdims,newstrides) | |
else | |
return dims,strides | |
end | |
end | |
function _mapreducedim2!(@nospecialize(f), @nospecialize(op), @nospecialize(initop), dims, | |
strides, arrays) | |
# Level 2: recursively delete dimensions of size 1 | |
newdims,newstrides = filterdimstrides(dims,strides) | |
_mapreducedim_impl!(f, op, initop, newdims, newstrides, arrays) | |
end | |
#------------------ | |
function _mapreducedim2!(@nospecialize(f), @nospecialize(op), @nospecialize(initop), dims, | |
strides, arrays) | |
# Level 2: recursively delete dimensions of size 1 | |
i = findfirst(isequal(1), dims) | |
if !(i isa Nothing) | |
newdims = TupleTools.deleteat(dims, i) | |
newstrides = broadcast(TupleTools.deleteat, strides, (i,)) | |
_mapreducedim2!(f, op, initop, newdims, newstrides, arrays) | |
else | |
_mapreducedim_impl!(f, op, initop, dims, strides, arrays) | |
end | |
return | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment