MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / pack_sequence_as

Function pack_sequence_as

python/paddle/utils/layers_utils.py:232–251  ·  view source on GitHub ↗

Pack a given flattened sequence into a given structure.

(structure, flat_sequence)

Source from the content-addressed store, hash-verified

230
231
232def pack_sequence_as(structure, flat_sequence):
233 """
234 Pack a given flattened sequence into a given structure.
235 """
236 if not is_sequence(flat_sequence):
237 raise TypeError("flat_sequence must be a sequence")
238 if not is_sequence(structure):
239 if len(flat_sequence) != 1:
240 raise ValueError(
241 f"Structure is a scalar but len(flat_sequence) == {len(flat_sequence)} > 1"
242 )
243 return flat_sequence[0]
244 flat_structure = flatten(structure)
245 if len(flat_structure) != len(flat_sequence):
246 raise ValueError(
247 f"Could not pack sequence. Structure had {len(flat_structure)} elements, but flat_sequence "
248 f"had {len(flat_sequence)} elements. Structure: {structure}, flat_sequence: {flat_sequence}."
249 )
250 _, packed = _packed_nest_with_indices(structure, flat_sequence, 0)
251 return _sequence_like(structure, packed)
252
253
254def map_structure(

Callers 10

condFunction · 0.90
pack_undefined_var_asFunction · 0.90
wrappedFunction · 0.90
_split_args_helperFunction · 0.90
merge_chunksFunction · 0.90
saved_tensorMethod · 0.90
map_structureFunction · 0.85
copy_mutable_varsFunction · 0.85

Calls 6

is_sequenceFunction · 0.85
TypeErrorClass · 0.85
ValueErrorClass · 0.85
_sequence_likeFunction · 0.85
flattenFunction · 0.70

Tested by

no test coverage detected