From e1cd68bd8e8a2c7334595d1b4ea0bc9dccfd3013 Mon Sep 17 00:00:00 2001 From: RĂ©mi Flamary Date: Thu, 5 Jan 2017 13:48:09 +0100 Subject: add tic() and toc() functions for easy coarse timing --- ot/__init__.py | 2 +- ot/utils.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ot/__init__.py b/ot/__init__.py index a925a6f..5c67dc5 100644 --- a/ot/__init__.py +++ b/ot/__init__.py @@ -16,7 +16,7 @@ from .bregman import sinkhorn, barycenter from .da import sinkhorn_lpl1_mm # utils functions -from .utils import dist, unif +from .utils import dist, unif, tic, toc, toq __version__ = "0.1.11" diff --git a/ot/utils.py b/ot/utils.py index d3df8fa..2f68775 100644 --- a/ot/utils.py +++ b/ot/utils.py @@ -6,6 +6,26 @@ import numpy as np from scipy.spatial.distance import cdist +import time +__time_tic_toc=time.time() + +def tic(): + """ Python implementation of Matlab tic() function """ + global __time_tic_toc + __time_tic_toc=time.time() + +def toc(message='Elapsed time : {} s'): + """ Python implementation of Matlab toc() function """ + t=time.time() + print(message.format(t-__time_tic_toc)) + return t-__time_tic_toc + +def toq(): + """ Python implementation of Julia toc() function """ + t=time.time() + return t-__time_tic_toc + + def kernel(x1,x2,method='gaussian',sigma=1,**kwargs): """Compute kernel matrix""" if method.lower() in ['gaussian','gauss','rbf']: -- cgit v1.2.3