mindspore.ops.csr_add
- mindspore.ops.csr_add(a: CSRTensor, b: CSRTensor, alpha: Tensor, beta: Tensor)[source]
Computes the linear combination of two input CSRTensors a and b.
\[out = alpha * a + beta * b\]where both \(a\) and \(b\) are CSRTensor, \(alpha\) and \(beta\) are both Tensor
Note
The user need to ensure that the input sparse matrix is legal. Otherwise, the behavior of the operator is undefined. For example, when there are multiple elements in the same position, the operator may return an error of fail execute.
- Parameters
- Returns
CSRTensor, a CSRTensor containing the following parts.
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.common.dtype as mstype >>> from mindspore import Tensor, CSRTensor >>> from mindspore import ops >>> a_indptr = Tensor([0, 1, 2], dtype=mstype.int32) >>> a_indices = Tensor([0, 1], dtype=mstype.int32) >>> a_values = Tensor([1, 2], dtype=mstype.float32) >>> shape = (2, 6) >>> b_indptr = Tensor([0, 1, 2], dtype=mstype.int32) >>> b_indices = Tensor([0, 1], dtype=mstype.int32) >>> b_values = Tensor([1, 2], dtype=mstype.float32) >>> alpha = Tensor(1, mstype.float32) >>> beta = Tensor(1, mstype.float32) >>> csra = CSRTensor(a_indptr, a_indices, a_values, shape) >>> csrb = CSRTensor(b_indptr, b_indices, b_values, shape) >>> out = ops.csr_add(csra, csrb, alpha, beta) >>> print(out) CSRTensor(shape=[2, 6], dtype=Float32, indptr=Tensor(shape=[3], dtype=Int32, value=[0 1 2]), indices=Tensor(shape=[2], dtype=Int32, value=[0 1]), values=Tensor(shape=[2], dtype=Float32, value=[ 2.00000000e+00 4.00000000e+00]))