fix #6672 (better reducedim type inference)
Merge pull request #6994 from stevengj/reducedim_type

better reducedim type inference