mv

paddle.sparse. mv ( x, vec, name=None ) [source]

Note

This API is only supported from CUDA 11.0 .

Applies matrix-vector product of Sparse Matrix ‘x’ and Dense vector ‘vec’ .

The supported input/output Tensor layout are as follows:

Note

x[SparseCsrTensor] @ vec[DenseTensor] -> out[DenseTensor] x[SparseCooTensor] @ vec[DenseTensor] -> out[DenseTensor]

It supports backward propagation.

The shape of x should be [M, N] , and the shape of vec should be [N] , and the shape of out will be [M] .

Parameters
  • x (SparseTensor) – The input 2D tensor. It must be SparseCooTensor/SparseCsrTensor. The data type can be float32 or float64.

  • vec (DenseTensor) – The input 1D tensor. It must be DenseTensor vector. The data type can be float32 or float64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

1D DenseTensor whose dtype is same with input.

Return type

DenseTensor

Examples

>>> 
>>> import paddle
>>> paddle.device.set_device('gpu')
>>> paddle.seed(100)

>>> # csr @ dense -> dense
>>> crows = [0, 2, 3, 5]
>>> cols = [1, 3, 2, 0, 1]
>>> values = [1., 2., 3., 4., 5.]
>>> dense_shape = [3, 4]
>>> csr = paddle.sparse.sparse_csr_tensor(crows, cols, values, dense_shape)
>>> print(csr)
Tensor(shape=[3, 4], dtype=paddle.float32, place=Place(gpu:0), stop_gradient=True,
       crows=[0, 2, 3, 5],
       cols=[1, 3, 2, 0, 1],
       values=[1., 2., 3., 4., 5.])
>>> vec = paddle.randn([4])

>>> out = paddle.sparse.mv(csr, vec)
>>> print(out)
Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-3.85499096, -2.42975140, -1.75087738])