mindspore.ops.SparseTensorDenseMatmul

class mindspore.ops.SparseTensorDenseMatmul(adjoint_st=False, adjoint_dt=False)[源代码]

Multiplies sparse matrix A by dense matrix B. The rank of sparse matrix and dense matrix must be equal to 2.

Parameters
  • adjoint_st (bool) – If true, sparse tensor is transposed before multiplication. Default: False.

  • adjoint_dt (bool) – If true, dense tensor is transposed before multiplication. Default: False.

Inputs:
  • indices (Tensor) - A 2-D Tensor, represents the position of the element in the sparse tensor. Support int32, int64, each element value should be a non-negative int number. The shape is \((n, 2)\).

  • values (Tensor) - A 1-D Tensor, represents the value corresponding to the position in the indices. Support float16, float32, float64, int32, int64, complex64, complex128. The shape should be \((n,)\).

  • sparse_shape (tuple(int) or (Tensor)) - A positive int tuple or tensor which specifies the shape of sparse tensor, and only constant value is allowed when sparse_shape is a tensor, should have 2 elements, represent sparse tensor shape is \((N, C)\).

  • dense (Tensor) - A 2-D Tensor, the dtype is same as values. If adjoint_st is False and adjoint_dt is False, the shape must be \((C, M)\). If adjoint_st is False and adjoint_dt is True, the shape must be \((M, C)\). If adjoint_st is True and adjoint_dt is False, the shape must be \((N, M)\). If adjoint_st is True and adjoint_dt is True, the shape must be \((M, N)\).

Outputs:

Tensor, the dtype is the same as values. If adjoint_st is False, the shape is \((N, M)\). If adjoint_st is True, the shape is \((C, M)\).

Raises
  • TypeError – If the type of adjoint_st or adjoint_dt is not bool, or the dtype of indices, dtype of values and dtype of dense don’t meet the parameter description.

  • ValueError – If sparse_shape, shape of indices, shape of values, and shape of dense don’t meet the parameter description.

Supported Platforms:

Ascend CPU

Examples

>>> indices = Tensor([[0, 1], [1, 2]], dtype=mindspore.int32)
>>> values = Tensor([1, 2], dtype=mindspore.float32)
>>> sparse_shape = (3, 4)
>>> dense = Tensor([[1, 1], [2, 2], [3, 3], [4, 4]], dtype=mindspore.float32)
>>> sparse_dense_matmul = ops.SparseTensorDenseMatmul()
>>> out = sparse_dense_matmul(indices, values, sparse_shape, dense)
>>> print(out)
[[2. 2.]
 [6. 6.]
 [0. 0.]]