code: def test_flattened_index_select(self):
      indices = numpy.array([[1, 2], [3, 4]])
      targets = torch.ones([2, 6, 3]).cumsum(1) - 1
      # Make the second batch double it's index so they're different.
      targets[1, :, :] *= 2
      indices = torch.tensor(indices, dtype=torch.long)
  
      selected = util.flattened_index_select(targets, indices)
  
      assert list(selected.size()) == [2, 2, 2, 3]
  
      ones = numpy.ones([3])
      numpy.testing.assert_array_equal(
          selected[0, 0, 0, :].data.numpy(), ones
      )
      numpy.testing.assert_array_equal(
          selected[0, 0, 1, :].data.numpy(), ones * 2
      )
      numpy.testing.assert_array_equal(
          selected[0, 1, 0, :].data.numpy(), ones * 3
      )
      numpy.testing.assert_array_equal(
          selected[0, 1, 1, :].data.numpy(), ones * 4
      )
  
      numpy.testing.assert_array_equal(
          selected[1, 0, 0, :].data.numpy(), ones * 2
      )
      numpy.testing.assert_array_equal(
          selected[1, 0, 1, :].data.numpy(), ones * 4
      )
      numpy.testing.assert_array_equal(
          selected[1, 1, 0, :].data.numpy(), ones * 6
      )
      numpy.testing.assert_array_equal(
          selected[1, 1, 1, :].data.numpy(), ones * 8
      )
  
      # Check we only accept 2D indices.
      with pytest.raises(ConfigurationError):
          util.flattened_index_select(targets, torch.ones([3, 4, 5]))
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_almost_equal
  import torch
  import pytest
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn import util
label_desc: Use image node_id 29 for calling the TestNnUtil obj's underlying member method code with example usage: obj.test_flattened_index_select() without return types