Skip to content

Pytest with 89% coverage #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b2f91f2
full coveragre utils
rflamary Jul 24, 2017
c6e648f
test parmap python 3.5
rflamary Jul 24, 2017
a31d3c2
map to list
rflamary Jul 24, 2017
f8e822c
test sinkhorn with empty marginals
rflamary Jul 24, 2017
7d9c5e7
add test optim
rflamary Jul 24, 2017
709d8cb
add dr tests
rflamary Jul 24, 2017
83ecc6d
bregman coverage
rflamary Jul 24, 2017
64cf2fc
tets barycenter
rflamary Jul 24, 2017
33f3d30
clean pep8
rflamary Jul 24, 2017
bd705ed
add test yunmlix and bary
rflamary Jul 24, 2017
f204e98
add test da 58% coverage
rflamary Jul 24, 2017
5aad08a
add test plot
rflamary Jul 24, 2017
a8d7301
add test plot and dataset
rflamary Jul 24, 2017
e11b1d1
test plot with no X
rflamary Jul 24, 2017
11f0652
matplotlib travis
rflamary Jul 24, 2017
46f297f
import nmpy before ot
rflamary Jul 26, 2017
68d7490
numpy assert + n_bins
rflamary Jul 26, 2017
67b011a
numpy assert test_da
rflamary Jul 26, 2017
347e628
n to n_samples
rflamary Jul 26, 2017
4a45135
dr +gpu numpy assert
rflamary Jul 26, 2017
2bc41ad
rng gpu
rflamary Jul 26, 2017
6a02db0
test_optim
rflamary Jul 26, 2017
86418eb
test_optim allclose
rflamary Jul 26, 2017
286de0a
clean test_ot
rflamary Jul 26, 2017
0e06129
Merge branch 'pytest' of github.com:rflamary/POT into pytest
rflamary Jul 26, 2017
81118f2
test_ot random state
rflamary Jul 26, 2017
109fc2a
flake8
rflamary Jul 26, 2017
e0fa14b
flake8
rflamary Jul 26, 2017
d101e08
nearly all review done
rflamary Jul 26, 2017
77037cc
gitignore
rflamary Jul 26, 2017
fac003d
author and license for tets files
rflamary Jul 26, 2017
0097017
add license and authors on all modules
rflamary Jul 26, 2017
251af8e
add author to all examples
rflamary Jul 26, 2017
84aa318
pep8
rflamary Jul 26, 2017
96f8b96
valid flake8
rflamary Jul 26, 2017
838550e
last stuff
rflamary Jul 26, 2017
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ ENV/

# Mac stuff
.DS_Store

# coverage output folder
cov_html/
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ matrix:
python: 2.7
before_install:
- ./.travis/before_install.sh
before_script: # configure a headless display to test plot generation
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you use only matplotlib? if so just use the Agg backend

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use the Agg backedn here
https://github.com/rflamary/POT/blob/pytest/test/test_plot.py

but travis still failed with DISPLAY error
https://travis-ci.org/rflamary/POT/builds/256924206

maybe the test_plot.py is not good but I don't see the problem

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's weird. You seem to have done it right. Are you sure matplotlib is not imported anywhere before?

you should also nest the imports to matplotlib in the or source tree. So matplotlib is not imported when you do import ot

# command to install dependencies
install:
- pip install -r requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pep8 :
flake8 examples/ ot/ test/

test : FORCE pep8
python -m py.test -v test/
python -m py.test -v test/ --cov=ot --cov-report html:cov_html

pytest : FORCE
python -m py.test -v test/
python -m py.test -v test/ --cov=ot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should have a native pytest command:

pytest -v test/ --cov=ot

Copy link
Collaborator Author

@rflamary rflamary Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under Debian/Ubuntu logilab-common install a useless executable named pytest. It's a well known bug but takes time to be corrected. This line ensure that the proper py.test is executed.

pytest-dev/pytest#1833


