Hello,
This is probably quite obvious for folks who regularly work with MLIR, so please bear with me
How does MLIR define the “rank” of a tensor? How about vectors and matrices?
From https://mathworld.wolfram.com/TensorRank.html:
The rank of a tensor is independent of the number of dimensions of the underlying space
The TF docs further clarify this for vectors:
- Rank: Number of tensor axes. A scalar has rank 0, a vector has rank 1, a matrix is rank 2.
As far as MLIR is concerned, it’s very hard to find a definitive answer as there is no relevant documentation, but perhaps I missed something? This is my mental model based on the links above:
- Let
A
be a tensor, e.g.tensor<10 x 10 x 10 x i32>
. It’s a rank-3 tensor. - Let
v
be a vector, e.g.vector<3 x i32>
, it’s a rank-1 tensor in a 3-D space (or e.g. 3-D vector).
Is this correct?
Here’s the tricky part - what should be the nomenclature for the so-called multi-dimensional vectors from the vector dialect? Currently, vector<4x8x128xf32>
is referred to as a 3-D vector, which would suggest that vector<3 x i32>
is not a 3-D vector . What about the rank? I’m probably just confusing myself
I should also mention that this came up when reviewing ⚙ D127875 [mlir][vector] Add vector.scalable.insert/extract ops. CC @dcaballe @javiersetoain
Thanks for taking a look!
Andrzej
Some other references
(…) a rank-1 tensor (i.e., a vector in N-dimensional space can be represented by N numbers (…)
The rank of a tensor is the number of indices required to uniquely select each element of the tensor.