Skip to content

Commit

Permalink
Use type inference of arange to clean up code (#357)
Browse files Browse the repository at this point in the history
* Use type inference of arange to clean up code

* commit
  • Loading branch information
zasdfgbnm authored and farhadrgh committed Nov 12, 2019
1 parent 1a2b450 commit c41581a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions torchani/aev.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def compute_shifts(cell: Tensor, pbc: Tensor, cutoff: float) -> Tensor:
inv_distances = reciprocal_cell.norm(2, -1)
num_repeats = torch.ceil(cutoff * inv_distances).to(torch.long)
num_repeats = torch.where(pbc, num_repeats, torch.zeros_like(num_repeats))
r1 = torch.arange(1, num_repeats[0] + 1, device=cell.device, dtype=torch.long)
r2 = torch.arange(1, num_repeats[1] + 1, device=cell.device, dtype=torch.long)
r3 = torch.arange(1, num_repeats[2] + 1, device=cell.device, dtype=torch.long)
r1 = torch.arange(1, num_repeats[0] + 1, device=cell.device)
r2 = torch.arange(1, num_repeats[1] + 1, device=cell.device)
r3 = torch.arange(1, num_repeats[2] + 1, device=cell.device)
o = torch.zeros(1, dtype=torch.long, device=cell.device)
return torch.cat([
torch.cartesian_prod(r1, r2, r3),
Expand Down Expand Up @@ -136,7 +136,7 @@ def neighbor_pairs(padding_mask: Tensor, coordinates: Tensor, cell: Tensor,
coordinates = coordinates.detach()
cell = cell.detach()
num_atoms = padding_mask.shape[1]
all_atoms = torch.arange(num_atoms, device=cell.device, dtype=torch.long)
all_atoms = torch.arange(num_atoms, device=cell.device)

# Step 2: center cell
p1_center, p2_center = torch.combinations(all_atoms).unbind(-1)
Expand All @@ -145,7 +145,7 @@ def neighbor_pairs(padding_mask: Tensor, coordinates: Tensor, cell: Tensor,
# Step 3: cells with shifts
# shape convention (shift index, molecule index, atom index, 3)
num_shifts = shifts.shape[0]
all_shifts = torch.arange(num_shifts, device=cell.device, dtype=torch.long)
all_shifts = torch.arange(num_shifts, device=cell.device)
shift_index, p1, p2 = torch.cartesian_prod(all_shifts, all_atoms, all_atoms).unbind(-1)
shifts_outide = shifts.index_select(0, shift_index)

Expand Down

0 comments on commit c41581a

Please sign in to comment.