code: def test_weighted_sum_works_on_simple_input(self):
      batch_size = 1
      sentence_length = 5
      embedding_dim = 4
      sentence_array = numpy.random.rand(
          batch_size, sentence_length, embedding_dim
      )
      sentence_tensor = torch.from_numpy(sentence_array).float()
      attention_tensor = torch.FloatTensor([[0.3, 0.4, 0.1, 0, 1.2]])
      aggregated_array = util.weighted_sum(
          sentence_tensor, attention_tensor
      ).data.numpy()
      assert aggregated_array.shape == (batch_size, embedding_dim)
      expected_array = (
          0.3 * sentence_array[0, 0]
          + 0.4 * sentence_array[0, 1]
          + 0.1 * sentence_array[0, 2]
          + 0.0 * sentence_array[0, 3]
          + 1.2 * sentence_array[0, 4]
      )
      numpy.testing.assert_almost_equal(
          aggregated_array, [expected_array], decimal=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 17 for calling the TestNnUtil obj's underlying member method code with example usage: obj.test_weighted_sum_works_on_simple_input() without return types