uploadpypi :
#python setup.py register
Expand Down
4 changes: 4 additions & 0 deletions examples/plot_OTDA_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
4 changes: 4 additions & 0 deletions examples/plot_OTDA_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import matplotlib.pylab as pl
import ot

Expand Down
4 changes: 4 additions & 0 deletions examples/plot_OTDA_color_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
from scipy import ndimage
import matplotlib.pylab as pl
Expand Down
4 changes: 4 additions & 0 deletions examples/plot_OTDA_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
Neural Information Processing Systems (NIPS), 2016.
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
4 changes: 4 additions & 0 deletions examples/plot_OTDA_mapping_color_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
from scipy import ndimage
import matplotlib.pylab as pl
Expand Down
5 changes: 4 additions & 1 deletion examples/plot_OT_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
1D optimal transport
====================

@author: rflamary
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
5 changes: 4 additions & 1 deletion examples/plot_OT_2D_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
2D Optimal transport between empirical distributions
====================================================

@author: rflamary
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
5 changes: 4 additions & 1 deletion examples/plot_OT_L1_vs_L2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
https://arxiv.org/pdf/1706.07650.pdf


@author: rflamary
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
5 changes: 4 additions & 1 deletion examples/plot_WDA.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
Wasserstein Discriminant Analysis
=================================

@author: rflamary
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl

Expand Down
6 changes: 4 additions & 2 deletions examples/plot_barycenter_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
1D Wasserstein barycenter demo
==============================


@author: rflamary
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
5 changes: 4 additions & 1 deletion examples/plot_compute_emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
1D optimal transport
====================

@author: rflamary
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
import matplotlib.pylab as pl
import ot
Expand Down
6 changes: 5 additions & 1 deletion ot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License


# All submodules and packages
from . import lp
Expand All @@ -24,6 +28,6 @@

__version__ = "0.3.1"

__all__ = ["emd", "emd2", "sinkhorn","sinkhorn2", "utils", 'datasets',
__all__ = ["emd", "emd2", "sinkhorn", "sinkhorn2", "utils", 'datasets',
'bregman', 'lp', 'plot', 'tic', 'toc', 'toq',
'dist', 'unif', 'barycenter', 'sinkhorn_lpl1_mm', 'da', 'optim']
25 changes: 16 additions & 9 deletions ot/bregman.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Bregman projections for regularized OT
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
# Nicolas Courty <ncourty@irisa.fr>
#
# License: MIT License

import numpy as np


Expand Down Expand Up @@ -103,8 +108,9 @@ def sink():
stopThr=stopThr, verbose=verbose, log=log, **kwargs)
elif method.lower() == 'sinkhorn_epsilon_scaling':
def sink():
return sinkhorn_epsilon_scaling(a, b, M, reg, numItermax=numItermax,
stopThr=stopThr, verbose=verbose, log=log, **kwargs)
return sinkhorn_epsilon_scaling(
a, b, M, reg, numItermax=numItermax,
stopThr=stopThr, verbose=verbose, log=log, **kwargs)
else:
print('Warning : unknown method using classic Sinkhorn Knopp')

Expand Down Expand Up @@ -211,8 +217,9 @@ def sink():
stopThr=stopThr, verbose=verbose, log=log, **kwargs)
elif method.lower() == 'sinkhorn_epsilon_scaling':
def sink():
return sinkhorn_epsilon_scaling(a, b, M, reg, numItermax=numItermax,
stopThr=stopThr, verbose=verbose, log=log, **kwargs)
return sinkhorn_epsilon_scaling(
a, b, M, reg, numItermax=numItermax,
stopThr=stopThr, verbose=verbose, log=log, **kwargs)
else:
print('Warning : unknown method using classic Sinkhorn Knopp')

Expand Down Expand Up @@ -588,7 +595,7 @@ def get_Gamma(alpha, beta, u, v):

cpt = cpt + 1

