code: def test_spmm(
      without_extensions, device, reduce, transpose, is_undirected
  ):
      if without_extensions:
          warnings.filterwarnings(
              "ignore", ".*can be accelerated via.*"
          )
  
      if is_undirected:
          kwargs = dict(is_undirected=True)
          adj = EdgeIndex(
              [[0, 1, 1, 2], [1, 0, 2, 1]], device=device, **kwargs
          )
      else:
          adj = EdgeIndex([[0, 1, 1, 2], [2, 0, 1, 2]], device=device)
      adj = adj.sort_by("col" if transpose else "row").values
  
      # Basic:
      x = torch.randn(3, 1, device=device)
  
      with pytest.raises(ValueError, match="to be sorted by"):
          adj.matmul(x, reduce=reduce, transpose=not transpose)
  
      out = adj.matmul(x, reduce=reduce, transpose=transpose)
      exp = _scatter_spmm(adj, x, None, reduce, transpose)
      assert out.allclose(exp)
  
      # With non-zero values:
      x = torch.randn(3, 1, device=device)
      value = torch.rand(adj.size(1), device=device)
  
      with pytest.raises(
          ValueError, match="'other_value' not supported"
      ):
          adj.matmul(
              x, reduce=reduce, other_value=value, transpose=transpose
          )
  
      out = adj.matmul(x, value, reduce=reduce, transpose=transpose)
      exp = _scatter_spmm(adj, x, value, reduce, transpose)
      assert out.allclose(exp)
  
      # Gradients w.r.t. other:
      x1 = torch.randn(3, 1, device=device, requires_grad=True)
      x2 = x1.detach().requires_grad_()
      grad = torch.randn_like(x1)
  
      out = adj.matmul(x1, reduce=reduce, transpose=transpose)
      out.backward(grad)
      exp = _scatter_spmm(adj, x2, None, reduce, transpose)
      exp.backward(grad)
      assert x1.grad.allclose(x2.grad)
  
      # Gradients w.r.t. value:
      x = torch.randn(3, 1, device=device)
      value1 = torch.rand(
          adj.size(1), device=device, requires_grad=True
      )
      value2 = value1.detach().requires_grad_()
      grad = torch.randn_like(x)
  
      out = adj.matmul(x, value1, reduce=reduce, transpose=transpose)
      out.backward(grad)
      exp = _scatter_spmm(adj, x, value2, reduce, transpose)
      exp.backward(grad)
      assert value1.grad.allclose(value2.grad)
  
imports: import os.path
  import warnings
  from typing import List, Optional
  import pytest
  import torch
  from torch import Tensor, tensor
  import torch_geometric
  from torch_geometric import EdgeIndex
  from torch_geometric.edge_index import SUPPORTED_DTYPES, ReduceType, SortReturnType, _scatter_spmm, _torch_sparse_spmm, _TorchSPMM, set_tuple_item
  from torch_geometric.profile import benchmark
  from torch_geometric.testing import onlyCUDA, onlyLinux, withCUDA, withoutExtensions, withPackage
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import scatter
label_desc: Use image node_id 28 for calling a global function with example usage: test_spmm(without_extensions, device, reduce, transpose, is_undirected) without return types