mindspore.ops.csr_softmax

View Source On Gitee
mindspore.ops.csr_softmax(logits: CSRTensor, dtype: mstype)[source]

Calculates the softmax of a CSRTensorMatrix.

Parameters
  • logits (CSRTensor) – Input sparse CSRTensor.

  • dtype (dtype) – Input data type.

Returns

CSRTensor, a CSRTensor containing

  • indptr - Indicates the start and end point for non-zero values in each row.

  • indices - The column positions of all non-zero values of the input.

  • values - The non-zero values of the dense tensor.

  • shape - The shape of the CSRTensor.

Supported Platforms:

GPU CPU

Examples

>>> import mindspore as ms
>>> import mindspore.ops as ops
>>> import mindspore.common.dtype as mstype
>>> from mindspore import Tensor, CSRTensor
>>> logits_indptr = Tensor([0, 4, 6], dtype=mstype.int32)
>>> logits_indices = Tensor([0, 2, 3, 4, 3, 4], dtype=mstype.int32)
>>> logits_values = Tensor([1, 2, 3, 4, 1, 2], dtype=mstype.float32)
>>> shape = (2, 6)
>>> logits = CSRTensor(logits_indptr, logits_indices, logits_values, shape)
>>> out = ops.csr_softmax(logits, dtype=mstype.float32)
>>> print(out)
CSRTensor(shape=[2, 6], dtype=Float32, indptr=Tensor(shape=[3], dtype=Int32, value=[0 4 6]),
               indices=Tensor(shape=[6], dtype=Int32, value=[0 2 3 4 3 4]),
               values=Tensor(shape=[6], dtype=Float32, value=[ 3.20586003e-02  8.71443152e-02  2.36882806e-01
               6.43914223e-01  2.68941432e-01  7.31058598e-01]))