dgl.sparse.sp_broadcast_v(A: SparseMatrix, v: Tensor, op: str) SparseMatrix[source]ο

Broadcast operator for sparse matrix and vector.

`v` is broadcasted to the shape of `A` and then the operator is applied on the non-zero values of `A`.

There are two cases regarding the shape of v:

1. `v` is a vector of shape `(1, A.shape[1])` or `(A.shape[1])`. In this case, `v` is broadcasted on the row dimension of `A`.

2. `v` is a vector of shape `(A.shape[0], 1)`. In this case, `v` is broadcasted on the column dimension of `A`.

If `A.val` takes shape `(nnz, D)`, then `v` will be broadcasted on the `D` dimension.

Parameters:
• A (SparseMatrix) β Sparse matrix

• v (torch.Tensor) β Vector

• op (str) β Operator in [βaddβ, βsubβ, βmulβ, βtruedivβ]

Returns:

Sparse matrix

Return type:

SparseMatrix

Examples

```>>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> v = torch.tensor([1, 2, 3, 4])
SparseMatrix(indices=tensor([[1, 0, 2],
[0, 3, 2]]),
values=tensor([11, 24, 33]),
shape=(3, 4), nnz=3)
```
```>>> v = torch.tensor([1, 2, 3]).view(-1, 1)
SparseMatrix(indices=tensor([[1, 0, 2],
[0, 3, 2]]),
values=tensor([12, 21, 33]),
shape=(3, 4), nnz=3)
```
```>>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> val = torch.tensor([[10, 20], [30, 40], [50, 60]])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> v = torch.tensor([1, 2, 3]).view(-1, 1)