def test_as_tensor_converts_field_correctly(self): index_field = IndexField(4, self.text) tensor = index_field.as_tensor( index_field.get_padding_lengths()).detach().cpu().numpy() numpy.testing.assert_array_equal(tensor, numpy.array([4]))
def test_as_array_converts_field_correctly(self): index_field = IndexField(4, self.text) array = index_field.as_array(index_field.get_padding_lengths()) numpy.testing.assert_array_equal(array, numpy.array([4]))
def test_as_array_handles_none_index_values(self): index_field = IndexField(None, self.text) array = index_field.as_array(index_field.get_padding_lengths()) numpy.testing.assert_array_equal(array, numpy.array([0, 0, 0, 0, 0]))
def test_index_field_inherits_padding_lengths_from_text_field(self): index_field = IndexField(4, self.text) assert index_field.get_padding_lengths() == {"num_options": 5}
def test_as_tensor_converts_field_correctly(self): index_field = IndexField(4, self.text) tensor = index_field.as_tensor(index_field.get_padding_lengths()).data.cpu().numpy() numpy.testing.assert_array_equal(tensor, numpy.array([4]))