#print('err=',err,' cpt=',cpt)
# print('err=',err,' cpt=',cpt)
if log:
log['logu'] = alpha / reg + np.log(u)
log['logv'] = beta / reg + np.log(v)
Expand Down Expand Up @@ -773,7 +780,7 @@ def get_reg(n): # exponential decreasing
loop = False

cpt = cpt + 1
#print('err=',err,' cpt=',cpt)
# print('err=',err,' cpt=',cpt)
if log:
log['alpha'] = alpha
log['beta'] = beta
Expand Down Expand Up @@ -960,16 +967,16 @@ def unmix(a, D, M, M0, h0, reg, reg0, alpha, numItermax=1000, stopThr=1e-3, verb

"""

#M = M/np.median(M)
# M = M/np.median(M)
K = np.exp(-M / reg)

#M0 = M0/np.median(M0)
# M0 = M0/np.median(M0)
K0 = np.exp(-M0 / reg0)
old = h0

err = 1
cpt = 0
#log = {'niter':0, 'all_err':[]}
# log = {'niter':0, 'all_err':[]}
if log:
log = {'err': []}

Expand Down
10 changes: 8 additions & 2 deletions ot/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Domain adaptation with optimal transport
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
# Nicolas Courty <ncourty@irisa.fr>
# Michael Perrot <michael.perrot@univ-st-etienne.fr>
#
# License: MIT License

import numpy as np
from .bregman import sinkhorn
from .lp import emd
Expand Down Expand Up @@ -472,7 +478,7 @@ def joint_OT_mapping_kernel(xs, xt, mu=1, eta=0.001, kerneltype='gaussian', sigm
Kp[:ns, :ns] = K

# ls regu
#K0 = K1.T.dot(K1)+eta*I
# K0 = K1.T.dot(K1)+eta*I
# Kreg=I

# RKHS regul
Expand All @@ -484,7 +490,7 @@ def joint_OT_mapping_kernel(xs, xt, mu=1, eta=0.001, kerneltype='gaussian', sigm
I = np.eye(ns)

# ls regul
#K0 = K1.T.dot(K1)+eta*I
# K0 = K1.T.dot(K1)+eta*I
# Kreg=I

# proper kernel ridge
Expand Down
4 changes: 4 additions & 0 deletions ot/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Simple example datasets for OT
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License


import numpy as np
import scipy as sp
Expand Down
4 changes: 4 additions & 0 deletions ot/dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Dimension reduction with optimal transport
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

from scipy import linalg
import autograd.numpy as np
from pymanopt.manifolds import Stiefel
Expand Down
5 changes: 5 additions & 0 deletions ot/gpu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
from . import da
from .bregman import sinkhorn

# Author: Remi Flamary <remi.flamary@unice.fr>
# Leo Gautheron <https://github.com/aje>
#
# License: MIT License

__all__ = ["bregman", "da", "sinkhorn"]
5 changes: 5 additions & 0 deletions ot/gpu/bregman.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Bregman projections for regularized OT with GPU
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
# Leo Gautheron <https://github.com/aje>
#
# License: MIT License

import numpy as np
import cudamat

Expand Down
8 changes: 8 additions & 0 deletions ot/gpu/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Domain adaptation with optimal transport with GPU implementation
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
# Nicolas Courty <ncourty@irisa.fr>
# Michael Perrot <michael.perrot@univ-st-etienne.fr>
# Leo Gautheron <https://github.com/aje>
#
# License: MIT License


import numpy as np
from ..utils import unif
from ..da import OTDA
Expand Down
4 changes: 4 additions & 0 deletions ot/lp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Solvers for the original linear program OT problem
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
# import compiled emd
from .emd_wrap import emd_c, emd2_c
Expand Down
9 changes: 6 additions & 3 deletions ot/lp/emd_wrap.pyx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 11 08:42:08 2014

@author: rflamary
Cython linker with C solver
"""

# Author: Remi Flamary <remi.flamary@unice.fr>
#
# License: MIT License

import numpy as np
cimport numpy as np

Expand Down
Loading