Cast 2D tensor into 1D tensor of vector?

Hi all,

I am wondering if there is an operation in the tensor (or maybe vector?) dialect that would allow me to cast something like tensor<Mx2xe> into tensor<Mxvector<2xe>> (the last dimension doesn’t necessarily have to be 2)?

I’ve tried tensor.shape_cast and some combinations of tensor.collapse/expand but to no avail…

Thanks in advance

You cannot cast in the sense of having a noop, or at least cheap, operation because there is no guarantee that the underlying tensor data is stored in a way that can be interpreted as a vector. You can write a loop that extracts vectors from a tensor and inserts them into another tensor using vector.transfer_read/write. This is more verbose, but is closer to what the code will actually have to do in the general case.