fixed #5147 collapsingbug in einsum

tests passed. this PR for the 1.9.x maintenance branch.