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
Uni-Core
Commits
a6ed694a
Unverified
Commit
a6ed694a
authored
Jul 19, 2022
by
Guolin Ke
Committed by
GitHub
Jul 19, 2022
Browse files
remaning no_ to num_
parent
3f498d32
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
unicore/utils.py
unicore/utils.py
+8
-8
No files found.
unicore/utils.py
View file @
a6ed694a
...
...
@@ -296,8 +296,8 @@ def permute_final_dims(tensor: torch.Tensor, inds: List[int]):
return
tensor
.
permute
(
first_inds
+
[
zero_index
+
i
for
i
in
inds
])
def
flatten_final_dims
(
t
:
torch
.
Tensor
,
n
o
_dims
:
int
):
return
t
.
reshape
(
t
.
shape
[:
-
n
o
_dims
]
+
(
-
1
,))
def
flatten_final_dims
(
t
:
torch
.
Tensor
,
n
um
_dims
:
int
):
return
t
.
reshape
(
t
.
shape
[:
-
n
um
_dims
]
+
(
-
1
,))
def
masked_mean
(
mask
,
value
,
dim
,
eps
=
1e-10
):
...
...
@@ -324,18 +324,18 @@ def one_hot(x, num_classes, dtype=torch.float32):
return
x_one_hot
def
batched_gather
(
data
,
inds
,
dim
=
0
,
n
o
_batch_dims
=
0
):
assert
dim
<
0
or
dim
-
n
o
_batch_dims
>=
0
def
batched_gather
(
data
,
inds
,
dim
=
0
,
n
um
_batch_dims
=
0
):
assert
dim
<
0
or
dim
-
n
um
_batch_dims
>=
0
ranges
=
[]
for
i
,
s
in
enumerate
(
data
.
shape
[:
n
o
_batch_dims
]):
for
i
,
s
in
enumerate
(
data
.
shape
[:
n
um
_batch_dims
]):
r
=
torch
.
arange
(
s
)
r
=
r
.
view
(
*
(
*
((
1
,)
*
i
),
-
1
,
*
((
1
,)
*
(
len
(
inds
.
shape
)
-
i
-
1
))))
ranges
.
append
(
r
)
remaining_dims
=
[
slice
(
None
)
for
_
in
range
(
len
(
data
.
shape
)
-
n
o
_batch_dims
)
slice
(
None
)
for
_
in
range
(
len
(
data
.
shape
)
-
n
um
_batch_dims
)
]
remaining_dims
[
dim
-
n
o
_batch_dims
if
dim
>=
0
else
dim
]
=
inds
remaining_dims
[
dim
-
n
um
_batch_dims
if
dim
>=
0
else
dim
]
=
inds
ranges
.
extend
(
remaining_dims
)
return
data
[
ranges
]
...
...
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