code: def test_logsumexp(self):
      for dtype in TEST_DTYPES:
          rtol = 1e-2 if dtype == torch.float16 else 1e-5
          mat = torch.tensor(
              [
                  [-1, 0, 1, 10, 50],
                  [-300, -200, -100, -50, -20],
                  [-300, -200, 0, 200, 300],
                  [100, 200, 300, 400, 500],
                  [0, 0, 0, 0, 0],
              ],
              dtype=dtype,
              requires_grad=True,
          ).to(TEST_DEVICE)
          result = lmu.logsumexp(
              mat, keep_mask=None, add_one=False, dim=1
          )
          torch.mean(result).backward(retain_graph=True)
          correct_result = torch.logsumexp(mat, dim=1, keepdim=True)
          self.assertTrue(
              torch.allclose(result, correct_result, rtol=rtol)
          )
  
          result = lmu.logsumexp(
              mat, keep_mask=None, add_one=True, dim=1
          )
          torch.mean(result).backward(retain_graph=True)
          correct_result = torch.logsumexp(
              torch.cat(
                  [
                      mat,
                      torch.zeros(mat.size(0), dtype=dtype)
                      .to(TEST_DEVICE)
                      .unsqueeze(1),
                  ],
                  dim=1,
              ),
              dim=1,
              keepdim=True,
          )
          self.assertTrue(
              torch.allclose(result, correct_result, rtol=rtol)
          )
  
          keep_mask = torch.tensor(
              [
                  [1, 1, 0, 0, 0],
                  [1, 1, 1, 1, 1],
                  [0, 1, 1, 1, 0],
                  [0, 0, 0, 0, 0],
                  [0, 1, 1, 0, 0],
              ],
              dtype=torch.bool,
          ).to(TEST_DEVICE)
          result = lmu.logsumexp(
              mat, keep_mask=keep_mask, add_one=False, dim=1
          )
          torch.mean(result).backward()
  
          row0_input = torch.tensor([-1, 0], dtype=dtype).to(
              TEST_DEVICE
          )
          row1_input = torch.tensor(
              [-300, -200, -100, -50, -20], dtype=dtype
          ).to(TEST_DEVICE)
          row2_input = torch.tensor([-200, 0, 200], dtype=dtype).to(
              TEST_DEVICE
          )
          row4_input = torch.tensor([0, 0], dtype=dtype).to(TEST_DEVICE)
  
          row0 = torch.logsumexp(row0_input, dim=0).unsqueeze(0)
          row1 = torch.logsumexp(row1_input, dim=0).unsqueeze(0)
          row2 = torch.logsumexp(row2_input, dim=0).unsqueeze(0)
          row3 = torch.tensor([0.0], dtype=dtype).to(TEST_DEVICE)
          row4 = torch.logsumexp(row4_input, dim=0).unsqueeze(0)
          correct_result = torch.stack(
              [row0, row1, row2, row3, row4], dim=0
          )
          self.assertTrue(
              torch.allclose(result, correct_result, rtol=rtol)
          )
  
file_path: pytorch-metric-learning/tests/utils/test_loss_and_miner_utils.py
imports: import unittest
  import torch
  from pytorch_metric_learning.utils import loss_and_miner_utils
  from ..None import TEST_DEVICE, TEST_DTYPES
label_desc: Use image node_id 1 for calling the TestLossAndMinerUtils obj's underlying member method code with example usage: obj.test_logsumexp() without return types