Fix linear indexing for middle-dimension slices; add more tests

This also boosts the speed of linear indexing by about 2-3 fold in my
tests (10^6 elements)
Merge github.com:JuliaLang/julia