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
torchani
Commits
2c0e6df5
Commit
2c0e6df5
authored
Nov 07, 2019
by
Gao, Xiang
Committed by
Farhad Ramezanghorbani
Nov 07, 2019
Browse files
Use modern type annotations for nn.py (#373)
* Use modern type annotations for nn.py * flake8
parent
3af8c49e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
7 deletions
+5
-7
torchani/nn.py
torchani/nn.py
+5
-7
No files found.
torchani/nn.py
View file @
2c0e6df5
import
torch
from
torch
import
Tensor
from
typing
import
Tuple
...
...
@@ -25,8 +26,7 @@ class ANIModel(torch.nn.Module):
def
__getitem__
(
self
,
i
):
return
self
.
module_list
[
i
]
def
forward
(
self
,
species_aev
):
# type: (Tuple[torch.Tensor, torch.Tensor]) -> Tuple[torch.Tensor, torch.Tensor]
def
forward
(
self
,
species_aev
:
Tuple
[
Tensor
,
Tensor
])
->
Tuple
[
Tensor
,
Tensor
]:
species
,
aev
=
species_aev
species_
=
species
.
flatten
()
aev
=
aev
.
flatten
(
0
,
1
)
...
...
@@ -51,8 +51,7 @@ class Ensemble(torch.nn.Module):
self
.
modules_list
=
torch
.
nn
.
ModuleList
(
modules
)
self
.
size
=
len
(
self
.
modules_list
)
def
forward
(
self
,
species_input
):
# type: (Tuple[torch.Tensor, torch.Tensor]) -> Tuple[torch.Tensor, torch.Tensor]
def
forward
(
self
,
species_input
:
Tuple
[
Tensor
,
Tensor
])
->
Tuple
[
Tensor
,
Tensor
]:
sum_
=
0
for
x
in
self
.
modules_list
:
sum_
+=
x
(
species_input
)[
1
]
...
...
@@ -70,8 +69,7 @@ class Sequential(torch.nn.Module):
super
(
Sequential
,
self
).
__init__
()
self
.
modules_list
=
torch
.
nn
.
ModuleList
(
modules
)
def
forward
(
self
,
input_
):
# type: (Tuple[torch.Tensor, torch.Tensor]) -> Tuple[torch.Tensor, torch.Tensor]
def
forward
(
self
,
input_
:
Tuple
[
Tensor
,
Tensor
])
->
Tuple
[
Tensor
,
Tensor
]:
for
module
in
self
.
modules_list
:
input_
=
module
(
input_
)
return
input_
...
...
@@ -79,5 +77,5 @@ class Sequential(torch.nn.Module):
class
Gaussian
(
torch
.
nn
.
Module
):
"""Gaussian activation"""
def
forward
(
self
,
x
)
:
def
forward
(
self
,
x
:
Tensor
)
->
Tensor
:
return
torch
.
exp
(
-
x
*
x
)
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