class_docstr: Test loss functions.
class_docstr_tok: ["Test","loss","functions","."]
code: def test_deep_graph_infomax_loss(self):
      import torch
      import numpy as np
      from deepchem.feat.graph_data import GraphData
      from torch_geometric.nn import global_mean_pool
      from deepchem.models.losses import DeepGraphInfomaxLoss
  
      x = np.array([[1, 0], [0, 1], [1, 1], [0, 0]])
      edge_index = np.array([[0, 1, 2, 0, 3], [1, 0, 1, 3, 2]])
      graph_index = np.array([0, 0, 1, 1])
      data = GraphData(
          node_features=x,
          edge_index=edge_index,
          graph_index=graph_index,
      ).numpy_to_torch()
      graph_infomax_loss = DeepGraphInfomaxLoss()._create_pytorch_loss()
  
      num_nodes = data.num_nodes
      embedding_dim = 8
      node_emb = torch.randn(num_nodes, embedding_dim)
      # Compute the global graph representation
      summary_emb = global_mean_pool(node_emb, data.graph_index)
      # Compute positive and negative scores
      positive_score = torch.matmul(node_emb, summary_emb.t())
      negative_score = torch.matmul(
          node_emb, summary_emb.roll(1, dims=0).t()
      )
      loss = graph_infomax_loss(positive_score, negative_score)
  
      # Check if the loss is a scalar and has the correct dtype
      assert loss.dim() == 0
      assert loss.dtype == torch.float32
  
imports: import unittest
  import numpy
  import pytest
  import deepchem
  import deepchem.models.losses
label_desc: Use image node_id 35 for calling the TestLosses obj's underlying member method code with example usage: obj.test_deep_graph_infomax_loss() without return types