If you don’t have any information on how your tensor will look like at compile time, I don’t know how you can highly optimize this operation. If it becomes a bottleneck, I guess it could be useful to factorize some parts of your code, so that you could potentially have some prior information on the inputs.