code: def add_node_attr(
      data: Data,
      value: Any,
      attr_name: Optional[str] = None,
  ) -> Data:
      # TODO Move to `BaseTransform`.
      if attr_name is None:
          if data.x is not None:
              x = data.x.view(-1, 1) if data.x.dim() == 1 else data.x
              data.x = torch.cat(
                  [x, value.to(x.device, x.dtype)], dim=-1
              )
          else:
              data.x = value
      else:
          data[attr_name] = value
  
      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 1 for calling a global function with example usage: add_node_attr(data, value, attr_name) and returns: data