Skip to content

Instantly share code, notes, and snippets.

@maartenvd
Created March 6, 2019 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maartenvd/87ad06525c60dbe8dbdedcc244aba850 to your computer and use it in GitHub Desktop.
Save maartenvd/87ad06525c60dbe8dbdedcc244aba850 to your computer and use it in GitHub Desktop.
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