[mlir][sparse] fully implement sparse tensor to sparse tensor conversions
with rigorous integration test Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D108721
This commit is contained in:
@@ -283,11 +283,23 @@ class SparseTensorConvertConverter : public OpConversionPattern<ConvertOp> {
|
||||
Type resType = op.getType();
|
||||
auto encDst = getSparseTensorEncoding(resType);
|
||||
auto encSrc = getSparseTensorEncoding(op.source().getType());
|
||||
// TODO: implement sparse => sparse
|
||||
// and sparse => dense
|
||||
if (!encDst || encSrc)
|
||||
if (encDst && encSrc) {
|
||||
// This is a sparse => sparse conversion, which is handled as follows:
|
||||
// t = src->asCOO(); ; src to COO in dst order
|
||||
// dst = newSparseTensor(t)
|
||||
// Using the coordinate scheme as an intermediate does not always
|
||||
// yield the fastest conversion but avoids the need for a full
|
||||
// O(N^2) conversion matrix.
|
||||
Value perm;
|
||||
Value coo = genNewCall(rewriter, op, encDst, 3, perm, operands[0]);
|
||||
rewriter.replaceOp(op, genNewCall(rewriter, op, encDst, 1, perm, coo));
|
||||
return success();
|
||||
}
|
||||
if (!encDst || encSrc) {
|
||||
// TODO: sparse => dense
|
||||
return failure();
|
||||
// This is a dense => sparse conversion, that is handled as follows:
|
||||
}
|
||||
// This is a dense => sparse conversion, which is handled as follows:
|
||||
// t = newSparseCOO()
|
||||
// for i1 in dim1
|
||||
// ..
|
||||
|
||||
Reference in New Issue
Block a user