Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nflib/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def forward(self, x):
z1 = torch.exp(s) * x1 + t # transform this half as a function of the other
if self.parity:
z0, z1 = z1, z0
z = torch.cat([z0, z1], dim=1)
z = torch.zeros((x.shape[0], self.dim))
z[:,::2] = z0
z[:,1::2] = z1
log_det = torch.sum(s, dim=1)
return z, log_det

Expand All @@ -128,7 +130,9 @@ def backward(self, z):
x1 = (z1 - t) * torch.exp(-s) # reverse the transform on this half
if self.parity:
x0, x1 = x1, x0
x = torch.cat([x0, x1], dim=1)
x = torch.zeros((z.shape[0], self.dim))
x[:,::2] = x0
x[:,1::2] = x1
log_det = torch.sum(-s, dim=1)
return x, log_det

Expand Down