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
25ceee71
Unverified
Commit
25ceee71
authored
Aug 03, 2021
by
moto
Committed by
GitHub
Aug 03, 2021
Browse files
Simplify extension initialization (#1649)
parent
ac1c9d5c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
torchaudio/extension/extension.py
torchaudio/extension/extension.py
+10
-7
No files found.
torchaudio/extension/extension.py
View file @
25ceee71
import
warnings
import
warnings
import
importlib
import
torch
import
torch
from
torchaudio._internal
import
module_utils
as
_mod_utils
from
torchaudio._internal
import
module_utils
as
_mod_utils
def
_init_extension
():
def
_init_extension
():
ext
=
'torchaudio._torchaudio'
if
_mod_utils
.
is_module_available
(
'torchaudio._torchaudio'
):
if
_mod_utils
.
is_module_available
(
ext
):
# Note this import has two purposes
_init_script_module
(
ext
)
# 1. to extract the path of the extension module so that
import
torchaudio._torchaudio
# noqa
# we can initialize the script module with the path.
# 2. so that torchaudio._torchaudio is accessible in other modules.
# Look at sox_io_backend which uses `torchaudio._torchaudio.XXX`,
# assuming that the module `_torchaudio` is accessible.
import
torchaudio._torchaudio
_init_script_module
(
torchaudio
.
_torchaudio
.
__file__
)
else
:
else
:
warnings
.
warn
(
'torchaudio C++ extension is not available.'
)
warnings
.
warn
(
'torchaudio C++ extension is not available.'
)
def
_init_script_module
(
module
):
def
_init_script_module
(
path
):
path
=
importlib
.
util
.
find_spec
(
module
).
origin
torch
.
classes
.
load_library
(
path
)
torch
.
classes
.
load_library
(
path
)
torch
.
ops
.
load_library
(
path
)
torch
.
ops
.
load_library
(
path
)
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