Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
OpenFold
Commits
ff969b98
Commit
ff969b98
authored
Oct 02, 2021
by
Gustaf Ahdritz
Browse files
Update type checks in tensor_tree_map
parent
f34bef8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
openfold/utils/tensor_utils.py
openfold/utils/tensor_utils.py
+5
-5
No files found.
openfold/utils/tensor_utils.py
View file @
ff969b98
...
@@ -92,16 +92,16 @@ def dict_map(fn, dic, leaf_type):
...
@@ -92,16 +92,16 @@ def dict_map(fn, dic, leaf_type):
def
tree_map
(
fn
,
tree
,
leaf_type
):
def
tree_map
(
fn
,
tree
,
leaf_type
):
tree_type
=
type
(
tree
)
if
(
isinstance
(
tree
,
dict
)):
if
(
tree_type
is
dict
):
return
dict_map
(
fn
,
tree
,
leaf_type
)
return
dict_map
(
fn
,
tree
,
leaf_type
)
elif
(
tree_type
is
list
):
elif
(
isinstance
(
tree
,
list
)
)
:
return
[
tree_map
(
fn
,
x
,
leaf_type
)
for
x
in
tree
]
return
[
tree_map
(
fn
,
x
,
leaf_type
)
for
x
in
tree
]
elif
(
tree_type
is
tuple
):
elif
(
isinstance
(
tree
,
tuple
)
)
:
return
tuple
([
tree_map
(
fn
,
x
,
leaf_type
)
for
x
in
tree
])
return
tuple
([
tree_map
(
fn
,
x
,
leaf_type
)
for
x
in
tree
])
elif
(
tree_type
is
leaf_type
):
elif
(
isinstance
(
tree
,
leaf_type
)
)
:
return
fn
(
tree
)
return
fn
(
tree
)
else
:
else
:
print
(
type
(
tree
))
raise
ValueError
(
"Not supported"
)
raise
ValueError
(
"Not supported"
)
tensor_tree_map
=
partial
(
tree_map
,
leaf_type
=
torch
.
Tensor
)
tensor_tree_map
=
partial
(
tree_map
,
leaf_type
=
torch
.
Tensor
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment