[Mlir-commits] [mlir] [mlir][sparse] introduce sparse_tensor.reinterpret_map operation. (PR #70378)
Aart Bik
llvmlistbot at llvm.org
Thu Oct 26 14:24:15 PDT 2023
================
@@ -415,6 +415,56 @@ SparseTensorEncodingAttr::getStaticLvlSliceStride(Level lvl) const {
return getStaticDimSliceStride(toOrigDim(*this, lvl));
}
+SmallVector<int64_t>
+SparseTensorEncodingAttr::tranlateShape(ArrayRef<int64_t> srcShape,
+ CrdTransDirectionKind dir) const {
+ if (isIdentity()) {
+ return SmallVector<int64_t>(srcShape);
+ }
+
+ SmallVector<int64_t> ret;
+ unsigned rank =
+ dir == CrdTransDirectionKind::dim2lvl ? getLvlRank() : getDimRank();
+ ret.reserve(rank);
+
+ if (isPermutation()) {
+ for (unsigned r = 0; r < rank; r++) {
+ unsigned trans = dir == CrdTransDirectionKind::dim2lvl
+ ? toOrigDim(*this, r)
+ : toStoredDim(*this, r);
+ ret.push_back(srcShape[trans]);
+ }
+ return ret;
+ }
+
+ // Non-permutation
+ AffineMap transMap =
+ dir == CrdTransDirectionKind::dim2lvl ? getDimToLvl() : getLvlToDim();
+
+ SmallVector<AffineExpr> dimRep;
+ dimRep.reserve(srcShape.size());
+ for (int64_t sz : srcShape) {
+ if (!ShapedType::isDynamic(sz)) {
+ // Push back the max coordinate for the given dimension/level size
----------------
aartbik wrote:
period
https://github.com/llvm/llvm-project/pull/70378
More information about the Mlir-commits
mailing list