Skip to content

Commit

Permalink
Simplify code using torch.triu_indices (#367)
Browse files Browse the repository at this point in the history
* Simplify code using torch.triu_indices

* Update aev.py
  • Loading branch information
zasdfgbnm authored and farhadrgh committed Nov 7, 2019
1 parent 2ba9ae0 commit ae2497d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions torchani/aev.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ def neighbor_pairs(padding_mask, coordinates, cell, shifts, cutoff):

def triu_index(num_species):
# type: (int) -> torch.Tensor
species = torch.arange(num_species, dtype=torch.long)
species1, species2 = torch.combinations(species, r=2, with_replacement=True).unbind(-1)
species1, species2 = torch.triu_indices(num_species, num_species).unbind(0)
pair_index = torch.arange(species1.shape[0], dtype=torch.long)
ret = torch.zeros(num_species, num_species, dtype=torch.long)
ret[species1, species2] = pair_index
Expand Down

0 comments on commit ae2497d

Please sign in to comment.