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] @ y[DenseTensor] -> out[SparseCsrTensor] x[SparseCooTensor] @ y[DenseTensor] -> out[SparseCooTensor] It supports backward propagation. The shape of x should be [M, N] , and the shape of y should be [N] , and the shape of out will be [M] . - Parameters
- 
           - x (Tensor) – The input 2D tensor. It must be SparseCooTensor/SparseCsrTensor. The data type can be float32 or float64. 
- y (Tensor) – 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 Tensor. 
- Return type
- 
           Tensor 
 Examples # required: gpu import paddle from paddle.fluid.framework import _test_eager_guard paddle.seed(100) # csr @ dense -> dense with _test_eager_guard(): 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) # 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) # Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, # [-3.85499096, -2.42975140, -1.75087738]) 
