MCPcopy
hub / github.com/dmlc/dgl / recursive_apply_pair

Function recursive_apply_pair

python/dgl/utils/internal.py:1138–1158  ·  view source on GitHub ↗

Recursively apply a function to every pair of elements in two containers with the same nested structure.

(data1, data2, fn, *args, **kwargs)

Source from the content-addressed store, hash-verified

1136
1137
1138def recursive_apply_pair(data1, data2, fn, *args, **kwargs):
1139 """Recursively apply a function to every pair of elements in two containers with the
1140 same nested structure.
1141 """
1142 if isinstance(data1, Mapping) and isinstance(data2, Mapping):
1143 return {
1144 k: recursive_apply_pair(data1[k], data2[k], fn, *args, **kwargs)
1145 for k in data1.keys()
1146 }
1147 elif isinstance(data1, tuple) and isinstance(data2, tuple):
1148 return tuple(
1149 recursive_apply_pair(x, y, fn, *args, **kwargs)
1150 for x, y in zip(data1, data2)
1151 )
1152 elif is_listlike(data1) and is_listlike(data2):
1153 return [
1154 recursive_apply_pair(x, y, fn, *args, **kwargs)
1155 for x, y in zip(data1, data2)
1156 ]
1157 else:
1158 return fn(data1, data2, *args, **kwargs)
1159
1160
1161def context_of(data):

Callers 2

_find_indicesMethod · 0.85
__next__Method · 0.85

Calls 2

is_listlikeFunction · 0.70
keysMethod · 0.45

Tested by

no test coverage detected