Optimized sub cube computation.