Struct melior::dialect::ods::sparse_tensor::UnpackOperation
source · pub struct UnpackOperation<'c> { /* private fields */ }
Expand description
An unpack
operation. Returns the (values, coordinates) pair unpacked from the input tensor.
The unpack operation is the inverse of sparse_tensor::pack
. It returns
the values and per-level position and coordinate array to the user
from the sparse tensor along with the actual length of the memory used in
each returned buffer. This operation can be used for returning an
unpacked MLIR sparse tensor to frontend; e.g., returning two numpy arrays to Python.
Disclaimer: This is the user’s responsibility to allocate large enough buffers to hold the sparse tensor. The sparse compiler simply copies each fields of the sparse tensor into the user-supplied buffer without bound checking.
TODO: the current implementation does not yet support non-identity mappings.
Example:
// input 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|
%v, %p, %c, %v_len, %p_len, %c_len = sparse_tensor.unpack %sp : tensor<3x4xf64, #SparseVector>
outs(%od, %op, %oi : tensor<3xf64>, tensor<2xindex>, tensor<3x2xindex>)
-> tensor<3xf64>, (tensor<2xindex>, tensor<3x2xindex>), index, (index, index)
// %v = arith.constant dense<[ 1.1, 2.2, 3.3 ]> : tensor<3xf64>
// %p = arith.constant dense<[ 0, 3 ]> : tensor<2xindex>
// %c = arith.constant dense<[[0,0], [1,2], [1,3]]> : tensor<3x2xindex>
// %v_len = 3
// %p_len = 2
// %c_len = 6 (3x2)
Implementations§
source§impl<'c> UnpackOperation<'c>
impl<'c> UnpackOperation<'c>
sourcepub fn as_operation(&self) -> &Operation<'c>
pub fn as_operation(&self) -> &Operation<'c>
Returns a generic operation.
sourcepub fn builder(
context: &'c Context,
location: Location<'c>
) -> UnpackOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> UnpackOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset>
Creates a builder.