summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2017-01-05 13:48:09 +0100
committerRémi Flamary <remi.flamary@gmail.com>2017-01-05 13:48:09 +0100
commite1cd68bd8e8a2c7334595d1b4ea0bc9dccfd3013 (patch)
tree0de1eae6814e76616a5f995a28fc6fa1eb4bfaca
parentb90ea88f8f0cf32aef102277588f80042c6cfcaa (diff)
add tic() and toc() functions for easy coarse timing
-rw-r--r--ot/__init__.py2
-rw-r--r--ot/utils.py20
2 files changed, 21 insertions, 1 deletions
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']: