class_docstr: Adds the random walk positional encoding from the `"Graph Neural
  Networks with Learnable Structural and Positional Representations"
  <https://arxiv.org/abs/2110.07875>`_ paper to the given graph
  (functional name: :obj:`add_random_walk_pe`).
  
  Args:
      walk_length (int): The number of random walk steps.
      attr_name (str, optional): The attribute name of the data object to add
          positional encodings to. If set to :obj:`None`, will be
          concatenated to :obj:`data.x`.
          (default: :obj:`"random_walk_pe"`)
class_docstr_tok: ["Adds","the","random","walk","positional","encoding","from","the","`","``","Graph","Neural","Networks","with","Learnable","Structural","and","Positional","Representations","''","<","https",":","\/\/arxiv.org\/abs\/2110.07875",">","`","_","paper","to","the","given","graph","(","functional","name",":",":","obj",":","`","add_random_walk_pe","`",")",".","Args",":","walk_length","(","int",")",":","The","number","of","random","walk","steps",".","attr_name","(","str",",","optional",")",":","The","attribute","name","of","the","data","object","to","add","positional","encodings","to",".","If","set","to",":","obj",":","`","None","`",",","will","be","concatenated","to",":","obj",":","`","data.x","`",".","(","default",":",":","obj",":","`","``","random_walk_pe","''","`",")"]
code: def forward(self, data: Data) -> Data:
      assert data.edge_index is not None
      row, col = data.edge_index
      N = data.num_nodes
      assert N is not None
  
      if data.edge_weight is None:
          value = torch.ones(data.num_edges, device=row.device)
      else:
          value = data.edge_weight
      value = scatter(value, row, dim_size=N, reduce="sum").clamp(
          min=1
      )[row]
      value = 1.0 / value
  
      if N <= 2_000:  # Dense code path for faster computation:
          adj = torch.zeros((N, N), device=row.device)
          adj[row, col] = value
          loop_index = torch.arange(N, device=row.device)
      elif torch_geometric.typing.WITH_WINDOWS:
          adj = to_torch_coo_tensor(
              data.edge_index, value, size=data.size()
          )
      else:
          adj = to_torch_csr_tensor(
              data.edge_index, value, size=data.size()
          )
  
      def get_pe(out: Tensor) -> Tensor:
          if is_torch_sparse_tensor(out):
              return get_self_loop_attr(
                  *to_edge_index(out), num_nodes=N
              )
          return out[loop_index, loop_index]
  
      out = adj
      pe_list = [get_pe(out)]
      for _ in range(self.walk_length - 1):
          out = out @ adj
          pe_list.append(get_pe(out))
  
      pe = torch.stack(pe_list, dim=-1)
      data = add_node_attr(data, pe, attr_name=self.attr_name)
  
      return data
  
file_path: pytorch_geometric/torch_geometric/transforms/add_positional_encoding.py
imports: from typing import Any, Optional
  import numpy
  import torch
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric.data import Data
  from torch_geometric.data.datapipes import functional_transform
  from torch_geometric.transforms import BaseTransform
  from torch_geometric.utils import get_laplacian, get_self_loop_attr, is_torch_sparse_tensor, scatter, to_edge_index, to_scipy_sparse_matrix, to_torch_coo_tensor, to_torch_csr_tensor
label_desc: Use image node_id 2 for calling the AddRandomWalkPE obj's underlying member method code with example usage: obj.forward(data) and returns: data, out, get_self_loop_attr