Fixed #5147 collapsingbug in einsum

At tests is also included that fails without the fix.
Minor style quirk, but if this fits in the previous line without exceeding the 79 character limit, then it belongs there.