MCPcopy Create free account
hub / github.com/ElliotVincent/SitsSCD / forward

Method forward

models/networks/positional_encoding.py:16–31  ·  view source on GitHub ↗
(self, batch_positions)

Source from the content-addressed store, hash-verified

14 self.updated_location = False
15
16 def forward(self, batch_positions):
17 if not self.updated_location:
18 self.denom = self.denom.to(batch_positions.device)
19 self.updated_location = True
20 sinusoid_table = (
21 batch_positions[:, :, None] / self.denom[None, None, :]
22 ) # B x T x C
23 sinusoid_table[:, :, 0::2] = torch.sin(sinusoid_table[:, :, 0::2]) # dim 2i
24 sinusoid_table[:, :, 1::2] = torch.cos(sinusoid_table[:, :, 1::2]) # dim 2i+1
25
26 if self.repeat is not None:
27 sinusoid_table = torch.cat(
28 [sinusoid_table for _ in range(self.repeat)], dim=-1
29 )
30
31 return sinusoid_table

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected