code: def test_triu_indices(self):
      iu1 = triu_indices(4)
      iu2 = triu_indices(4, k=2)
      iu3 = triu_indices(4, m=5)
      iu4 = triu_indices(4, k=2, m=5)
  
      a = np.array(
          [
              [1, 2, 3, 4],
              [5, 6, 7, 8],
              [9, 10, 11, 12],
              [13, 14, 15, 16],
          ]
      )
      b = np.arange(1, 21).reshape(4, 5)
  
      # Both for indexing:
      assert_array_equal(
          a[iu1], array([1, 2, 3, 4, 6, 7, 8, 11, 12, 16])
      )
      assert_array_equal(
          b[iu3],
          array([1, 2, 3, 4, 5, 7, 8, 9, 10, 13, 14, 15, 19, 20]),
      )
  
      # And for assigning values:
      a[iu1] = -1
      assert_array_equal(
          a,
          array(
              [
                  [-1, -1, -1, -1],
                  [5, -1, -1, -1],
                  [9, 10, -1, -1],
                  [13, 14, 15, -1],
              ]
          ),
      )
      b[iu3] = -1
      assert_array_equal(
          b,
          array(
              [
                  [-1, -1, -1, -1, -1],
                  [6, -1, -1, -1, -1],
                  [11, 12, -1, -1, -1],
                  [16, 17, 18, -1, -1],
              ]
          ),
      )
  
      # These cover almost the whole array (two diagonals right of the
      # main one):
      a[iu2] = -10
      assert_array_equal(
          a,
          array(
              [
                  [-1, -1, -10, -10],
                  [5, -1, -1, -10],
                  [9, 10, -1, -1],
                  [13, 14, 15, -1],
              ]
          ),
      )
      b[iu4] = -10
      assert_array_equal(
          b,
          array(
              [
                  [-1, -1, -10, -10, -10],
                  [6, -1, -1, -10, -10],
                  [11, 12, -1, -1, -10],
                  [16, 17, 18, -1, -1],
              ]
          ),
      )
  
imports: import functools
  from unittest import expectedFailure, skipIf
  import pytest
  from pytest import raises
  from torch.testing._internal.common_utils import instantiate_parametrized_tests, parametrize, run_tests, TEST_WITH_TORCHDYNAMO, TestCase, xpassIfTorchDynamo
label_desc: Use image node_id 1 for calling the TestTriuIndices obj's underlying member method code with example usage: obj.test_triu_indices() without return types