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

Function map_structure

python/paddle/utils/layers_utils.py:254–262  ·  view source on GitHub ↗

Apply `func` to each entry in `structure` and return a new structure.

(
    func: Callable[[_T], _U], *structure: NestedStructure[_T]
)

Source from the content-addressed store, hash-verified

252
253
254def map_structure(
255 func: Callable[[_T], _U], *structure: NestedStructure[_T]
256) -> NestedStructure[_U]:
257 """
258 Apply `func` to each entry in `structure` and return a new structure.
259 """
260 flat_structure = [flatten(s) for s in structure]
261 entries = zip(*flat_structure)
262 return pack_sequence_as(structure[0], [func(*x) for x in entries])
263
264
265def hold_mutable_vars(structure):

Callers 15

while_loopFunction · 0.90
create_var_likeFunction · 0.90
condFunction · 0.90
merge_every_var_listFunction · 0.90
static_pylayerFunction · 0.90
_map_structure_onlyFunction · 0.90
_map_debug_infoFunction · 0.90
merge_chunksFunction · 0.90
map_ifFunction · 0.90

Calls 3

pack_sequence_asFunction · 0.85
flattenFunction · 0.70
funcFunction · 0.50

Tested by

no test coverage detected