more efficient implementation of reduced_dims