Implement leaf index calculations for arbitrary sparse array dimensions.