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
Torchaudio
Commits
bc1ffb11
Unverified
Commit
bc1ffb11
authored
Apr 06, 2020
by
moto
Committed by
GitHub
Apr 06, 2020
Browse files
Simplify helper function (#514)
parent
3695a0ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
28 deletions
+5
-28
test/test_batch_consistency.py
test/test_batch_consistency.py
+5
-28
No files found.
test/test_batch_consistency.py
View file @
bc1ffb11
...
@@ -10,19 +10,7 @@ import common_utils
...
@@ -10,19 +10,7 @@ import common_utils
from
common_utils
import
AudioBackendScope
,
BACKENDS
from
common_utils
import
AudioBackendScope
,
BACKENDS
def
_test_batch_shape
(
functional
,
tensor
,
*
args
,
**
kwargs
):
def
_test_batch_shape
(
functional
,
tensor
,
*
args
,
atol
=
1e-8
,
rtol
=
1e-5
,
**
kwargs
):
kwargs_compare
=
{}
if
'atol'
in
kwargs
:
atol
=
kwargs
[
'atol'
]
del
kwargs
[
'atol'
]
kwargs_compare
[
'atol'
]
=
atol
if
'rtol'
in
kwargs
:
rtol
=
kwargs
[
'rtol'
]
del
kwargs
[
'rtol'
]
kwargs_compare
[
'rtol'
]
=
rtol
# Single then transform then batch
# Single then transform then batch
torch
.
random
.
manual_seed
(
42
)
torch
.
random
.
manual_seed
(
42
)
...
@@ -36,24 +24,13 @@ def _test_batch_shape(functional, tensor, *args, **kwargs):
...
@@ -36,24 +24,13 @@ def _test_batch_shape(functional, tensor, *args, **kwargs):
computed
=
functional
(
tensors
.
clone
(),
*
args
,
**
kwargs
)
computed
=
functional
(
tensors
.
clone
(),
*
args
,
**
kwargs
)
assert
expected
.
shape
==
computed
.
shape
,
(
expected
.
shape
,
computed
.
shape
)
assert
expected
.
shape
==
computed
.
shape
,
(
expected
.
shape
,
computed
.
shape
)
assert
torch
.
allclose
(
expected
,
computed
,
**
kwargs_compare
)
assert
torch
.
allclose
(
expected
,
computed
,
atol
=
atol
,
rtol
=
rtol
)
return
tensors
,
expected
return
tensors
,
expected
def
_test_batch
(
functional
,
tensor
,
*
args
,
**
kwargs
):
def
_test_batch
(
functional
,
tensor
,
*
args
,
atol
=
1e-8
,
rtol
=
1e-5
,
**
kwargs
):
tensors
,
expected
=
_test_batch_shape
(
functional
,
tensor
,
*
args
,
**
kwargs
)
tensors
,
expected
=
_test_batch_shape
(
functional
,
tensor
,
*
args
,
atol
=
atol
,
rtol
=
rtol
,
**
kwargs
)
kwargs_compare
=
{}
if
'atol'
in
kwargs
:
atol
=
kwargs
[
'atol'
]
del
kwargs
[
'atol'
]
kwargs_compare
[
'atol'
]
=
atol
if
'rtol'
in
kwargs
:
rtol
=
kwargs
[
'rtol'
]
del
kwargs
[
'rtol'
]
kwargs_compare
[
'rtol'
]
=
rtol
# 3-Batch then transform
# 3-Batch then transform
...
@@ -67,7 +44,7 @@ def _test_batch(functional, tensor, *args, **kwargs):
...
@@ -67,7 +44,7 @@ def _test_batch(functional, tensor, *args, **kwargs):
computed
=
functional
(
tensors
.
clone
(),
*
args
,
**
kwargs
)
computed
=
functional
(
tensors
.
clone
(),
*
args
,
**
kwargs
)
assert
expected
.
shape
==
computed
.
shape
,
(
expected
.
shape
,
computed
.
shape
)
assert
expected
.
shape
==
computed
.
shape
,
(
expected
.
shape
,
computed
.
shape
)
assert
torch
.
allclose
(
expected
,
computed
,
**
kwargs_compare
)
assert
torch
.
allclose
(
expected
,
computed
,
atol
=
atol
,
rtol
=
rtol
)
class
TestFunctional
(
unittest
.
TestCase
):
class
TestFunctional
(
unittest
.
TestCase
):
...
...
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