mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: https://github.com/pytorch/pytorch/pull/106205 Approved by: https://github.com/albanD
15 lines
374 B
Python
15 lines
374 B
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
from functorch._C import dim
|
|
|
|
tree_flatten = dim.tree_flatten
|
|
|
|
|
|
def tree_map(fn, tree):
|
|
vs, unflatten = tree_flatten(tree)
|
|
return unflatten(fn(v) for v in vs)
|