Note that the stack solution can be quite a bit more efficient once you have substantial computation and perhaps a batch of X to process at the same time.
(And if you have elementwise computation, this is probably not good anyways…)
Best regards
Thomas