From 10cda042b3209a3e66242ee3eab904e92c482f55 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 15:46:53 +0000 Subject: [PATCH 1/7] Initial move into nsflow. --- data/bsds300.py | 2 +- data/gas.py | 2 +- data/hepmass.py | 2 +- data/miniboone.py | 2 +- data/omniglot.py | 2 +- data/plane.py | 2 +- data/power.py | 2 +- {nde => nsflow}/__init__.py | 0 nsflow/nde/__init__.py | 0 {nde => nsflow/nde}/distributions/__init__.py | 0 {nde => nsflow/nde}/distributions/base.py | 2 +- {nde => nsflow/nde}/distributions/discrete.py | 4 ++-- {nde => nsflow/nde}/distributions/discrete_test.py | 0 {nde => nsflow/nde}/distributions/mixture.py | 0 {nde => nsflow/nde}/distributions/normal.py | 4 ++-- {nde => nsflow/nde}/distributions/normal_test.py | 0 {nde => nsflow/nde}/distributions/uniform.py | 0 {nde => nsflow/nde}/flows/__init__.py | 0 {nde => nsflow/nde}/flows/autoregressive.py | 6 +++--- {nde => nsflow/nde}/flows/autoregressive_test.py | 0 {nde => nsflow/nde}/flows/base.py | 4 ++-- {nde => nsflow/nde}/flows/base_test.py | 0 {nde => nsflow/nde}/flows/realnvp.py | 8 ++++---- {nde => nsflow/nde}/flows/realnvp_test.py | 0 {nde => nsflow/nde}/transforms/__init__.py | 0 {nde => nsflow/nde}/transforms/autoregressive.py | 8 ++++---- {nde => nsflow/nde}/transforms/autoregressive_test.py | 0 {nde => nsflow/nde}/transforms/base.py | 2 +- {nde => nsflow/nde}/transforms/base_test.py | 0 {nde => nsflow/nde}/transforms/conv.py | 5 +++-- {nde => nsflow/nde}/transforms/conv_test.py | 0 {nde => nsflow/nde}/transforms/coupling.py | 6 +++--- {nde => nsflow/nde}/transforms/coupling_test.py | 0 {nde => nsflow/nde}/transforms/linear.py | 4 ++-- {nde => nsflow/nde}/transforms/linear_test.py | 0 {nde => nsflow/nde}/transforms/lu.py | 4 ++-- {nde => nsflow/nde}/transforms/lu_test.py | 0 {nde => nsflow/nde}/transforms/made.py | 2 +- {nde => nsflow/nde}/transforms/made_test.py | 0 {nde => nsflow/nde}/transforms/nonlinearities.py | 6 +++--- {nde => nsflow/nde}/transforms/nonlinearities_test.py | 0 {nde => nsflow/nde}/transforms/normalization.py | 4 ++-- {nde => nsflow/nde}/transforms/normalization_test.py | 0 {nde => nsflow/nde}/transforms/orthogonal.py | 4 ++-- {nde => nsflow/nde}/transforms/orthogonal_test.py | 0 {nde => nsflow/nde}/transforms/permutations.py | 4 ++-- {nde => nsflow/nde}/transforms/permutations_test.py | 0 {nde => nsflow/nde}/transforms/qr.py | 4 ++-- {nde => nsflow/nde}/transforms/qr_test.py | 0 {nde => nsflow/nde}/transforms/reshape.py | 5 +++-- {nde => nsflow/nde}/transforms/reshape_test.py | 0 {nde => nsflow/nde}/transforms/splines/__init__.py | 0 {nde => nsflow/nde}/transforms/splines/cubic.py | 4 ++-- {nde => nsflow/nde}/transforms/splines/cubic_test.py | 0 {nde => nsflow/nde}/transforms/splines/linear.py | 4 ++-- {nde => nsflow/nde}/transforms/splines/linear_test.py | 0 {nde => nsflow/nde}/transforms/splines/quadratic.py | 4 ++-- {nde => nsflow/nde}/transforms/splines/quadratic_test.py | 0 .../nde}/transforms/splines/rational_quadratic.py | 4 ++-- .../nde}/transforms/splines/rational_quadratic_test.py | 0 {nde => nsflow/nde}/transforms/standard.py | 2 +- {nde => nsflow/nde}/transforms/standard_test.py | 0 {nde => nsflow/nde}/transforms/svd.py | 4 ++-- {nde => nsflow/nde}/transforms/svd_test.py | 0 {nde => nsflow/nde}/transforms/transform_test.py | 0 {nn => nsflow/nn}/__init__.py | 0 {nn => nsflow/nn}/attention.py | 4 ++-- {nn => nsflow/nn}/conv.py | 0 {nn => nsflow/nn}/mlp.py | 0 {nn => nsflow/nn}/mlp_test.py | 0 {nn => nsflow/nn}/resnet.py | 2 +- {nn => nsflow/nn}/unet.py | 2 +- {optim => nsflow/optim}/__init__.py | 0 {optim => nsflow/optim}/custom_lr_schedulers.py | 0 {utils => nsflow/utils}/__init__.py | 0 {utils => nsflow/utils}/io.py | 0 {utils => nsflow/utils}/torchutils.py | 2 +- {utils => nsflow/utils}/torchutils_test.py | 0 {utils => nsflow/utils}/typechecks.py | 0 {vae => nsflow/vae}/__init__.py | 0 {vae => nsflow/vae}/base.py | 2 +- {vae => nsflow/vae}/base_test.py | 0 setup.py | 7 +++++++ 83 files changed, 75 insertions(+), 66 deletions(-) rename {nde => nsflow}/__init__.py (100%) create mode 100644 nsflow/nde/__init__.py rename {nde => nsflow/nde}/distributions/__init__.py (100%) rename {nde => nsflow/nde}/distributions/base.py (99%) rename {nde => nsflow/nde}/distributions/discrete.py (97%) rename {nde => nsflow/nde}/distributions/discrete_test.py (100%) rename {nde => nsflow/nde}/distributions/mixture.py (100%) rename {nde => nsflow/nde}/distributions/normal.py (98%) rename {nde => nsflow/nde}/distributions/normal_test.py (100%) rename {nde => nsflow/nde}/distributions/uniform.py (100%) rename {nde => nsflow/nde}/flows/__init__.py (100%) rename {nde => nsflow/nde}/flows/autoregressive.py (95%) rename {nde => nsflow/nde}/flows/autoregressive_test.py (100%) rename {nde => nsflow/nde}/flows/base.py (97%) rename {nde => nsflow/nde}/flows/base_test.py (100%) rename {nde => nsflow/nde}/flows/realnvp.py (93%) rename {nde => nsflow/nde}/flows/realnvp_test.py (100%) rename {nde => nsflow/nde}/transforms/__init__.py (100%) rename {nde => nsflow/nde}/transforms/autoregressive.py (99%) rename {nde => nsflow/nde}/transforms/autoregressive_test.py (100%) rename {nde => nsflow/nde}/transforms/base.py (99%) rename {nde => nsflow/nde}/transforms/base_test.py (100%) rename {nde => nsflow/nde}/transforms/conv.py (96%) rename {nde => nsflow/nde}/transforms/conv_test.py (100%) rename {nde => nsflow/nde}/transforms/coupling.py (99%) rename {nde => nsflow/nde}/transforms/coupling_test.py (100%) rename {nde => nsflow/nde}/transforms/linear.py (99%) rename {nde => nsflow/nde}/transforms/linear_test.py (100%) rename {nde => nsflow/nde}/transforms/lu.py (97%) rename {nde => nsflow/nde}/transforms/lu_test.py (100%) rename {nde => nsflow/nde}/transforms/made.py (99%) rename {nde => nsflow/nde}/transforms/made_test.py (100%) rename {nde => nsflow/nde}/transforms/nonlinearities.py (99%) rename {nde => nsflow/nde}/transforms/nonlinearities_test.py (100%) rename {nde => nsflow/nde}/transforms/normalization.py (99%) rename {nde => nsflow/nde}/transforms/normalization_test.py (100%) rename {nde => nsflow/nde}/transforms/orthogonal.py (98%) rename {nde => nsflow/nde}/transforms/orthogonal_test.py (100%) rename {nde => nsflow/nde}/transforms/permutations.py (97%) rename {nde => nsflow/nde}/transforms/permutations_test.py (100%) rename {nde => nsflow/nde}/transforms/qr.py (97%) rename {nde => nsflow/nde}/transforms/qr_test.py (100%) rename {nde => nsflow/nde}/transforms/reshape.py (98%) rename {nde => nsflow/nde}/transforms/reshape_test.py (100%) rename {nde => nsflow/nde}/transforms/splines/__init__.py (100%) rename {nde => nsflow/nde}/transforms/splines/cubic.py (99%) rename {nde => nsflow/nde}/transforms/splines/cubic_test.py (100%) rename {nde => nsflow/nde}/transforms/splines/linear.py (98%) rename {nde => nsflow/nde}/transforms/splines/linear_test.py (100%) rename {nde => nsflow/nde}/transforms/splines/quadratic.py (98%) rename {nde => nsflow/nde}/transforms/splines/quadratic_test.py (100%) rename {nde => nsflow/nde}/transforms/splines/rational_quadratic.py (99%) rename {nde => nsflow/nde}/transforms/splines/rational_quadratic_test.py (100%) rename {nde => nsflow/nde}/transforms/standard.py (98%) rename {nde => nsflow/nde}/transforms/standard_test.py (100%) rename {nde => nsflow/nde}/transforms/svd.py (97%) rename {nde => nsflow/nde}/transforms/svd_test.py (100%) rename {nde => nsflow/nde}/transforms/transform_test.py (100%) rename {nn => nsflow/nn}/__init__.py (100%) rename {nn => nsflow/nn}/attention.py (99%) rename {nn => nsflow/nn}/conv.py (100%) rename {nn => nsflow/nn}/mlp.py (100%) rename {nn => nsflow/nn}/mlp_test.py (100%) rename {nn => nsflow/nn}/resnet.py (99%) rename {nn => nsflow/nn}/unet.py (98%) rename {optim => nsflow/optim}/__init__.py (100%) rename {optim => nsflow/optim}/custom_lr_schedulers.py (100%) rename {utils => nsflow/utils}/__init__.py (100%) rename {utils => nsflow/utils}/io.py (100%) rename {utils => nsflow/utils}/torchutils.py (99%) rename {utils => nsflow/utils}/torchutils_test.py (100%) rename {utils => nsflow/utils}/typechecks.py (100%) rename {vae => nsflow/vae}/__init__.py (100%) rename {vae => nsflow/vae}/base.py (99%) rename {vae => nsflow/vae}/base_test.py (100%) create mode 100644 setup.py diff --git a/data/bsds300.py b/data/bsds300.py index f019f8a..70c216e 100644 --- a/data/bsds300.py +++ b/data/bsds300.py @@ -1,7 +1,7 @@ import h5py import numpy as np import os -import utils +from nsflow import utils from matplotlib import pyplot as plt from torch.utils import data diff --git a/data/gas.py b/data/gas.py index 07690cf..5083475 100644 --- a/data/gas.py +++ b/data/gas.py @@ -1,7 +1,7 @@ import numpy as np import os import pandas as pd -import utils +from nsflow import utils from matplotlib import pyplot as plt from torch.utils.data import Dataset diff --git a/data/hepmass.py b/data/hepmass.py index 736ec11..8226d86 100644 --- a/data/hepmass.py +++ b/data/hepmass.py @@ -1,7 +1,7 @@ import numpy as np import os import pandas as pd -import utils +from nsflow import utils from collections import Counter from matplotlib import pyplot as plt diff --git a/data/miniboone.py b/data/miniboone.py index 8096726..8ec99df 100644 --- a/data/miniboone.py +++ b/data/miniboone.py @@ -1,6 +1,6 @@ import numpy as np import os -import utils +from nsflow import utils from matplotlib import pyplot as plt from torch.utils.data import Dataset diff --git a/data/omniglot.py b/data/omniglot.py index eb02fbf..92e3f29 100644 --- a/data/omniglot.py +++ b/data/omniglot.py @@ -2,7 +2,7 @@ import os import torch -import utils +from nsflow import utils from PIL import Image from scipy.io import loadmat diff --git a/data/plane.py b/data/plane.py index c06e6d3..51b936c 100644 --- a/data/plane.py +++ b/data/plane.py @@ -8,7 +8,7 @@ from torch import distributions from torch.utils.data import Dataset -import utils +from nsflow import utils class PlaneDataset(Dataset): diff --git a/data/power.py b/data/power.py index 9dec6b2..c1a3425 100644 --- a/data/power.py +++ b/data/power.py @@ -1,6 +1,6 @@ import numpy as np import os -import utils +from nsflow import utils from matplotlib import pyplot as plt from torch.utils.data import Dataset diff --git a/nde/__init__.py b/nsflow/__init__.py similarity index 100% rename from nde/__init__.py rename to nsflow/__init__.py diff --git a/nsflow/nde/__init__.py b/nsflow/nde/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nde/distributions/__init__.py b/nsflow/nde/distributions/__init__.py similarity index 100% rename from nde/distributions/__init__.py rename to nsflow/nde/distributions/__init__.py diff --git a/nde/distributions/base.py b/nsflow/nde/distributions/base.py similarity index 99% rename from nde/distributions/base.py rename to nsflow/nde/distributions/base.py index 7b60686..8ce6ff6 100644 --- a/nde/distributions/base.py +++ b/nsflow/nde/distributions/base.py @@ -4,7 +4,7 @@ from torch import nn -import utils +from nsflow import utils class NoMeanException(Exception): diff --git a/nde/distributions/discrete.py b/nsflow/nde/distributions/discrete.py similarity index 97% rename from nde/distributions/discrete.py rename to nsflow/nde/distributions/discrete.py index ea853db..98d13d2 100644 --- a/nde/distributions/discrete.py +++ b/nsflow/nde/distributions/discrete.py @@ -4,9 +4,9 @@ from torch.nn import functional as F -import utils +from nsflow import utils -from nde import distributions +from nsflow.nde import distributions class ConditionalIndependentBernoulli(distributions.Distribution): diff --git a/nde/distributions/discrete_test.py b/nsflow/nde/distributions/discrete_test.py similarity index 100% rename from nde/distributions/discrete_test.py rename to nsflow/nde/distributions/discrete_test.py diff --git a/nde/distributions/mixture.py b/nsflow/nde/distributions/mixture.py similarity index 100% rename from nde/distributions/mixture.py rename to nsflow/nde/distributions/mixture.py diff --git a/nde/distributions/normal.py b/nsflow/nde/distributions/normal.py similarity index 98% rename from nde/distributions/normal.py rename to nsflow/nde/distributions/normal.py index 04069fb..b309d1d 100644 --- a/nde/distributions/normal.py +++ b/nsflow/nde/distributions/normal.py @@ -3,9 +3,9 @@ import numpy as np import torch -import utils +from nsflow import utils -from nde import distributions +from nsflow.nde import distributions class StandardNormal(distributions.Distribution): diff --git a/nde/distributions/normal_test.py b/nsflow/nde/distributions/normal_test.py similarity index 100% rename from nde/distributions/normal_test.py rename to nsflow/nde/distributions/normal_test.py diff --git a/nde/distributions/uniform.py b/nsflow/nde/distributions/uniform.py similarity index 100% rename from nde/distributions/uniform.py rename to nsflow/nde/distributions/uniform.py diff --git a/nde/flows/__init__.py b/nsflow/nde/flows/__init__.py similarity index 100% rename from nde/flows/__init__.py rename to nsflow/nde/flows/__init__.py diff --git a/nde/flows/autoregressive.py b/nsflow/nde/flows/autoregressive.py similarity index 95% rename from nde/flows/autoregressive.py rename to nsflow/nde/flows/autoregressive.py index 69e4092..2fddffa 100644 --- a/nde/flows/autoregressive.py +++ b/nsflow/nde/flows/autoregressive.py @@ -2,9 +2,9 @@ from torch.nn import functional as F -from nde import distributions -from nde import flows -from nde import transforms +from nsflow.nde import distributions +from nsflow.nde import flows +from nsflow.nde import transforms class MaskedAutoregressiveFlow(flows.Flow): diff --git a/nde/flows/autoregressive_test.py b/nsflow/nde/flows/autoregressive_test.py similarity index 100% rename from nde/flows/autoregressive_test.py rename to nsflow/nde/flows/autoregressive_test.py diff --git a/nde/flows/base.py b/nsflow/nde/flows/base.py similarity index 97% rename from nde/flows/base.py rename to nsflow/nde/flows/base.py index 1fbcc54..0f0b1f0 100644 --- a/nde/flows/base.py +++ b/nsflow/nde/flows/base.py @@ -1,8 +1,8 @@ """Basic definitions for the flows module.""" -import utils +from nsflow import utils -from nde import distributions +from nsflow.nde import distributions class Flow(distributions.Distribution): diff --git a/nde/flows/base_test.py b/nsflow/nde/flows/base_test.py similarity index 100% rename from nde/flows/base_test.py rename to nsflow/nde/flows/base_test.py diff --git a/nde/flows/realnvp.py b/nsflow/nde/flows/realnvp.py similarity index 93% rename from nde/flows/realnvp.py rename to nsflow/nde/flows/realnvp.py index 85920f4..77655ca 100644 --- a/nde/flows/realnvp.py +++ b/nsflow/nde/flows/realnvp.py @@ -3,10 +3,10 @@ import torch from torch.nn import functional as F -from nde import distributions -from nde import flows -from nde import transforms -import nn as nn_ +from nsflow.nde import distributions +from nsflow.nde import flows +from nsflow.nde import transforms +from nsflow import nn as nn_ class SimpleRealNVP(flows.Flow): diff --git a/nde/flows/realnvp_test.py b/nsflow/nde/flows/realnvp_test.py similarity index 100% rename from nde/flows/realnvp_test.py rename to nsflow/nde/flows/realnvp_test.py diff --git a/nde/transforms/__init__.py b/nsflow/nde/transforms/__init__.py similarity index 100% rename from nde/transforms/__init__.py rename to nsflow/nde/transforms/__init__.py diff --git a/nde/transforms/autoregressive.py b/nsflow/nde/transforms/autoregressive.py similarity index 99% rename from nde/transforms/autoregressive.py rename to nsflow/nde/transforms/autoregressive.py index 275e4c8..36fed52 100644 --- a/nde/transforms/autoregressive.py +++ b/nsflow/nde/transforms/autoregressive.py @@ -4,10 +4,10 @@ import torch from torch.nn import functional as F -import utils -from nde import transforms -from nde.transforms import made as made_module -from nde.transforms import splines +from nsflow import utils +from nsflow.nde import transforms +from nsflow.nde.transforms import made as made_module +from nsflow.nde.transforms import splines class AutoregressiveTransform(transforms.Transform): """Transforms each input variable with an invertible elementwise transformation. diff --git a/nde/transforms/autoregressive_test.py b/nsflow/nde/transforms/autoregressive_test.py similarity index 100% rename from nde/transforms/autoregressive_test.py rename to nsflow/nde/transforms/autoregressive_test.py diff --git a/nde/transforms/base.py b/nsflow/nde/transforms/base.py similarity index 99% rename from nde/transforms/base.py rename to nsflow/nde/transforms/base.py index 457c66d..d742f6f 100644 --- a/nde/transforms/base.py +++ b/nsflow/nde/transforms/base.py @@ -5,7 +5,7 @@ from torch import nn -import utils +from nsflow import utils class InverseNotAvailable(Exception): diff --git a/nde/transforms/base_test.py b/nsflow/nde/transforms/base_test.py similarity index 100% rename from nde/transforms/base_test.py rename to nsflow/nde/transforms/base_test.py diff --git a/nde/transforms/conv.py b/nsflow/nde/transforms/conv.py similarity index 96% rename from nde/transforms/conv.py rename to nsflow/nde/transforms/conv.py index 7f6a18a..3ac6271 100644 --- a/nde/transforms/conv.py +++ b/nsflow/nde/transforms/conv.py @@ -1,5 +1,6 @@ -import utils -from nde import transforms +from nsflow import utils + +from nsflow.nde import transforms class OneByOneConvolution(transforms.LULinear): diff --git a/nde/transforms/conv_test.py b/nsflow/nde/transforms/conv_test.py similarity index 100% rename from nde/transforms/conv_test.py rename to nsflow/nde/transforms/conv_test.py diff --git a/nde/transforms/coupling.py b/nsflow/nde/transforms/coupling.py similarity index 99% rename from nde/transforms/coupling.py rename to nsflow/nde/transforms/coupling.py index adae5ad..532b8cc 100644 --- a/nde/transforms/coupling.py +++ b/nsflow/nde/transforms/coupling.py @@ -5,10 +5,10 @@ import torch from torch.nn import functional as F -import utils +from nsflow import utils -from nde import transforms -from nde.transforms import splines +from nsflow.nde import transforms +from nsflow.nde.transforms import splines class CouplingTransform(transforms.Transform): diff --git a/nde/transforms/coupling_test.py b/nsflow/nde/transforms/coupling_test.py similarity index 100% rename from nde/transforms/coupling_test.py rename to nsflow/nde/transforms/coupling_test.py diff --git a/nde/transforms/linear.py b/nsflow/nde/transforms/linear.py similarity index 99% rename from nde/transforms/linear.py rename to nsflow/nde/transforms/linear.py index 61e3fb5..24ac340 100644 --- a/nde/transforms/linear.py +++ b/nsflow/nde/transforms/linear.py @@ -6,9 +6,9 @@ from torch import nn from torch.nn import functional as F, init -import utils +from nsflow import utils -from nde import transforms +from nsflow.nde import transforms class LinearCache(object): diff --git a/nde/transforms/linear_test.py b/nsflow/nde/transforms/linear_test.py similarity index 100% rename from nde/transforms/linear_test.py rename to nsflow/nde/transforms/linear_test.py diff --git a/nde/transforms/lu.py b/nsflow/nde/transforms/lu.py similarity index 97% rename from nde/transforms/lu.py rename to nsflow/nde/transforms/lu.py index 5537203..44881cb 100644 --- a/nde/transforms/lu.py +++ b/nsflow/nde/transforms/lu.py @@ -4,7 +4,7 @@ from torch import nn from torch.nn import functional as F, init -from nde.transforms.linear import Linear +from nsflow.nde.transforms.linear import Linear class LULinear(Linear): @@ -117,4 +117,4 @@ def logabsdet(self): where: D = num of features """ - return torch.sum(torch.log(self.upper_diag)) \ No newline at end of file + return torch.sum(torch.log(self.upper_diag)) diff --git a/nde/transforms/lu_test.py b/nsflow/nde/transforms/lu_test.py similarity index 100% rename from nde/transforms/lu_test.py rename to nsflow/nde/transforms/lu_test.py diff --git a/nde/transforms/made.py b/nsflow/nde/transforms/made.py similarity index 99% rename from nde/transforms/made.py rename to nsflow/nde/transforms/made.py index 7026fc1..b5a4e29 100644 --- a/nde/transforms/made.py +++ b/nsflow/nde/transforms/made.py @@ -3,7 +3,7 @@ import torch -import utils +from nsflow import utils from torch import nn from torch.nn import functional as F, init diff --git a/nde/transforms/made_test.py b/nsflow/nde/transforms/made_test.py similarity index 100% rename from nde/transforms/made_test.py rename to nsflow/nde/transforms/made_test.py diff --git a/nde/transforms/nonlinearities.py b/nsflow/nde/transforms/nonlinearities.py similarity index 99% rename from nde/transforms/nonlinearities.py rename to nsflow/nde/transforms/nonlinearities.py index 8e61ad5..90fb357 100644 --- a/nde/transforms/nonlinearities.py +++ b/nsflow/nde/transforms/nonlinearities.py @@ -6,10 +6,10 @@ from torch import nn from torch.nn import functional as F -import utils +from nsflow import utils -from nde import transforms -from nde.transforms import splines +from nsflow.nde import transforms +from nsflow.nde.transforms import splines class Tanh(transforms.Transform): def forward(self, inputs, context=None): diff --git a/nde/transforms/nonlinearities_test.py b/nsflow/nde/transforms/nonlinearities_test.py similarity index 100% rename from nde/transforms/nonlinearities_test.py rename to nsflow/nde/transforms/nonlinearities_test.py diff --git a/nde/transforms/normalization.py b/nsflow/nde/transforms/normalization.py similarity index 99% rename from nde/transforms/normalization.py rename to nsflow/nde/transforms/normalization.py index efd0ec8..8723f06 100644 --- a/nde/transforms/normalization.py +++ b/nsflow/nde/transforms/normalization.py @@ -5,9 +5,9 @@ from torch import nn from torch.nn import functional as F -import utils +from nsflow import utils -from nde import transforms +from nsflow.nde import transforms # class BatchNorm(transforms.Transform): diff --git a/nde/transforms/normalization_test.py b/nsflow/nde/transforms/normalization_test.py similarity index 100% rename from nde/transforms/normalization_test.py rename to nsflow/nde/transforms/normalization_test.py diff --git a/nde/transforms/orthogonal.py b/nsflow/nde/transforms/orthogonal.py similarity index 98% rename from nde/transforms/orthogonal.py rename to nsflow/nde/transforms/orthogonal.py index 922394d..b66669c 100644 --- a/nde/transforms/orthogonal.py +++ b/nsflow/nde/transforms/orthogonal.py @@ -4,9 +4,9 @@ from torch import nn -import utils +from nsflow import utils -from nde import transforms +from nsflow.nde import transforms class HouseholderSequence(transforms.Transform): diff --git a/nde/transforms/orthogonal_test.py b/nsflow/nde/transforms/orthogonal_test.py similarity index 100% rename from nde/transforms/orthogonal_test.py rename to nsflow/nde/transforms/orthogonal_test.py diff --git a/nde/transforms/permutations.py b/nsflow/nde/transforms/permutations.py similarity index 97% rename from nde/transforms/permutations.py rename to nsflow/nde/transforms/permutations.py index 8f04289..5ff9d34 100644 --- a/nde/transforms/permutations.py +++ b/nsflow/nde/transforms/permutations.py @@ -1,9 +1,9 @@ """Implementations of permutation-like transforms.""" import torch -import utils +from nsflow import utils -from nde import transforms +from nsflow.nde import transforms class Permutation(transforms.Transform): diff --git a/nde/transforms/permutations_test.py b/nsflow/nde/transforms/permutations_test.py similarity index 100% rename from nde/transforms/permutations_test.py rename to nsflow/nde/transforms/permutations_test.py diff --git a/nde/transforms/qr.py b/nsflow/nde/transforms/qr.py similarity index 97% rename from nde/transforms/qr.py rename to nsflow/nde/transforms/qr.py index 935e1af..82a3bbf 100644 --- a/nde/transforms/qr.py +++ b/nsflow/nde/transforms/qr.py @@ -4,8 +4,8 @@ from torch import nn from torch.nn import functional as F, init -from nde import transforms -from nde.transforms.linear import Linear +from nsflow.nde import transforms +from nsflow.nde.transforms.linear import Linear class QRLinear(Linear): diff --git a/nde/transforms/qr_test.py b/nsflow/nde/transforms/qr_test.py similarity index 100% rename from nde/transforms/qr_test.py rename to nsflow/nde/transforms/qr_test.py diff --git a/nde/transforms/reshape.py b/nsflow/nde/transforms/reshape.py similarity index 98% rename from nde/transforms/reshape.py rename to nsflow/nde/transforms/reshape.py index 0b42289..9c31c5a 100644 --- a/nde/transforms/reshape.py +++ b/nsflow/nde/transforms/reshape.py @@ -1,7 +1,8 @@ import torch -import utils -from nde import transforms +from nsflow import utils + +from nsflow.nde import transforms class SqueezeTransform(transforms.Transform): diff --git a/nde/transforms/reshape_test.py b/nsflow/nde/transforms/reshape_test.py similarity index 100% rename from nde/transforms/reshape_test.py rename to nsflow/nde/transforms/reshape_test.py diff --git a/nde/transforms/splines/__init__.py b/nsflow/nde/transforms/splines/__init__.py similarity index 100% rename from nde/transforms/splines/__init__.py rename to nsflow/nde/transforms/splines/__init__.py diff --git a/nde/transforms/splines/cubic.py b/nsflow/nde/transforms/splines/cubic.py similarity index 99% rename from nde/transforms/splines/cubic.py rename to nsflow/nde/transforms/splines/cubic.py index 3afb077..45803d2 100644 --- a/nde/transforms/splines/cubic.py +++ b/nsflow/nde/transforms/splines/cubic.py @@ -3,8 +3,8 @@ import torch from torch.nn import functional as F -import utils -from nde import transforms +from nsflow import utils +from nsflow.nde import transforms DEFAULT_MIN_BIN_WIDTH = 1e-3 DEFAULT_MIN_BIN_HEIGHT = 1e-3 diff --git a/nde/transforms/splines/cubic_test.py b/nsflow/nde/transforms/splines/cubic_test.py similarity index 100% rename from nde/transforms/splines/cubic_test.py rename to nsflow/nde/transforms/splines/cubic_test.py diff --git a/nde/transforms/splines/linear.py b/nsflow/nde/transforms/splines/linear.py similarity index 98% rename from nde/transforms/splines/linear.py rename to nsflow/nde/transforms/splines/linear.py index 3b5fee0..4eec259 100644 --- a/nde/transforms/splines/linear.py +++ b/nsflow/nde/transforms/splines/linear.py @@ -4,8 +4,8 @@ from torch.nn import functional as F import numpy as np -import utils -from nde import transforms +from nsflow import utils +from nsflow.nde import transforms def unconstrained_linear_spline(inputs, unnormalized_pdf, inverse=False, diff --git a/nde/transforms/splines/linear_test.py b/nsflow/nde/transforms/splines/linear_test.py similarity index 100% rename from nde/transforms/splines/linear_test.py rename to nsflow/nde/transforms/splines/linear_test.py diff --git a/nde/transforms/splines/quadratic.py b/nsflow/nde/transforms/splines/quadratic.py similarity index 98% rename from nde/transforms/splines/quadratic.py rename to nsflow/nde/transforms/splines/quadratic.py index 2bee354..0e5d9f5 100644 --- a/nde/transforms/splines/quadratic.py +++ b/nsflow/nde/transforms/splines/quadratic.py @@ -3,8 +3,8 @@ import torch from torch.nn import functional as F -import utils -from nde import transforms +from nsflow import utils +from nsflow.nde import transforms DEFAULT_MIN_BIN_WIDTH = 1e-3 DEFAULT_MIN_BIN_HEIGHT = 1e-3 diff --git a/nde/transforms/splines/quadratic_test.py b/nsflow/nde/transforms/splines/quadratic_test.py similarity index 100% rename from nde/transforms/splines/quadratic_test.py rename to nsflow/nde/transforms/splines/quadratic_test.py diff --git a/nde/transforms/splines/rational_quadratic.py b/nsflow/nde/transforms/splines/rational_quadratic.py similarity index 99% rename from nde/transforms/splines/rational_quadratic.py rename to nsflow/nde/transforms/splines/rational_quadratic.py index e98d0fd..978130d 100644 --- a/nde/transforms/splines/rational_quadratic.py +++ b/nsflow/nde/transforms/splines/rational_quadratic.py @@ -1,10 +1,10 @@ import torch from torch.nn import functional as F -import utils +from nsflow import utils import numpy as np -from nde import transforms +from nsflow.nde import transforms DEFAULT_MIN_BIN_WIDTH = 1e-3 DEFAULT_MIN_BIN_HEIGHT = 1e-3 diff --git a/nde/transforms/splines/rational_quadratic_test.py b/nsflow/nde/transforms/splines/rational_quadratic_test.py similarity index 100% rename from nde/transforms/splines/rational_quadratic_test.py rename to nsflow/nde/transforms/splines/rational_quadratic_test.py diff --git a/nde/transforms/standard.py b/nsflow/nde/transforms/standard.py similarity index 98% rename from nde/transforms/standard.py rename to nsflow/nde/transforms/standard.py index 121233a..624a642 100644 --- a/nde/transforms/standard.py +++ b/nsflow/nde/transforms/standard.py @@ -1,7 +1,7 @@ """Implementations of some standard transforms.""" import torch -from nde import transforms +from nsflow.nde import transforms class IdentityTransform(transforms.Transform): diff --git a/nde/transforms/standard_test.py b/nsflow/nde/transforms/standard_test.py similarity index 100% rename from nde/transforms/standard_test.py rename to nsflow/nde/transforms/standard_test.py diff --git a/nde/transforms/svd.py b/nsflow/nde/transforms/svd.py similarity index 97% rename from nde/transforms/svd.py rename to nsflow/nde/transforms/svd.py index cd07fa0..79760fe 100644 --- a/nde/transforms/svd.py +++ b/nsflow/nde/transforms/svd.py @@ -4,8 +4,8 @@ from torch import nn from torch.nn import init -from nde import transforms -from nde.transforms.linear import Linear +from nsflow.nde import transforms +from nsflow.nde.transforms.linear import Linear class SVDLinear(Linear): diff --git a/nde/transforms/svd_test.py b/nsflow/nde/transforms/svd_test.py similarity index 100% rename from nde/transforms/svd_test.py rename to nsflow/nde/transforms/svd_test.py diff --git a/nde/transforms/transform_test.py b/nsflow/nde/transforms/transform_test.py similarity index 100% rename from nde/transforms/transform_test.py rename to nsflow/nde/transforms/transform_test.py diff --git a/nn/__init__.py b/nsflow/nn/__init__.py similarity index 100% rename from nn/__init__.py rename to nsflow/nn/__init__.py diff --git a/nn/attention.py b/nsflow/nn/attention.py similarity index 99% rename from nn/attention.py rename to nsflow/nn/attention.py index 65eeb64..ed6062e 100644 --- a/nn/attention.py +++ b/nsflow/nn/attention.py @@ -3,7 +3,7 @@ from torch import nn from torch.nn import functional as F -import utils +from nsflow import utils # # Projection of x onto y @@ -217,4 +217,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/nn/conv.py b/nsflow/nn/conv.py similarity index 100% rename from nn/conv.py rename to nsflow/nn/conv.py diff --git a/nn/mlp.py b/nsflow/nn/mlp.py similarity index 100% rename from nn/mlp.py rename to nsflow/nn/mlp.py diff --git a/nn/mlp_test.py b/nsflow/nn/mlp_test.py similarity index 100% rename from nn/mlp_test.py rename to nsflow/nn/mlp_test.py diff --git a/nn/resnet.py b/nsflow/nn/resnet.py similarity index 99% rename from nn/resnet.py rename to nsflow/nn/resnet.py index 6c04899..823981a 100644 --- a/nn/resnet.py +++ b/nsflow/nn/resnet.py @@ -3,7 +3,7 @@ from torch import nn from torch.nn import functional as F, init -import utils +from nsflow import utils class ResidualBlock(nn.Module): diff --git a/nn/unet.py b/nsflow/nn/unet.py similarity index 98% rename from nn/unet.py rename to nsflow/nn/unet.py index 4bfabf8..dcf860e 100644 --- a/nn/unet.py +++ b/nsflow/nn/unet.py @@ -3,7 +3,7 @@ from torch import nn from torch.nn import functional as F -import utils +from nsflow import utils class UNet(nn.Module): diff --git a/optim/__init__.py b/nsflow/optim/__init__.py similarity index 100% rename from optim/__init__.py rename to nsflow/optim/__init__.py diff --git a/optim/custom_lr_schedulers.py b/nsflow/optim/custom_lr_schedulers.py similarity index 100% rename from optim/custom_lr_schedulers.py rename to nsflow/optim/custom_lr_schedulers.py diff --git a/utils/__init__.py b/nsflow/utils/__init__.py similarity index 100% rename from utils/__init__.py rename to nsflow/utils/__init__.py diff --git a/utils/io.py b/nsflow/utils/io.py similarity index 100% rename from utils/io.py rename to nsflow/utils/io.py diff --git a/utils/torchutils.py b/nsflow/utils/torchutils.py similarity index 99% rename from utils/torchutils.py rename to nsflow/utils/torchutils.py index 39b08f6..3550d0b 100644 --- a/utils/torchutils.py +++ b/nsflow/utils/torchutils.py @@ -2,7 +2,7 @@ import torch -import utils +from nsflow import utils def tile(x, n): diff --git a/utils/torchutils_test.py b/nsflow/utils/torchutils_test.py similarity index 100% rename from utils/torchutils_test.py rename to nsflow/utils/torchutils_test.py diff --git a/utils/typechecks.py b/nsflow/utils/typechecks.py similarity index 100% rename from utils/typechecks.py rename to nsflow/utils/typechecks.py diff --git a/vae/__init__.py b/nsflow/vae/__init__.py similarity index 100% rename from vae/__init__.py rename to nsflow/vae/__init__.py diff --git a/vae/base.py b/nsflow/vae/base.py similarity index 99% rename from vae/base.py rename to nsflow/vae/base.py index 931e339..1bc6b54 100644 --- a/vae/base.py +++ b/nsflow/vae/base.py @@ -4,7 +4,7 @@ from torch import nn -import utils +from nsflow import utils class VariationalAutoencoder(nn.Module): diff --git a/vae/base_test.py b/nsflow/vae/base_test.py similarity index 100% rename from vae/base_test.py rename to nsflow/vae/base_test.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2698117 --- /dev/null +++ b/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup, find_packages + +setup( + name='nsflow', + version='0.1.0', + packages=find_packages(exclude=['data']) +) From 92853dc186b7271d34fce4cf7234aff936af8970 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 17:18:47 +0000 Subject: [PATCH 2/7] Test refactoring. --- nsflow/nde/distributions/tests/__init__.py | 0 .../{discrete_test.py => tests/test_discrete.py} | 2 +- .../{normal_test.py => tests/test_normal.py} | 2 +- nsflow/nde/flows/tests/__init__.py | 0 .../test_autoregressive.py} | 2 +- nsflow/nde/flows/{base_test.py => tests/test_base.py} | 6 +++--- .../nde/flows/{realnvp_test.py => tests/test_realnvp.py} | 2 +- nsflow/nde/transforms/tests/__init__.py | 0 .../test_autoregressive.py} | 4 ++-- .../nde/transforms/{base_test.py => tests/test_base.py} | 6 +++--- .../nde/transforms/{conv_test.py => tests/test_conv.py} | 4 ++-- .../{coupling_test.py => tests/test_coupling.py} | 8 ++++---- .../transforms/{linear_test.py => tests/test_linear.py} | 8 ++++---- nsflow/nde/transforms/{lu_test.py => tests/test_lu.py} | 6 +++--- .../nde/transforms/{made_test.py => tests/test_made.py} | 2 +- .../test_nonlinearities.py} | 5 ++--- .../test_normalization.py} | 6 +++--- .../{orthogonal_test.py => tests/test_orthogonal.py} | 6 +++--- .../{permutations_test.py => tests/test_permutations.py} | 4 ++-- nsflow/nde/transforms/{qr_test.py => tests/test_qr.py} | 6 +++--- .../transforms/{reshape_test.py => tests/test_reshape.py} | 4 ++-- .../{standard_test.py => tests/test_standard.py} | 4 ++-- nsflow/nde/transforms/{svd_test.py => tests/test_svd.py} | 6 +++--- .../{transform_test.py => tests/test_transform.py} | 2 +- nsflow/nn/tests/__init__.py | 0 nsflow/nn/{mlp_test.py => tests/test_mlp.py} | 2 +- nsflow/utils/tests/__init__.py | 0 .../{torchutils_test.py => tests/test_torchutils.py} | 2 +- nsflow/vae/tests/__init__.py | 0 nsflow/vae/{base_test.py => tests/test_base.py} | 4 ++-- 30 files changed, 51 insertions(+), 52 deletions(-) create mode 100644 nsflow/nde/distributions/tests/__init__.py rename nsflow/nde/distributions/{discrete_test.py => tests/test_discrete.py} (98%) rename nsflow/nde/distributions/{normal_test.py => tests/test_normal.py} (99%) create mode 100644 nsflow/nde/flows/tests/__init__.py rename nsflow/nde/flows/{autoregressive_test.py => tests/test_autoregressive.py} (95%) rename nsflow/nde/flows/{base_test.py => tests/test_base.py} (97%) rename nsflow/nde/flows/{realnvp_test.py => tests/test_realnvp.py} (96%) create mode 100644 nsflow/nde/transforms/tests/__init__.py rename nsflow/nde/transforms/{autoregressive_test.py => tests/test_autoregressive.py} (97%) rename nsflow/nde/transforms/{base_test.py => tests/test_base.py} (97%) rename nsflow/nde/transforms/{conv_test.py => tests/test_conv.py} (80%) rename nsflow/nde/transforms/{coupling_test.py => tests/test_coupling.py} (98%) rename nsflow/nde/transforms/{linear_test.py => tests/test_linear.py} (98%) rename nsflow/nde/transforms/{lu_test.py => tests/test_lu.py} (94%) rename nsflow/nde/transforms/{made_test.py => tests/test_made.py} (99%) rename nsflow/nde/transforms/{nonlinearities_test.py => tests/test_nonlinearities.py} (97%) rename nsflow/nde/transforms/{normalization_test.py => tests/test_normalization.py} (96%) rename nsflow/nde/transforms/{orthogonal_test.py => tests/test_orthogonal.py} (95%) rename nsflow/nde/transforms/{permutations_test.py => tests/test_permutations.py} (93%) rename nsflow/nde/transforms/{qr_test.py => tests/test_qr.py} (95%) rename nsflow/nde/transforms/{reshape_test.py => tests/test_reshape.py} (95%) rename nsflow/nde/transforms/{standard_test.py => tests/test_standard.py} (97%) rename nsflow/nde/transforms/{svd_test.py => tests/test_svd.py} (95%) rename nsflow/nde/transforms/{transform_test.py => tests/test_transform.py} (96%) create mode 100644 nsflow/nn/tests/__init__.py rename nsflow/nn/{mlp_test.py => tests/test_mlp.py} (97%) create mode 100644 nsflow/utils/tests/__init__.py rename nsflow/utils/{torchutils_test.py => tests/test_torchutils.py} (99%) create mode 100644 nsflow/vae/tests/__init__.py rename nsflow/vae/{base_test.py => tests/test_base.py} (98%) diff --git a/nsflow/nde/distributions/tests/__init__.py b/nsflow/nde/distributions/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/nde/distributions/discrete_test.py b/nsflow/nde/distributions/tests/test_discrete.py similarity index 98% rename from nsflow/nde/distributions/discrete_test.py rename to nsflow/nde/distributions/tests/test_discrete.py index 6e46bcb..c0a166e 100644 --- a/nsflow/nde/distributions/discrete_test.py +++ b/nsflow/nde/distributions/tests/test_discrete.py @@ -3,7 +3,7 @@ import torch import torchtestcase import unittest -from nde.distributions import discrete +from nsflow.nde.distributions import discrete class ConditionalIndependentBernoulliTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/distributions/normal_test.py b/nsflow/nde/distributions/tests/test_normal.py similarity index 99% rename from nsflow/nde/distributions/normal_test.py rename to nsflow/nde/distributions/tests/test_normal.py index 48d8243..53e84f9 100644 --- a/nsflow/nde/distributions/normal_test.py +++ b/nsflow/nde/distributions/tests/test_normal.py @@ -3,7 +3,7 @@ import torch import torchtestcase import unittest -from nde.distributions import normal +from nsflow.nde.distributions import normal class StandardNormalTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/flows/tests/__init__.py b/nsflow/nde/flows/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/nde/flows/autoregressive_test.py b/nsflow/nde/flows/tests/test_autoregressive.py similarity index 95% rename from nsflow/nde/flows/autoregressive_test.py rename to nsflow/nde/flows/tests/test_autoregressive.py index f5f0baa..8262cb8 100644 --- a/nsflow/nde/flows/autoregressive_test.py +++ b/nsflow/nde/flows/tests/test_autoregressive.py @@ -4,7 +4,7 @@ import torchtestcase import unittest -from nde.flows import autoregressive as ar +from nsflow.nde.flows import autoregressive as ar class MaskedAutoregressiveFlowTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/flows/base_test.py b/nsflow/nde/flows/tests/test_base.py similarity index 97% rename from nsflow/nde/flows/base_test.py rename to nsflow/nde/flows/tests/test_base.py index 4834c4c..80a3610 100644 --- a/nsflow/nde/flows/base_test.py +++ b/nsflow/nde/flows/tests/test_base.py @@ -3,9 +3,9 @@ import torch import torchtestcase import unittest -from nde import transforms -from nde import distributions -from nde.flows import base +from nsflow.nde import transforms +from nsflow.nde import distributions +from nsflow.nde.flows import base class FlowTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/flows/realnvp_test.py b/nsflow/nde/flows/tests/test_realnvp.py similarity index 96% rename from nsflow/nde/flows/realnvp_test.py rename to nsflow/nde/flows/tests/test_realnvp.py index e5f6e16..6c2fe1e 100644 --- a/nsflow/nde/flows/realnvp_test.py +++ b/nsflow/nde/flows/tests/test_realnvp.py @@ -4,7 +4,7 @@ import torchtestcase import unittest -from nde.flows import realnvp +from nsflow.nde.flows import realnvp class SimpleRealNVPTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/transforms/tests/__init__.py b/nsflow/nde/transforms/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/nde/transforms/autoregressive_test.py b/nsflow/nde/transforms/tests/test_autoregressive.py similarity index 97% rename from nsflow/nde/transforms/autoregressive_test.py rename to nsflow/nde/transforms/tests/test_autoregressive.py index f171b37..ff095ec 100644 --- a/nsflow/nde/transforms/autoregressive_test.py +++ b/nsflow/nde/transforms/tests/test_autoregressive.py @@ -3,8 +3,8 @@ import torch import unittest -from nde.transforms import autoregressive -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import autoregressive +from nsflow.nde.transforms.tests.test_transform import TransformTest class MaskedAffineAutoregressiveTransformTest(TransformTest): diff --git a/nsflow/nde/transforms/base_test.py b/nsflow/nde/transforms/tests/test_base.py similarity index 97% rename from nsflow/nde/transforms/base_test.py rename to nsflow/nde/transforms/tests/test_base.py index 4fdccb4..27783ae 100644 --- a/nsflow/nde/transforms/base_test.py +++ b/nsflow/nde/transforms/tests/test_base.py @@ -4,9 +4,9 @@ import numpy as np import torch -from nde.transforms import base -from nde.transforms import standard -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import base +from nsflow.nde.transforms import standard +from nsflow.nde.transforms.tests.test_transform import TransformTest class CompositeTransformTest(TransformTest): diff --git a/nsflow/nde/transforms/conv_test.py b/nsflow/nde/transforms/tests/test_conv.py similarity index 80% rename from nsflow/nde/transforms/conv_test.py rename to nsflow/nde/transforms/tests/test_conv.py index 54b2843..70534d0 100644 --- a/nsflow/nde/transforms/conv_test.py +++ b/nsflow/nde/transforms/tests/test_conv.py @@ -1,8 +1,8 @@ import torch import unittest -from nde import transforms -from nde.transforms.transform_test import TransformTest +from nsflow.nde import transforms +from nsflow.nde.transforms.tests.test_transform import TransformTest class OneByOneConvolutionTest(TransformTest): diff --git a/nsflow/nde/transforms/coupling_test.py b/nsflow/nde/transforms/tests/test_coupling.py similarity index 98% rename from nsflow/nde/transforms/coupling_test.py rename to nsflow/nde/transforms/tests/test_coupling.py index 4f9c2cb..a24a1be 100644 --- a/nsflow/nde/transforms/coupling_test.py +++ b/nsflow/nde/transforms/tests/test_coupling.py @@ -6,11 +6,11 @@ from torch import nn -import nn as nn_ -import utils +from nsflow import nn as nn_ +from nsflow import utils -from nde.transforms import coupling -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import coupling +from nsflow.nde.transforms.tests.test_transform import TransformTest def create_coupling_transform(cls, shape, **kwargs): if len(shape) == 1: diff --git a/nsflow/nde/transforms/linear_test.py b/nsflow/nde/transforms/tests/test_linear.py similarity index 98% rename from nsflow/nde/transforms/linear_test.py rename to nsflow/nde/transforms/tests/test_linear.py index f69bd90..e0c6da9 100644 --- a/nsflow/nde/transforms/linear_test.py +++ b/nsflow/nde/transforms/tests/test_linear.py @@ -5,11 +5,11 @@ from unittest.mock import MagicMock -import utils +from nsflow import utils -from nde.transforms import linear -from nde.transforms.transform_test import TransformTest -from nde.transforms.linear import Linear +from nsflow.nde.transforms import linear +from nsflow.nde.transforms.tests.test_transform import TransformTest +from nsflow.nde.transforms.linear import Linear class LinearTest(TransformTest): diff --git a/nsflow/nde/transforms/lu_test.py b/nsflow/nde/transforms/tests/test_lu.py similarity index 94% rename from nsflow/nde/transforms/lu_test.py rename to nsflow/nde/transforms/tests/test_lu.py index a79ed53..2300ed8 100644 --- a/nsflow/nde/transforms/lu_test.py +++ b/nsflow/nde/transforms/tests/test_lu.py @@ -3,10 +3,10 @@ import torch import unittest -import utils +from nsflow import utils -from nde.transforms import lu -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import lu +from nsflow.nde.transforms.tests.test_transform import TransformTest class LULinearTest(TransformTest): diff --git a/nsflow/nde/transforms/made_test.py b/nsflow/nde/transforms/tests/test_made.py similarity index 99% rename from nsflow/nde/transforms/made_test.py rename to nsflow/nde/transforms/tests/test_made.py index 119181e..be8d419 100644 --- a/nsflow/nde/transforms/made_test.py +++ b/nsflow/nde/transforms/tests/test_made.py @@ -4,7 +4,7 @@ import torchtestcase import unittest -from nde.transforms import made +from nsflow.nde.transforms import made class ShapeTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/transforms/nonlinearities_test.py b/nsflow/nde/transforms/tests/test_nonlinearities.py similarity index 97% rename from nsflow/nde/transforms/nonlinearities_test.py rename to nsflow/nde/transforms/tests/test_nonlinearities.py index 3a5c1cd..dc321cc 100644 --- a/nsflow/nde/transforms/nonlinearities_test.py +++ b/nsflow/nde/transforms/tests/test_nonlinearities.py @@ -3,9 +3,8 @@ import torch import unittest -import nde.transforms.splines.quadratic -from nde.transforms import base, nonlinearities as nl, standard -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import base, nonlinearities as nl, standard +from nsflow.nde.transforms.tests.test_transform import TransformTest class TanhTest(TransformTest): diff --git a/nsflow/nde/transforms/normalization_test.py b/nsflow/nde/transforms/tests/test_normalization.py similarity index 96% rename from nsflow/nde/transforms/normalization_test.py rename to nsflow/nde/transforms/tests/test_normalization.py index 6e7217f..33b4ed6 100644 --- a/nsflow/nde/transforms/normalization_test.py +++ b/nsflow/nde/transforms/tests/test_normalization.py @@ -3,9 +3,9 @@ import torch import unittest -from nde.transforms import base -from nde.transforms import normalization as norm -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import base +from nsflow.nde.transforms import normalization as norm +from nsflow.nde.transforms.tests.test_transform import TransformTest class BatchNormTest(TransformTest): diff --git a/nsflow/nde/transforms/orthogonal_test.py b/nsflow/nde/transforms/tests/test_orthogonal.py similarity index 95% rename from nsflow/nde/transforms/orthogonal_test.py rename to nsflow/nde/transforms/tests/test_orthogonal.py index 7633a12..297469b 100644 --- a/nsflow/nde/transforms/orthogonal_test.py +++ b/nsflow/nde/transforms/tests/test_orthogonal.py @@ -3,10 +3,10 @@ import torch import unittest -import utils +from nsflow import utils -from nde.transforms import orthogonal -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import orthogonal +from nsflow.nde.transforms.tests.test_transform import TransformTest class HouseholderSequenceTest(TransformTest): diff --git a/nsflow/nde/transforms/permutations_test.py b/nsflow/nde/transforms/tests/test_permutations.py similarity index 93% rename from nsflow/nde/transforms/permutations_test.py rename to nsflow/nde/transforms/tests/test_permutations.py index cb964f0..a22e027 100644 --- a/nsflow/nde/transforms/permutations_test.py +++ b/nsflow/nde/transforms/tests/test_permutations.py @@ -3,8 +3,8 @@ import torch import unittest -from nde.transforms import permutations -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import permutations +from nsflow.nde.transforms.tests.test_transform import TransformTest class PermutationTest(TransformTest): diff --git a/nsflow/nde/transforms/qr_test.py b/nsflow/nde/transforms/tests/test_qr.py similarity index 95% rename from nsflow/nde/transforms/qr_test.py rename to nsflow/nde/transforms/tests/test_qr.py index 70b66c0..321c68f 100644 --- a/nsflow/nde/transforms/qr_test.py +++ b/nsflow/nde/transforms/tests/test_qr.py @@ -1,10 +1,10 @@ import torch import unittest -import utils +from nsflow import utils -from nde.transforms import qr -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import qr +from nsflow.nde.transforms.tests.test_transform import TransformTest class QRLinearTest(TransformTest): diff --git a/nsflow/nde/transforms/reshape_test.py b/nsflow/nde/transforms/tests/test_reshape.py similarity index 95% rename from nsflow/nde/transforms/reshape_test.py rename to nsflow/nde/transforms/tests/test_reshape.py index 74b262e..6366e24 100644 --- a/nsflow/nde/transforms/reshape_test.py +++ b/nsflow/nde/transforms/tests/test_reshape.py @@ -1,8 +1,8 @@ import torch import unittest -from nde.transforms.transform_test import TransformTest -from nde import transforms +from nsflow.nde.transforms.tests.test_transform import TransformTest +from nsflow.nde import transforms class SqueezeTransformTest(TransformTest): diff --git a/nsflow/nde/transforms/standard_test.py b/nsflow/nde/transforms/tests/test_standard.py similarity index 97% rename from nsflow/nde/transforms/standard_test.py rename to nsflow/nde/transforms/tests/test_standard.py index 8a41749..e5b104d 100644 --- a/nsflow/nde/transforms/standard_test.py +++ b/nsflow/nde/transforms/tests/test_standard.py @@ -4,8 +4,8 @@ import torch import unittest -from nde.transforms import standard -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import standard +from nsflow.nde.transforms.tests.test_transform import TransformTest class IdentityTransformTest(TransformTest): diff --git a/nsflow/nde/transforms/svd_test.py b/nsflow/nde/transforms/tests/test_svd.py similarity index 95% rename from nsflow/nde/transforms/svd_test.py rename to nsflow/nde/transforms/tests/test_svd.py index 08dd516..7684180 100644 --- a/nsflow/nde/transforms/svd_test.py +++ b/nsflow/nde/transforms/tests/test_svd.py @@ -1,10 +1,10 @@ import torch import unittest -import utils +from nsflow import utils -from nde.transforms import svd -from nde.transforms.transform_test import TransformTest +from nsflow.nde.transforms import svd +from nsflow.nde.transforms.tests.test_transform import TransformTest class SVDLinearTest(TransformTest): diff --git a/nsflow/nde/transforms/transform_test.py b/nsflow/nde/transforms/tests/test_transform.py similarity index 96% rename from nsflow/nde/transforms/transform_test.py rename to nsflow/nde/transforms/tests/test_transform.py index 2b90c1d..3472f4a 100644 --- a/nsflow/nde/transforms/transform_test.py +++ b/nsflow/nde/transforms/tests/test_transform.py @@ -1,7 +1,7 @@ import torch import torchtestcase -from nde.transforms import base +from nsflow.nde.transforms import base class TransformTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nn/tests/__init__.py b/nsflow/nn/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/nn/mlp_test.py b/nsflow/nn/tests/test_mlp.py similarity index 97% rename from nsflow/nn/mlp_test.py rename to nsflow/nn/tests/test_mlp.py index adea93f..627c294 100644 --- a/nsflow/nn/mlp_test.py +++ b/nsflow/nn/tests/test_mlp.py @@ -4,7 +4,7 @@ import torchtestcase import unittest -from nn import mlp +from nsflow.nn import mlp class MLPTest(torchtestcase.TorchTestCase): diff --git a/nsflow/utils/tests/__init__.py b/nsflow/utils/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/utils/torchutils_test.py b/nsflow/utils/tests/test_torchutils.py similarity index 99% rename from nsflow/utils/torchutils_test.py rename to nsflow/utils/tests/test_torchutils.py index 0d771cd..5c439b2 100644 --- a/nsflow/utils/torchutils_test.py +++ b/nsflow/utils/tests/test_torchutils.py @@ -4,7 +4,7 @@ import torchtestcase import unittest -from utils import torchutils +from nsflow.utils import torchutils class TorchUtilsTest(torchtestcase.TorchTestCase): diff --git a/nsflow/vae/tests/__init__.py b/nsflow/vae/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/vae/base_test.py b/nsflow/vae/tests/test_base.py similarity index 98% rename from nsflow/vae/base_test.py rename to nsflow/vae/tests/test_base.py index 65b8455..01a190d 100644 --- a/nsflow/vae/base_test.py +++ b/nsflow/vae/tests/test_base.py @@ -4,8 +4,8 @@ import torchtestcase import unittest -from nde import distributions -from vae import base +from nsflow.nde import distributions +from nsflow.vae import base class VariationalAutoencoderTest(torchtestcase.TorchTestCase): From c28b1f528d3e4c44a5364bfddcbcbaf46df66b0b Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 17:22:28 +0000 Subject: [PATCH 3/7] Use new linear algebra function names. --- nsflow/nde/transforms/linear.py | 4 ++-- nsflow/nde/transforms/lu.py | 4 ++-- nsflow/nde/transforms/qr.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nsflow/nde/transforms/linear.py b/nsflow/nde/transforms/linear.py index 24ac340..1cc04d3 100644 --- a/nsflow/nde/transforms/linear.py +++ b/nsflow/nde/transforms/linear.py @@ -177,7 +177,7 @@ def inverse_no_cache(self, inputs): """ batch_size = inputs.shape[0] outputs = inputs - self.bias - outputs, lu = torch.gesv(outputs.t(), self._weight) # Linear-system solver. + outputs, lu = torch.solve(outputs.t(), self._weight) # Linear-system solver. outputs = outputs.t() # The linear-system solver returns the LU decomposition of the weights, which we # can use to obtain the log absolute determinant directly. @@ -210,7 +210,7 @@ def weight_inverse_and_logabsdet(self): """ # If both weight inverse and logabsdet are needed, it's cheaper to compute both together. identity = torch.eye(self.features, self.features) - weight_inv, lu = torch.gesv(identity, self._weight) # Linear-system solver. + weight_inv, lu = torch.solve(identity, self._weight) # Linear-system solver. logabsdet = torch.sum(torch.log(torch.abs(torch.diag(lu)))) return weight_inv, logabsdet diff --git a/nsflow/nde/transforms/lu.py b/nsflow/nde/transforms/lu.py index 44881cb..7774741 100644 --- a/nsflow/nde/transforms/lu.py +++ b/nsflow/nde/transforms/lu.py @@ -103,8 +103,8 @@ def weight_inverse(self): """ lower, upper = self._create_lower_upper() identity = torch.eye(self.features, self.features) - lower_inverse, _ = torch.trtrs(identity, lower, upper=False, unitriangular=True) - weight_inverse, _ = torch.trtrs(lower_inverse, upper, upper=True, unitriangular=False) + lower_inverse, _ = torch.triangular_solve(identity, lower, upper=False, unitriangular=True) + weight_inverse, _ = torch.triangular_solve(lower_inverse, upper, upper=True, unitriangular=False) return weight_inverse @property diff --git a/nsflow/nde/transforms/qr.py b/nsflow/nde/transforms/qr.py index 82a3bbf..da05977 100644 --- a/nsflow/nde/transforms/qr.py +++ b/nsflow/nde/transforms/qr.py @@ -70,7 +70,7 @@ def inverse_no_cache(self, inputs): upper = self._create_upper() outputs = inputs - self.bias outputs, _ = self.orthogonal.inverse(outputs) # Ignore logabsdet since we know it's zero. - outputs, _ = torch.trtrs(outputs.t(), upper, upper=True) + outputs, _ = torch.triangular_solve(outputs.t(), upper, upper=True) outputs = outputs.t() logabsdet = -self.logabsdet() logabsdet = logabsdet * torch.ones(outputs.shape[0]) @@ -96,7 +96,7 @@ def weight_inverse(self): """ upper = self._create_upper() identity = torch.eye(self.features, self.features) - upper_inv, _ = torch.trtrs(identity, upper, upper=True) + upper_inv, _ = torch.triangular_solve(identity, upper, upper=True) weight_inv, _ = self.orthogonal(upper_inv) return weight_inv From 766f7166a6f475a1304d558491db61c945c07b26 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 17:30:51 +0000 Subject: [PATCH 4/7] Refactor spline tests. --- nsflow/nde/transforms/splines/tests/__init__.py | 0 .../transforms/splines/{cubic_test.py => tests/test_cubic.py} | 2 +- .../transforms/splines/{linear_test.py => tests/test_linear.py} | 2 +- .../splines/{quadratic_test.py => tests/test_quadratic.py} | 2 +- .../test_rational_quadratic.py} | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 nsflow/nde/transforms/splines/tests/__init__.py rename nsflow/nde/transforms/splines/{cubic_test.py => tests/test_cubic.py} (98%) rename nsflow/nde/transforms/splines/{linear_test.py => tests/test_linear.py} (97%) rename nsflow/nde/transforms/splines/{quadratic_test.py => tests/test_quadratic.py} (97%) rename nsflow/nde/transforms/splines/{rational_quadratic_test.py => tests/test_rational_quadratic.py} (98%) diff --git a/nsflow/nde/transforms/splines/tests/__init__.py b/nsflow/nde/transforms/splines/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsflow/nde/transforms/splines/cubic_test.py b/nsflow/nde/transforms/splines/tests/test_cubic.py similarity index 98% rename from nsflow/nde/transforms/splines/cubic_test.py rename to nsflow/nde/transforms/splines/tests/test_cubic.py index 3fc071b..6b6c5c1 100644 --- a/nsflow/nde/transforms/splines/cubic_test.py +++ b/nsflow/nde/transforms/splines/tests/test_cubic.py @@ -1,7 +1,7 @@ import torch import torchtestcase -from nde.transforms import splines +from nsflow.nde.transforms import splines class CubicSplineTest(torchtestcase.TorchTestCase): diff --git a/nsflow/nde/transforms/splines/linear_test.py b/nsflow/nde/transforms/splines/tests/test_linear.py similarity index 97% rename from nsflow/nde/transforms/splines/linear_test.py rename to nsflow/nde/transforms/splines/tests/test_linear.py index ac8dbd9..59fb34c 100644 --- a/nsflow/nde/transforms/splines/linear_test.py +++ b/nsflow/nde/transforms/splines/tests/test_linear.py @@ -1,7 +1,7 @@ import torch import torchtestcase -from nde.transforms import splines +from nsflow.nde.transforms import splines class LinearSplineTest(torchtestcase.TorchTestCase): def test_forward_inverse_are_consistent(self): diff --git a/nsflow/nde/transforms/splines/quadratic_test.py b/nsflow/nde/transforms/splines/tests/test_quadratic.py similarity index 97% rename from nsflow/nde/transforms/splines/quadratic_test.py rename to nsflow/nde/transforms/splines/tests/test_quadratic.py index cb52f1e..dfbf48b 100644 --- a/nsflow/nde/transforms/splines/quadratic_test.py +++ b/nsflow/nde/transforms/splines/tests/test_quadratic.py @@ -1,7 +1,7 @@ import torch import torchtestcase -from nde.transforms import splines +from nsflow.nde.transforms import splines class QuadraticSplineTest(torchtestcase.TorchTestCase): def test_forward_inverse_are_consistent(self): diff --git a/nsflow/nde/transforms/splines/rational_quadratic_test.py b/nsflow/nde/transforms/splines/tests/test_rational_quadratic.py similarity index 98% rename from nsflow/nde/transforms/splines/rational_quadratic_test.py rename to nsflow/nde/transforms/splines/tests/test_rational_quadratic.py index 77fef5b..3500782 100644 --- a/nsflow/nde/transforms/splines/rational_quadratic_test.py +++ b/nsflow/nde/transforms/splines/tests/test_rational_quadratic.py @@ -1,7 +1,7 @@ import torch import torchtestcase -from nde.transforms import splines +from nsflow.nde.transforms import splines class RationalQuadraticSplineTest(torchtestcase.TorchTestCase): def test_forward_inverse_are_consistent(self): From af63f82d80c444ca1e8eefc613d3e713f57d3216 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 17:34:43 +0000 Subject: [PATCH 5/7] Skip a MADE test. --- nsflow/nde/transforms/tests/test_made.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nsflow/nde/transforms/tests/test_made.py b/nsflow/nde/transforms/tests/test_made.py index be8d419..d9d7d11 100644 --- a/nsflow/nde/transforms/tests/test_made.py +++ b/nsflow/nde/transforms/tests/test_made.py @@ -9,6 +9,7 @@ class ShapeTest(torchtestcase.TorchTestCase): + @unittest.skip('Not implemented yet.') def test_conditional(self): features = 100 hidden_features = 200 From fe1bc3fbbc1a7bc349a4ae430d57cade27e161f3 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 17:36:58 +0000 Subject: [PATCH 6/7] Get rid of print statement in normalization test. --- nsflow/nde/transforms/tests/test_normalization.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nsflow/nde/transforms/tests/test_normalization.py b/nsflow/nde/transforms/tests/test_normalization.py index 33b4ed6..d0083cb 100644 --- a/nsflow/nde/transforms/tests/test_normalization.py +++ b/nsflow/nde/transforms/tests/test_normalization.py @@ -35,7 +35,6 @@ def test_forward(self): logabsdet_ref += torch.sum(torch.log(transform.weight)) self.assert_tensor_is_good(outputs_ref, [batch_size, features]) self.assert_tensor_is_good(logabsdet_ref, [batch_size]) - print(outputs, outputs_ref) self.assertEqual(outputs, outputs_ref) self.assertEqual(logabsdet, logabsdet_ref) From a88391554846680a71a543a91b88aa986c5bbf61 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Thu, 6 Feb 2020 17:44:04 +0000 Subject: [PATCH 7/7] Stop stochastic test failures. --- nsflow/nde/transforms/tests/test_nonlinearities.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nsflow/nde/transforms/tests/test_nonlinearities.py b/nsflow/nde/transforms/tests/test_nonlinearities.py index dc321cc..e5fd01c 100644 --- a/nsflow/nde/transforms/tests/test_nonlinearities.py +++ b/nsflow/nde/transforms/tests/test_nonlinearities.py @@ -51,6 +51,7 @@ def test_ones_to_ones(self): self.assertEqual(outputs, inputs) def test_forward_inverse_are_consistent(self): + torch.manual_seed(0) for transform in self.transforms: with self.subTest(transform=transform): inputs = torch.rand(self.batch_size, *self.shape) @@ -65,7 +66,7 @@ def test_forward_inverse_are_consistent(self): nl.PiecewiseQuadraticCDF(shape, tails='linear'), nl.PiecewiseCubicCDF(shape, tails='linear'), nl.PiecewiseRationalQuadraticCDF(shape, tails='linear')] - + torch.manual_seed(0) for transform in transforms: with self.subTest(transform=transform): inputs = 3 * torch.randn(batch_size, *shape)