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>

source

pub fn name() -> &'static str

Returns a name.

source

pub fn as_operation(&self) -> &Operation<'c>

Returns a generic operation.

source

pub fn builder( context: &'c Context, location: Location<'c> ) -> UnpackOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset>

Creates a builder.

source

pub fn ret_values(&self) -> Result<OperationResult<'c, '_>, Error>

source

pub fn ret_levels(&self) -> impl Iterator<Item = OperationResult<'c, '_>>

source

pub fn val_len(&self) -> Result<OperationResult<'c, '_>, Error>

source

pub fn lvl_lens(&self) -> impl Iterator<Item = OperationResult<'c, '_>>

source

pub fn tensor(&self) -> Result<Value<'c, '_>, Error>

source

pub fn out_values(&self) -> Result<Value<'c, '_>, Error>

source

pub fn out_levels(&self) -> impl Iterator<Item = Value<'c, '_>>

Trait Implementations§

source§

impl<'c> From<UnpackOperation<'c>> for Operation<'c>

source§

fn from(operation: UnpackOperation<'c>) -> Self

Converts to this type from the input type.
source§

impl<'c> TryFrom<Operation<'c>> for UnpackOperation<'c>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(operation: Operation<'c>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for UnpackOperation<'c>

§

impl<'c> !Send for UnpackOperation<'c>

§

impl<'c> !Sync for UnpackOperation<'c>

§

impl<'c> Unpin for UnpackOperation<'c>

§

impl<'c> UnwindSafe for UnpackOperation<'c>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.