code: def test_masked(self):
      attention = LegacyAttention()
      # Testing general masked non-batched case.
      vector = torch.FloatTensor([[0.3, 0.1, 0.5]])
      matrix = torch.FloatTensor(
          [[[0.6, 0.8, 0.1], [0.15, 0.5, 0.2], [0.1, 0.4, 0.3]]]
      )
      mask = torch.FloatTensor([[1.0, 0.0, 1.0]])
      result = attention(vector, matrix, mask).data.numpy()
      assert_almost_equal(
          result, numpy.array([[0.52248482, 0.0, 0.47751518]])
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/modules/attention/legacy_attention_test.py
imports: from __future__ import absolute_import
  import numpy
  from numpy.testing import assert_almost_equal
  import torch
  from allennlp.common import Params
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.modules.attention.attention import Attention
  from allennlp.modules.attention.legacy_attention import LegacyAttention
label_desc: Use image node_id 3 for calling the TestLegacyAttention obj's underlying member method code with example usage: obj.test_masked() without return types