[Mlir-commits] [mlir] 9db037d - [mlir][sparse] fixed pack op documentation and purity

Aart Bik llvmlistbot at llvm.org
Fri Feb 10 16:28:57 PST 2023


Author: Aart Bik
Date: 2023-02-10T16:28:42-08:00
New Revision: 9db037d542d974f42120ba69c30d53392638a8d5

URL: https://github.com/llvm/llvm-project/commit/9db037d542d974f42120ba69c30d53392638a8d5
DIFF: https://github.com/llvm/llvm-project/commit/9db037d542d974f42120ba69c30d53392638a8d5.diff

LOG: [mlir][sparse] fixed pack op documentation and purity

Example did not have correct shapes. Also the operation
has no side effects (since it slaps a clean SSA tensor
around the data).

Reviewed By: Peiming, wrengr

Differential Revision: https://reviews.llvm.org/D143679

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
index 395015d23d8cd..299cd0f14fa42 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
@@ -58,7 +58,7 @@ def SparseTensor_NewOp : SparseTensor_Op<"new", [Pure]>,
   let hasVerifier = 1;
 }
 
-def SparseTensor_PackOp : SparseTensor_Op<"pack">,
+def SparseTensor_PackOp : SparseTensor_Op<"pack", [Pure]>,
     Arguments<(ins AnyRankedTensor:$data,
                    AnyRankedTensor:$indices)>,
     Results<(outs AnySparseTensor: $result)> {
@@ -66,9 +66,9 @@ def SparseTensor_PackOp : SparseTensor_Op<"pack">,
 
   let description = [{
     Packs the data/indices into a COO sparse tensor. The coordinates in `indices`
-    shall not exceed the dimension sizes of the returned sparse tensor.
-    Note that the returned tensor must be statically
-    shaped because it is impossible to infer the shape from sparse coordinates.
+    shall not exceed the dimension sizes of the returned sparse tensor. Note
+    that the returned tensor must be statically shaped because it is impossible
+    to infer the shape from sparse coordinates.
 
     `$indices`: stored via a 2-D tensor of integer elements with shape [N, ndims],
     which specifies the indices of the elements in the sparse tensor that contains
@@ -77,19 +77,19 @@ def SparseTensor_PackOp : SparseTensor_Op<"pack">,
     `$data`: stored via a 1-D tensor with shape [N], that supplies the corresponding
     values for the indices.
 
-    The operation can be used to materialize a sparse tensor from external sources. E.g.,
-    when passing from Python as two numpy arrays for data and indices.
+    The operation can be used to materialize a sparse tensor from external sources.
+    E.g., when passing from Python as two numpy arrays for data and indices.
 
     Example:
     ```mlir
-    %data    = arith.constant dense<[ 1     , 5     ]> : tensor<3xf64>
-    %indices = arith.constant dense<[[0,  0],[1,  2]]> : tensor<3x2xindex>
-
-    %st = sparse_tensor.pack %data, %indices : tensor<6xf64>, tensor<6x2xi32
-                                            to tensor<100x100xf64, #COO>
-    // %st = [[1, 0, 0, 0],
-    //        [0, 0, 5, 0],
-    //        [0, 0, 0, 0]]
+    %data    = arith.constant dense<[ 1.1,   2.2,   3.3 ]> : tensor<3xf64>
+    %indices = arith.constant dense<[[0,0], [1,2], [1,3]]> : tensor<3x2xindex>
+
+    %st = sparse_tensor.pack %data, %indices : tensor<3xf64>, tensor<3x2xindex
+                                            to tensor<3x4xf64, #COO>
+    // yields COO format |1.1, 0.0, 0.0, 0.0|
+    //     of 3x4 matrix |0.0, 0.0, 2.2, 3.3|
+    //                   |0.0, 0.0, 0.0, 0.0|
     ```
   }];
 


        


More information about the Mlir-commits mailing list